davidds@microsoft.UUCP (David D'SOUZA) (12/24/90)
When you minimize your application, Window's will draw the class icon on the desktop for you. Now what if you want to use a different icon at different times? Here's how to do this: Register your window class with a NULL hIcon. This tells windows that you want to draw your own icon. (The Modeless dialog box class automatically registered by windows already has a null icon so you can use this method to draw your own icons too.) HANDLE hIcon; /* Icon for this application you initialized some * place else. Perhaps the return value from LoadIcon, eh? */ In your Window Proc for the window being iconified, you need the following code: /* Try with and without this to see what it does. Basically, this * neat little hack lets you return the icon you want to use * when a user drags this iconic window around the screen. Windows converts * color icons to mono cursors automatically. (Hint: Without this, you will * drag a white box.) */ case WM_QUERYDRAGICON: return((LONG)(WORD)hIcon); break; /* The paint routine */ case WM_PAINT: { PAINTSTRUCT ps; if (IsIconic(hWnd)) { BeginPaint(hWnd, (LPPAINTSTRUCT)&ps); /* Paint the desktop background into the window so that the transparent parts of the icon show through. Assumes MM_TEXT mapping mode...*/ DefWindowProc(hWnd, WM_ICONERASEBKGND, (WORD)ps.hdc, 0L); /* Use 0,0 as the x,y location of the icon. Don't use the rect in the paintstruct since that is the update rect.*/ DrawIcon(ps.hdc, 0,0, hIcon); EndPaint(hWnd, (LPPAINTSTRUCT)&ps); } else /* Or do your own paint routine here. */ return(DefWindowProc(hWnd, message, wParam, lParam)); } There may be some flicker when this is drawn. To fix that, do the following WM_ERASEBKGND: if (IsIconic(hWnd)) /* Don't erase the background now since we will do it at paint time when we paint our icon...*/ return(TRUE); else return(DefWindowProc(hWnd, message, wParam, lParam)); BTW: This will only work for apps you create. It won't help you (unless you have the source) make dos boxes get the same icon as seen in the progman group window etc. Also, don't bother asking me how to find out what icon the user has chosen for your app in the progman group. Problems like this will be addressed post 3.0...