2010-05-17 84 views
1

我试图把我的窗口桌面的孩子,我这样做是这样的:设置窗口始终停留在桌面上的Windows7

HWND ProgmanHwnd = 
       ::FindWindowEx(
        ::FindWindowEx(
         ::FindWindow(L"Progman", L"Program Manager"), 
         NULL, 
         L"SHELLDLL_DefView", 
         L""), 
        NULL, 
        L"SysListView32", 
        L"FolderView"); 
SetParent(m_hWnd, ProgmanHwnd); 

这在WindowsXP中正常工作,我的窗口是在所有窗口下面,当我按下“显示桌面”选项窗口显示,所有其他“正常”窗口隐藏。

但在Win7中,当我做了上面的代码,同一个窗口不显示,在spy ++中,我可以看到我的窗口是SysListView32的子窗口,但它不显示(它具有WM_VISIBLE样式)?

我失踪了什么?还是从winXP改为win7?我怎么能做到这一点在win7上工作?

更新: 它与航空主题有关,因为如果我将桌面主题更改为基本,那么窗口会显示,但是如果我切换回航空主题之一,则会再次隐藏。

谢谢

+0

贵窗口收到任何消息?也许它得到了一个节目,但然后隐藏起来?我只是拍出了KLUDGE的想法。 – baash05 2010-05-18 01:12:35

+0

Nop,我已经尝试确保是可见性,没有什么(间谍告诉可见)...是另一件我不明白的东西... – Nuno 2010-05-18 09:05:12

+0

你可以告诉每个FindWindow和FindWindowEx调用是否成功?如果不分开呼叫,并且任何呼叫失败,则调用GetLastError。 – dlb 2010-05-18 17:51:25

回答

1

我试过你的代码,它和我的测试MFC应用程序正常工作。除了在SetParent之前需要双冒号。你把你引用的代码放在哪里?我已经把我的OnCreate函数。工作没有问题。

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
     return -1; 

    // create a view to occupy the client area of the frame 
    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, 
     CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) 
    { 
     TRACE0("Failed to create view window\n"); 
     return -1; 
    } 

    HWND ProgmanHwnd = 
     ::FindWindowEx(
      ::FindWindowEx(
       ::FindWindow(L"Progman", L"Program Manager"), 
       NULL, 
       L"SHELLDLL_DefView", 
       L""), 
      NULL, 
      L"SysListView32", 
      L"FolderView"); 
    ::SetParent(m_hWnd, ProgmanHwnd); 

    return 0; 
} 
+0

奇怪的是,我已经在普通的对话框应用程序中尝试过,并且在Windows7中没有出现过,您是否试图在女巫操作系统中执行此操作? XP工作正常,在win7中没有。 (请记住,如果主题设置为基本,那么它的工作原理,在航空主题中不起作用) – Nuno 2010-05-19 13:27:17

+0

也许对话窗口是这里的关键(某些窗口(前)样式标志)。我尝试了Windows 7 Ultimate 32bit和Aero开启的代码,而不是基本模式。 – 2010-05-20 20:09:46

+0

我有一些使用Office2007主题的经验,适用于VS2008 SP1或/和Feature Pack的MFC。我想为模式窗口使用Office框架,而不仅仅是主框架。在WinXP下没有问题,但在Win7下没有适当的框架,只是客户端边缘,直到我添加了WS_CAPTION和WS_BORDER样式。所以我敢打赌,你必须适当调整窗口风格。 – 2010-05-20 20:15:58

0

桌面窗口是在WINXP ProgMan-> SHELLDLL_DefView-的一部分> SysListView32 ,而不是直接在方案。

让下面的代码段用Java编写的

尝试{ NativeCall.init(); Int32调用IC =新的IntCall(“user32.dll”,“FindWindowA”); parent = ic.executeCall(new Object [] { “ProgMan”,“Program Manager”}); ic.destroy();

} catch (Exception e) { 
     e.printStackTrace(); 
    } 
    System.out.println(" parent :"+parent); 




    try { 
     NativeCall.init(); 
     IntCall ic = new IntCall("user32.dll", "FindWindowExW"); 
     child1 = ic.executeCall(new Object[]{ 
       parent, 0,"SHELLDLL_DefView", null}); 
     ic.destroy(); 

    } catch (Exception e) { 
     e.printStackTrace(); 

    } 

    System.out.println(" child1 :"+child1); 


    try { 
     NativeCall.init(); 
     IntCall ic = new IntCall("user32.dll", "FindWindowExW"); 
     child1 = ic.executeCall(new Object[]{ 
       child1, 0,"SysListView32", null}); 
     ic.destroy(); 

    } catch (Exception e) { 
     e.printStackTrace(); 

    } 

    System.out.println(" child2 :"+child1); 

System.out.println(“parent:”+ parent);

try { 
     NativeCall.init(); 
     IntCall ic = new IntCall("user32.dll", "FindWindowA"); 
     tmp = ic.executeCall(new Object[]{ 
        "notepad", "hi.txt - Notepad"}); 
     ic.destroy(); 

    } catch (Exception e) { 
     e.printStackTrace(); 

}

相关问题