Microsoft KB Archive/179582

{|
 * width="100%"|

HOWTO: Set the Title Bar Icon in a Dialog Box

 * }

Q179582

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)

-

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.

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; Additional query words: Icon Dialog

Keywords : _IK kbDlg kbIcon kbOSWinNT400 kbOSWin2000 kbResource kbSDKWin32 kbGrpDSUser kbOSWin95 kbOSWin98

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch