How To Set the Title Bar Icon in a Dialog Box (179582)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0

This article was previously published under Q179582

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;
				

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbDlg kbhowto kbIcon kbResource KB179582