在试用某些Ap时,发现有些Ap的窗口可以嵌入桌面,这样Win+D键的时候就可以看到,很方便。在网上搜索了一下,原理就是将窗口的父窗口设置成桌面。
这个父窗口在Xp下通过FindWindow("Program manager","progman")找到,但是在win7下这个方法找到的父窗口就不好用了。用spy++看了之后,写了下面一段代码findDesktopIconWnd(),在xp和win7下都可以找到这个父窗口。子窗口再调用SetParent(child,parent)就可以在桌面上看到了。
InBlock.gif static BOOL enumUserWindowsCB(HWND hwnd,LPARAM lParam)
InBlock.gif{
InBlock.gif         long wflags = GetWindowLong(hwnd, GWL_STYLE);
InBlock.gif         if(!(wflags & WS_VISIBLE)) return TRUE;
InBlock.gif
        HWND sndWnd;
InBlock.gif         if( !(sndWnd=FindWindowEx(hwnd, NULL, L "SHELLDLL_DefView", NULL)) ) return TRUE;
InBlock.gif
        HWND targetWnd;
InBlock.gif         if( !(targetWnd=FindWindowEx(sndWnd, NULL, L "SysListView32", L "FolderView")) ) return TRUE;
InBlock.gif
        HWND* resultHwnd = (HWND*)lParam;
InBlock.gif        *resultHwnd = targetWnd;
InBlock.gif
         return FALSE;
InBlock.gif}
InBlock.gif
HWND findDesktopIconWnd()
InBlock.gif{
InBlock.gif        HWND resultHwnd = NULL;
InBlock.gif        EnumWindows((WNDENUMPROC)enumUserWindowsCB, (LPARAM)&resultHwnd);
InBlock.gif         return resultHwnd;
InBlock.gif}