The following is an example that has been circulating on the Internet for a long time. Do you rarely find any problems ?? Red indicates the problem.
Change the window icon and display it in the taskbar
The following two functions can display a task entry to the taskbar and change their icons for each subwindow in the application. It is particularly useful for applications that hide the main window like QQ.
// Function purpose: Change the icon of a window and display it in the taskbar, task switching entry, and task manager.
// Parameter description:
// The Window handle for the hwnd to change the icon
// Hlargeicon 32*32
// The hsmallicon icon is displayed in addition to the task switch bar. the icon is 16*16.
// The icon displayed on hicon, 32*32. It is automatically compressed to 16*16 when it is displayed in other places except the Task Switch bar.
// Note:
// This function is powerless for the mode dialog box.
// If hicon is null, the function does not change the window icon, but displays the original icon in the taskbar,
// Task Switch entry, in the task manager.
// This function displays the icon to the taskbar, Task Switch entry, and,
// In the task manager, the parent window pointer is no longer available after the call is completed.
Bool sendwndicontotaskbar (hwnd, hicon hlargeicon, hicon hsmallicon );
Bool sendwndicontotaskbar (hwnd, hicon );
Bool cuiapp: sendwndicontotaskbar (hwnd, hicon hlargeicon, hicon hsmallicon)
{
Bool ret = true;
Assert (hwnd );
If (! : Iswindow (hwnd ))
Return false;
// Obtain the window pointer
Cwnd * pwnd;
Pwnd = pwnd-> fromhandle (hwnd );
Assert (pwnd );
If (! Pwnd)
Return false;
// Set the parent window to null
If (pwnd-> getparent ())
If (: setwindowlong (hwnd, gwl_hwndparent, null) = 0)
Return false;
If (! (Pwnd-> modifystyle (null, ws_overlappedwindow )))
Ret = false;
// Set the window icon
If (hlargeicon & hsmallicon)
{
Pwnd-> seticon (hsmallicon, false );
Pwnd-> seticon (hlargeicon, true );
}
Return ret;
}
Bool cuiapp: sendwndicontotaskbar (hwnd, hicon)
{
Bool ret = true;
Assert (hwnd );
If (! : Iswindow (hwnd ))
Return false;
// Obtain the window pointer
Cwnd * pwnd;
Pwnd = pwnd-> fromhandle (hwnd );
Assert (pwnd );
If (! Pwnd)
Return false;
// Set the parent window to null
If (pwnd-> getparent ())
If (: setwindowlong (hwnd, gwl_hwndparent, null) = 0)
Return false;
If (! (Pwnd-> modifystyle (null, ws_overlappedwindow )))
Ret = false;
// Set the window icon
Pwnd-> seticon (hicon, true );
Pwnd-> seticon (hicon, false );
Return ret;
}
If the main window is hidden (always hidden, only closed) when it is generated, how does the subwindow close the main window?
If (: setwindowlong (hwnd, gwl_hwndparent, null) = 0)
Changed to If (: setparent (hwnd, null) = 0) to display the icon in the subwindow. the pointer in the main window can also be used in the subwindow, but this poses a problem, that is, the subwindow cannot be displayed in the taskbar !!