[comp.windows.ms.programmer] Fonts in MessageBox

bam@cs.arizona.edu (Brett A. Morrison) (05/19/91)

Keywords says it all.  Please help!  I need to figure out how to change the
font using the MessageBox function.

E-Mail:  bam@cs.arizona.edu

Brett Morrison

bonneau@hyper.hyper.com (Paul Bonneau) (05/22/91)

In article <1523@caslon.cs.arizona.edu> bam@cs.arizona.edu (Brett A. Morrison) writes:
>Keywords says it all.  Please help!  I need to figure out how to change the
>font using the MessageBox function.
>
>E-Mail:  bam@cs.arizona.edu
>
>Brett Morrison
>
The WM_SETFONT message can be used to supply a new font
handle to a control for display.  So, the problem is how
to get the message to each control of the MessageBox.

A sleazy hack springs to mind:

Before the call to MessageBox(), set a global flag to
indicate that a MessageBox is present (and clear the flag
after the call).

When the main window gets the WM_ACTIVTE message with
wParam == 0 *and* the global flag set, then LOWORD(lParam) is
the window handle of the MessageBox.

Walk the linked list of child windows (ie. controls) of the
MessageBox with a loop like:

	for (hwnd = GetWindow(hwndMessageBox, GW_CHILD);
	    hwnd != NULL; hwnd = GetWindow(hwnd, GW_HWNDNEXT))
		SendMessage(hwnd, WM_SETFONT, ...);

There may be a cleaner way, but I think this approach will
work anyway (although make sure you have a bucket handy since
it *is* pretty gagnastic).

cheers - Paul Bonneau.