VC questions about the icon displayed in the sub-Window

Source: Internet
Author: User

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 !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.