Article ID: 108936
Article Last Modified on 7/11/2005
BOOL WINAPI GenericDlgProc (HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
RECT rect ;
switch (msg) {
case WM_INITDIALOG:
hIcon = LoadIcon(); // Load the icon that is to be displayed
// when minimized.
return TRUE ;
case WM_ERASEBKGND:
if (IsIconic(hwnd) && hIcon) {
SendMessage( hwnd, WM_ICONERASEBKGND, wParam, 0L );
return TRUE;
}
break;
case WM_QUERYDRAGICON:
return (hIcon);
case WM_PAINT: {
PAINTSTRUCT ps;
BeginPaint( hwnd, &ps );
if (IsIconic(hwnd)) //*** If iconic, paint the icon.
{
if (hIcon) {
//center the icon correctly...
GetClientRect(hwnd, &rect) ;
rect.left = (rect.right - GetSystemMetrics(SM_CXICON))
>> 1;
rect.top = (rect.bottom - GetSystemMetrics(SM_CYICON))
>> 1;
DrawIcon( ps.hdc, rect.left, rect.top, hIcon );
}
}
EndPaint( hwnd, &ps );
}
break;
}
return FALSE;
} //*** GenericDlgProc
The workaround described above assumes that the dialog box belongs to the
predefined dialog class. For private dialog box classes, there is no need
to manually draw the icon for the dialog box when it is minimized. You can
specify the icon while registering the dialog box class. Remember to set
the cbWndExtra field to DLGWINDOWEXTRA. When the dialog box is minimized,
the icon will be painted automatically.
Additional query words: DLGMAIN
Keywords: kbhowto kbdlg KB108936