Embed a form in the desktop

Source: Internet
Author: User

In the trial of some apps, found that some of the AP's window can be embedded in the desktop, so win+d can be seen when the key, very convenient. Searching the web, the principle is to set the window's parent window to the desktop.
This parent window is found under XP through FindWindow ("program Manager", "ProgMan"), but the parent window found under Win7 is not good. After watching with Spy + +, write the following section of code Finddesktopiconwnd (), the parent window can be found under XP and Win7. The child window is then called SetParent (child,parent) and can be seen on the desktop.

In QT Practice:

Theory:
0. #include <windows.h>
1. Call the Win32 API to get the desktop handle and get the window handle through Qwidget::winid ()
2. Call Win32 API Settings Two window parent-child relationship

Practice:
Add a function declaration to the private part of the header file:

Static BOOL ENUMUSERWINDOWSCB (Hwndhwnd,lparamlparam);   Static global functions
HWND Finddesktopiconwnd ();

Function implementation:

BOOL WIDGET::ENUMUSERWINDOWSCB (HWND hwnd,lparam LPARAM)
{
Long wflags = GetWindowLong (hwnd, Gwl_style);
if (! ( Wflags & ws_visible)) return TRUE;

HWND Sndwnd;
if (! ( Sndwnd=findwindowex (hwnd, NULL, L "Shelldll_defview", null))) return TRUE;
HWND Targetwnd;
if (! ( Targetwnd=findwindowex (Sndwnd, NULL, L "SysListView32", L "Folderview"))) return TRUE;

hwnd* Resulthwnd = (hwnd*) LParam;
*resulthwnd = Targetwnd;
return FALSE;
}


HWND Widget::finddesktopiconwnd ()
{
HWND Resulthwnd = NULL;
EnumWindows ((Wndenumproc) ENUMUSERWINDOWSCB, (LPARAM) &resulthwnd);
return resulthwnd;
}

With the help of the above two functions, the following work is simple and can be achieved by adding the following code where needed:

HWND Desktophwnd = Finddesktopiconwnd ();
if (Desktophwnd) SetParent (This->winid (), Desktophwnd);

From: Leisurely blog http://mypyg.blog.51cto.com/820446/263349

Embed a form in the desktop

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.