views:

93

answers:

2

Hi,

I'm trying to set my window a child of the desktop, and i'm doing this like this:

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

This works fine in windowsXP, my window is underneath all windows and when i press the "show desktop" option the window shows and all other "normal" windows are hide.

But in Win7 when i do the above code the same window is not displayed, in spy++ i can see that my window is a child window of the SysListView32 but it not display (and it has the WM_VISIBLE style)?

What i'm missing? or what changed from winXP to win7? how can i do this to work on win7?

Update: It's got something to do with aero theme, because if i change the desktop theme to the basic then the window is displayed, but if i switch back to one of the aero theme then is hided again.

Thanks

+2  A: 

I tried your code and it works fine with my test MFC app. Except you need double colon before SetParent. Where did you put the code that you quote? I've put mine in OnCreate function. Works without problems.

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;
}
AOI Karasu
Strange, i've tried the same in a normal dialog app and in Windows7 does not appear, are you trying to do this in witch operating system? XP works fine, in win7 does not. (remember that if the theme is setted in basic then it works, does not work in aero themes)
Nuno
Perhaps the dialog window is the key here (some window (ex)style flags). I tried the code on Windows 7 ultimate 32bit and Aero turned on, not Basic mode.
AOI Karasu
I have some experience using Office2007 theme that goes with MFC for VS2008 SP1 or/and Feature Pack. I wanted to use Office frame for modal windows, not just the main frame. Under WinXP had no trouble, but under Win7 there was no proper frame, just client edge, until I added WS_CAPTION and WS_BORDER styles. So my bet is that you have to ajust the window style properly.
AOI Karasu
A: 

hi in windows 7 , the desktop windows is part of ProgMan->SHELLDLL_DefView->SysListView32 instead of directly under program in winxp.

let the following code snippet written in java

try { NativeCall.init(); IntCall ic = new 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();

}

Prasanna