MORE INFORMATION
When an application for the Microsoft Windows operating system
registers a window class, it specifies a handle to an appropriate icon
in the hIcon member of the
WNDCLASS data structure. This can be an
application-specific icon loaded from the application's resources or
the default application icon provided with Windows.
If the application includes its own icon, Windows sends a WM_PAINTICON
message when the user minimizes the application. If the application
passes the WM_PAINTICON message to the
DefWindowProc function, Windows paints the icon in the appropriate location.
If the application specifies the default icon or no icon, Windows does
not send a WM_PAINTICON message when the user minimizes the
application; instead, it sends a WM_PAINT message. When the
application receives the WM_PAINT message, it can either pass the
message to
DefWindowProc so that Windows will paint the default icon, or the application can paint the icon dynamically.
Because the application cannot process the WM_PAINTICON message,
except to pass it to
DefWindowProc, it has been removed from the
documentation for version 3.1 of the Windows SDK.
The following code demonstrates how to process the WM_PAINT message to
paint the icon. Given a window handle, the
IsIconic function indicates whether the window is an icon:
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
if (IsIconic(hWnd))
{
SendMessage(hWnd, WM_ICONERASEBKGND, (WORD)ps.hdc, 0);
DrawIcon(ps.hdc, 0, 0, hIcon);
}
EndPaint(hWnd, &ps);
}
break;
When the application processes the WM_QUERYDRAGICON message by
returning the handle to its icon, Windows converts the icon to a
cursor when the user drags the icon window with the mouse.
case WM_QUERYDRAGICON:
return hIcon;
Because the application paints the icon background when it processes
the WM_PAINT message, the following code prevents the screen from
flashing:
case WM_ERASEBKGND:
if (IsIconic(hWnd))
return TRUE;
else
return DefWindowProc(...);
break;
DefWindowProc erases the background.