DOCUMENT:Q74539 06-NOV-1999 [win16sdk] TITLE :HOWTO: Draw the Icon for a Minimized Application PRODUCT :Microsoft Windows Software Development Kit PROD/VER:WINDOWS:3.0,3.1 OPER/SYS: KEYWORDS:kb16bitonly kbIcon kbGrpDSUser kbOSWin310 kbWndwProp ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1 ------------------------------------------------------------------------------- SUMMARY ======= The text below describes how an application developed for the Microsoft Windows graphical environment can draw its own icon when it is minimized. An application can use these techniques to draw different icons to indicate its state. In Windows version 3.1, an application can initiate a dynamic data exchange (DDE) conversation with the Windows Program Manager to determine which icon the user has associated with an application and can then draw that icon using the following techniques. MORE INFORMATION ================ To draw its own icon when minimized, a Windows-based application performs the following five steps: 1. When the application registers its main window's window class, specify NULL as the value of the hIcon member of the WNDCLASS data structure. 2. Create a static variable to store the icon the application will use, as follows: HICON hIcon; Initialize this variable to the value returned from the CreateIcon or LoadIcon function. 3. To draw the icon, process the WM_PAINT message in the main window's window procedure as follows: case WM_PAINT: { PAINTSTRUCT ps; if (IsIconic(hWnd)) { BeginPaint(hWnd, (LPPAINTSTRUCT)&ps); // Paint the desktop window background. DefWindowProc(hWnd, WM_ICONERASEBKGND, (WORD)ps.hdc, 0L); // Draw the icon on top of it. DrawIcon(ps.hdc, 0,0, hIcon); EndPaint(hWnd, (LPPAINTSTRUCT)&ps); } else return DefWindowProc(hWnd, message, wParam, lParam); } 4. To prevent a screen flash when the application draws the icon, process the WM_ERASEBKGND message in the main window's window procedure, as follows: case WM_ERASEBKGND: if (IsIconic(hWnd)) // Do not erase the background now. When the application // paints its icon, it will erase the background. return TRUE; else return DefWindowProc(hWnd, message, wParam, lParam); 5. Process the WM_QUERYDRAGICON message in the main window's window procedure. When the user is about to drag a window that has no icon defined for its window class, Windows sends it a WM_QUERYDRAGICON message. The code below causes Windows to create a dragging cursor based on the specified icon. Windows automatically converts a color icon to a monochrome cursor. case WM_QUERYDRAGICON: return (LONG)(WORD)hIcon; break; Additional query words: ====================================================================== Keywords : kb16bitonly kbIcon kbGrpDSUser kbOSWin310 kbWndwProp Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310 Version : WINDOWS:3.0,3.1 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. Copyright Microsoft Corporation 1999.