Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Set the Title Bar Icon in a Dialog Box


Summary

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.

↑ Back to the top


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

   case WM_INITDIALOG:
{
HICON hIcon;

hIcon = LoadImage( g_hInst,
MAKEINTRESOURCE(IDI_MAIN_ICON),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
0);
if(hIcon)
{
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
}
}
return TRUE;

↑ Back to the top


Keywords: kbsdkuser2003swept, kbdlg, kbhowto, kbicon, kbresource, kb

↑ Back to the top

Article Info
Article ID : 179582
Revision : 3
Created on : 4/17/2018
Published on : 4/18/2018
Exists online : False
Views : 169