Getting a Dialog to Use an Icon When Minimized

Last reviewed: September 29, 1995
Article ID: Q114612
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

The standard Windows dialog box does not have an icon when it is minimized. A dialog box can be made to use an icon by replacing the standard dialog box class with a private dialog box class.

MORE INFORMATION

The standard dialog box class specifies NULL as the value of the hIcon field of its WNDCLASS structure. So no icon is drawn when the standard dialog box is minimized.

An icon can be specified by getting the dialog to use a private class as follows:

  1. Register a private class.

          WNDCLASS wc;
    

          wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
          wc.lpfnWndProc = DefDlgProc;
          wc.cbClsExtra = 0;
          wc.cbWndExtra = DLGWINDOWEXTRA;
          wc.hInstance = hinst;
          wc.hIcon = LoadIcon(hinst, "DialogIcon");
          wc.hCursor = LoadCursor(NULL, IDC_ARROW);
          wc.hbrBackground = COLOR_WINDOW + 1;
          wc.lpszMenuName = NULL;
          wc.lpszClassName = "MyDlgClass";
          RegisterClass(&wc);
    

    NOTE: The default dialog window procedure, DefDlgProc(), is used as the window procedure of the class. This causes windows of this class to behave as standard dialogs. The cbWndExtra field has to be assigned to DLGWINDOWEXTRA - the dialog box stores its internal state information in these extra window bytes. The icon to be used when the dialog box is minimized is assigned to the hIncon field.

  2. Get the dialog box to use the private class.

    Use the CLASS statement in the dialog box template to get the dialog box to use the private class:

          IDD_MYDIALOG DIALOG 0, 0, 186, 92
          CLASS "MyDlgClass"
          :
    

  3. Create the dialog box using DialogBox() or CreateDialog().

          DialogBox (hinst,
    
                     MAKEINTRESOURCE (IDD_MYDIALOG),
                     NULL,
                    (DLGPROC)MyDlgFunc);
    
       MyDlgFunc() is the dialog function implemented by the application. When
       the dialog box is minimized, it will use the icon specified in the
       private class.
    


Additional reference words: 3.10 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrDlgs


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: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.