Author Topic: MessageBox - change font?  (Read 4567 times)

0000

  • Member
  • ****
  • Posts: 872
MessageBox - change font?
« on: September 16, 2015, 11:22:22 PM »
Probably a silly question, but is there any way to change the font for a MessageBox?
I am making a macro for debugging purposes, to display the registers and perhaps a few
variables. As you might know, the font used for MessageBox is not monospace; and
therefore the displayed registers are not aligned.

I am trying to avoid creating a window or dialog box to keep the code in the macro
as small as possible.

I was thinking it might be possible to somehow hook the MsgBox message handler.
I haven't found anything relevent in my search of MSDN. So, maybe it is not possible?

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: MessageBox - change font?
« Reply #1 on: September 17, 2015, 12:13:25 AM »
the message box uses a font that is selected by the user in display properties - settings
you can get that font with SystemParametersInfo, using SPI_GETNONCLIENTMETRICS

the font can also be changed using SPI_SETNONCLIENTMETRICS
but, that changes a user setting (generally a no-no)
ok - that's the official way

you might try sending the MessageBox window a WM_SETFONT message
MessageBox uses a static control to display text, so that may not work
you may have to subclass the window to get it done

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: MessageBox - change font?
« Reply #2 on: September 17, 2015, 12:15:19 AM »
probably a better way, altogether, would be to create your own dialog box
you can choose whatever font you like   :t

0000

  • Member
  • ****
  • Posts: 872
Re: MessageBox - change font?
« Reply #3 on: September 17, 2015, 12:19:09 AM »
you may have to subclass the window to get it done

If I'm going to subclass, I might as well make a dialog box. I thought it would be kind of difficult to
change the MessageBox font, but I thought I remembered seeing it somewhere. For all I know
it very well could have been a dialog box (memory leak on my part).

0000

  • Member
  • ****
  • Posts: 872
Re: MessageBox - change font?
« Reply #4 on: September 17, 2015, 12:20:59 AM »
probably a better way, altogether, would be to create your own dialog box
you can choose whatever font you like   :t

Was posting basically the same. The macro I intend building may become unwieldy.  :dazzled:

jj2007

  • Member
  • *****
  • Posts: 11587
  • Assembler is fun ;-)
    • MasmBasic
Re: MessageBox - change font?
« Reply #5 on: September 17, 2015, 04:27:53 AM »
After some years of experience with the deb macro my lessons are:
- I rarely use the MsgBox variant (e.g. deb 1, "test", eax, ebx)
- even less the deb to file variant (deb 5, ...), it's just too much work to open the file in notepad
- most of the time it's a simple deb 4, i.e. output to console
- sometimes in loops I use option deb n, i.e. print during the first n iterations
- if all that doesn't help, it's time to launch Olly ;-)

The extra code is rarely relevant. After all, a macro can be globally switched off, in case of deb with usedeb=0.

Re fonts, it's much easier to use tabs.

Vortex

  • Member
  • *****
  • Posts: 2588
Re: MessageBox - change font?
« Reply #6 on: September 17, 2015, 05:07:22 AM »
Hi zedd151,

You can modify the user interface of a message box. My method is based on moving the creation of a message box to a separate thread. After enumerating all the open windows, you get the handle of the message box with the help of the ID number of the thread displaying the message box. The rest is easy, once you get the handle, you can modify the message box as it's window.

0000

  • Member
  • ****
  • Posts: 872
Re: MessageBox - change font?
« Reply #7 on: September 17, 2015, 05:37:45 AM »
... You can modify the user interface of a message box. ...

Thanks Vortex, that's what I thought. I knew I read it somewhere that customizing MB was possible.
But it seems like more coding than creating a dialog box, which is the approach that I will probably
use. But your example is appreciated, as it may come in handy for a future project. :t

Vortex

  • Member
  • *****
  • Posts: 2588
Re: MessageBox - change font?
« Reply #8 on: September 17, 2015, 05:47:45 AM »
Hi zedd151,

You are welcome. Here is an article about using Windows hooks to create custom message boxes :

http://www.catch22.net/tuts/custom-messagebox

0000

  • Member
  • ****
  • Posts: 872
Re: MessageBox - change font?
« Reply #9 on: September 17, 2015, 05:54:28 AM »
Great! Getting the handle of the MessageBox is the tricky part. (I wasn't sure about how to do it)
Once that is done, everything else is a piece of cake.  :eusa_dance: