HOWTO: Set the Title Bar Icon in a Dialog Box

Last reviewed: January 23, 1998
Article ID: Q179582
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) on the following platforms: - Windows 95 - Windows NT

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 : UsrDlgs UsrRes kbcode
Version : win95; WINNT:4.0;
Platform : Win95 winnt
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 23, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.