Microsoft KB Archive/68586

-

{| The information in this article applies to: Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1 Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT versions 3.5 and 3.51 - Microsoft Windows 95 version 4.0
 * width="100%"|

SUMMARY
To simulate changing the font in a message box, create a dialog box that uses the desired font. Specify the style and contents of the dialog box to reflect the style of the desired message box. The application can also draw a system icon in the dialog box.

MORE INFORMATION
The message box is a unique object in Windows. Its handle is not available to an application; therefore, it cannot be modified. An application can simulate a message box with a different font by creating a dialog box that looks like a message box.

To change the font in a dialog box, use the optional statement FONT in the dialog statement of the resource script (.RC) file. For example, resource file statements for a dialog box displaying an error in Courier point size 12 would be as follows:

FontError DIALOG 45, 17, 143, 46 CAPTION &quot;Font Error&quot; FONT 12, &quot;Courier&quot; STYLE WS_CAPTION | WS_SYSMENU | DS_MODALFRAME BEGIN CTEXT &quot;Please select the right font&quot;, -1, 0, 7, 143, 9 DEFPUSHBUTTON &quot;OK&quot; IDOK,   56, 25,  32, 14, WS_GROUP END To center the dialog box in the screen, use GetWindowRect to retrieve the dimensions of the screen and MoveWindow to place the dialog box appropriately. The following code demonstrates this procedure: case WM_INITDIALOG: GetWindowRect(hDlg, &rc); x = GetSystemMetrics(SM_CXSCREEN); y = GetSystemMetrics(SM_CYSCREEN); MoveWindow (hDlg,         (x - (rc.right - rc.left)) >> 1,  /* x position */          (y - (rc.bottom - rc.top)) >> 1,  /* y position */          rc.right - rc.left,               /* x size */          rc.bottom - rc.top,               /* y size */          TRUE);                            /* paint the window */ return TRUE; To display a system icon in the dialog box, call the DrawIcon function during the processing of a WM_PAINT message. After drawing the desired icon, the dialog procedure passes control back to the dialog manager by returning FALSE. The code to paint the exclamation point icon (used in warning messages) is as follows: case WM_PAINT: hIcon = LoadIcon(NULL, IDI_EXCLAMATION); hDC = GetDC(hDlg); DrawIcon(hDC, 20, 40, hIcon); ReleaseDC(hDlg, hDC); return FALSE;
 * }

-

Last reviewed: November 2, 1995

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.