INF: Specifying a System Icon in a Dialog Box

ID Number: Q79985

3.00

WINDOWS

Summary:

It is possible to place a system icon into a dialog box. However,

system icons cannot be specified in an application's resource (RC)

file. This article discusses a method to specify a system icon in a

dialog box in Windows version 3.0.

Windows version 3.1 includes STM_GETICON and STM_SETICON, which

make this process unnecessary.

More Information:

System icons (IDI_ASTERISK or IDI_QUESTION, for example) cannot be

specified in a dialog box's resource file because an icon control in a

dialog box template specifies an application icon resource. The icon

control cannot specify a system icon, which belongs to the display

driver.

To place a system icon in an application's dialog box, include the

following code in the dialog procedure:

switch (message)

{

static HICON hIcon;

case WM_INITDIALOG:

hIcon = LoadIcon(NULL, IDI_HAND);

return TRUE;

case WM_PAINT:

{

HDC hDC;

hDC = GetDC(hDlg);

DrawIcon(hDC, x, y, hIcon);

ReleaseDC(hDlg, hDC);

return FALSE;

}

...

}

While points in the RC file are in dialog base units, the x and y

coordinates passed to the DrawIcon function are in screen units. For

information on converting dialog units to screen units, query this

knowledge base on the following words:

prod(winsdk) and translate and dialog and units

Additional reference words: 3.00