The system reduces an application's main window (overlapping style) to a minimized window when the user clicks Minimize from the window menu or the application calls the ShowWindow function and specifies a value such as SW_MINIMIZE. Minimizing a window speeds up system performance by reducing the amount of work an application must do when updating its main window.
For a typical application, the system draws an icon, called the class icon, when the window is minimized, labeling the icon with the name of the window. The class icon, a static image that represents the application, is specified by the application when it registers the window class. The application assigns a handle to the class icon to the hIcon member of WNDCLASS before calling RegisterClass. The application can use the LoadIcon function to retrieve the icon handle.
Before drawing the class icon, the system sends a WM_ICONERASEBKGND message to the window procedure, enabling the application to prepare the background for drawing the icon by setting the best possible background colors for the icon. This is useful for applications that combine the icon with the current background colors. If the application processes the message, it should use the display device context provided with the message to draw the background (the wParam parameter contains a handle to the display DC). If the application does not process the WM_ICONERASEBKGND message, it should pass the message to DefWindowProc ; the function fills the icon area with the current desktop color and pattern. After sending the WM_ICONERASEBKGND message, the system sends the WM_PAINTICON message to the window procedure. The application should immediately forward this internal message to DefWindowProc.
The system does not require that a window class have a class icon. If an application sets the hIcon member of WNDCLASS to NULL, a class icon is not defined. In this case, the system sends the WM_ERASEBKGND message (instead of WM_ICONERASEBKGND ) to a window of the class whenever the window must paint the icon background. The system then sends a WM_PAINT message and the application draws an icon or another image representing the minimized window. In such cases, the application must determine when the window is minimized and draw accordingly. It can do so by calling the IsIconic function. If the function returns TRUE, the window is minimized. If an application has no class icon and fails to process WM_ERASEBKGND and WM_PAINT, the area that the system reserves for the application's icon will contain whatever was previously on the screen.