dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: SetForegroundWindow() problems on Vista

  1. #1
    Join Date
    May 2002
    Posts
    1,435

    SetForegroundWindow() problems on Vista

    I have an application that is implemented as a COM Automation server. When my application is called by a client it displays its window and then calls SetForegroundWindow() so that it shows itself in front of the client.

    This method has worked for years on 95, 98, 2000 and XP but it fails on Vista. SetForegroundWindow() returns TRUE but my application's window does not display in front of the client.

    As an alternative solution I tried calling SetWindowPos() with the parameter HWND_TOP but that behaves the same as SetForegroundWindow(). However, if I change HWND_TOP to HWND_TOPMOST my application does come out on top but it now stays on top and other applications below it cannot be activated. That behavior is also different from previous versions of Windows.

    Has anyone else run into these problems on Vista yet? Any solutions or suggestions?

  2. #2
    Join Date
    Jul 2008
    Posts
    1

    Re: SetForegroundWindow() problems on Vista

    I have the same problem in Vista. This issue has been for a year! Have someone provide a solution?

  3. #3
    Join Date
    Dec 2008
    Posts
    1

    Talking Re: SetForegroundWindow() problems on Vista

    Quote Originally Posted by 0xC0000005 View Post
    I have an application that is implemented as a COM Automation server. When my application is called by a client it displays its window and then calls SetForegroundWindow() so that it shows itself in front of the client.

    This method has worked for years on 95, 98, 2000 and XP but it fails on Vista. SetForegroundWindow() returns TRUE but my application's window does not display in front of the client.

    As an alternative solution I tried calling SetWindowPos() with the parameter HWND_TOP but that behaves the same as SetForegroundWindow(). However, if I change HWND_TOP to HWND_TOPMOST my application does come out on top but it now stays on top and other applications below it cannot be activated. That behavior is also different from previous versions of Windows.

    Has anyone else run into these problems on Vista yet? Any solutions or suggestions?
    I don't know if you've figured this hack out since your original post but since YOU gave me clue to try this, I wanted to make sure that I returned the favor.

    The trick is to do SetWindowPos twice, the first one with HWND_TOPMOST but NOT SWP_SHOWWINDOW, then the second one with HWND_NOTOPMOST and WITH SWP_SHOWWINDOW.

    This ends up showing a ForegroundWindow which is not TOPMOST and it's working on every cse I've tried it on my Vista machine.

    bool SetForegroundWindowEx(hWnd Wnd)
    {

    if (isVista) //roll your own function here
    {
    SetWindowPos(Wnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE OR SWP_NOSIZE);
    SetWindowPos(Wnd,HWND_NOTOPMOST,0,0,0,0,SWP_SHOWWINDOW OR SWP_NOMOVE
    OR SWP_NOSIZE);
    return GetForegroundWindow()==Wnd;
    }
    else
    {
    return SetForegroundWindow(Wnd);
    }
    }

    Hope this helps!

  4. #4
    Join Date
    Jan 2008
    Posts
    178

    Re: SetForegroundWindow() problems on Vista

    It's the wrong method. See KB and STTW

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)