Displaying an Icon in a Dialog Box

You can place icons in dialog boxes by using the ICON control statement in the DIALOG statement. You have already seen an example of a DIALOG statement in the About dialog box described with the Generic application. The DIALOG statement for that box looks like this:

AboutBox DIALOG 22, 17, 144, 75

STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU

CAPTION “About Icon”

BEGIN

CTEXT “Microsoft Windows” -1, 37, 5, 68, 8

CTEXT “Generic Application” -1, 0, 14, 144, 8

CTEXT “Version 3.0" -1, 38, 34, 64, 8

DEFPUSHBUTTON ”OK" IDOK, 53, 59, 32, 14, WS_GROUP

END

You can add an icon to the dialog box by inserting the following ICON statement immediately after the DEFPUSHBUTTON statement:

ICON “MyIcon”, -1, 25, 14, 16, 21

When an icon is added to a dialog box, it is treated like any other control. It must have a control ID, a position for its upper-left corner, a width, and a height. In this example, –1 is the control ID, 25 and 14 specify the location of the icon in the dialog box, and 16 and 21 specify the height and width of the icon, respectively. However, Windows ignores the height and width, sizing the icon automatically.

The name MyIcon identifies the icon you want to use. The icon must be defined in an ICON statement elsewhere within the resource script file. For example, the following statement defines the icon MyIcon.

MyIcon ICON MYICON.ICO