How To Set the Title Bar Icon in a Dialog Box


You can enable your application to display an icon in the title bar of a dialog box by adding the WS_SYSMENU and WS_CAPTION styles to the dialog box template and sending the WM_SETICON message from within the dialog box procedure in response to the WM_INITDIALOG message.

More Information

On Windows 95 and Windows NT 4.0, any popup or overlapped window can display a small icon for the system menu icon.

Dialog boxes on Windows 95 and Windows NT 4.0 do not display a small icon on their system menus by default. If you want the dialog box to display its own icon for the system menu, add the WS_CAPTION and WS_SYSMENU styles to the dialog box template and send the WM_SETICON message when the dialog box procedure is called with the WM_INITDIALOG message.

Send the WM_SETICON message to change or set the small and large icons of a window. In this case, because you are setting the small icon, wParam must be set to the ICON_SMALL value.

The following sample code assumes that the dialog box template has the WS_CAPTION and WS_SYSMENU styles in addition to any other styles required.

Sample Code

HICON hIcon;

hIcon = LoadImage( g_hInst,
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
return TRUE;