CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    How to set focus on the next window after minimizing ?

    Dear Gurus.

    How can I set the focus to the next open window after I minimize some other window ?

    For example:
    I have the following apps open: IE, Word, Notepad
    When I minimize - Notepad is going to the task bar,
    At this point I lose the focus and the other open windows cannot be minimized

    (My program do minimize the current window in focus when I click something)


    This is what I tried:

    GetForegroundWindow()->ShowWindow(SW_SHOWMINIMIZED);
    Sleep(1000); // Let it minimize ?
    ::GetWindow(GetForegroundWindow()->m_hWnd, GW_HWNDNEXT);


    Any ideas ?

    Best Regards - Yovav

  2. #2
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    Re: How to set focus on the next window after minimizing ?

    OK, I partially managed to do it with the following code:

    GetForegroundWindow()->ShowWindow(SW_SHOWMINIMIZED);

    CWnd* pCurrentWindow;
    POINT pt;

    GetCursorPos(&pt);
    pCurrentWindow = WindowFromPoint(pt);
    pCurrentWindow->SetForegroundWindow();


    The problem is that it will only get the focus of windows behind the cursor (mouse)

    Any idea how to get the next window regardless to the cursor location ?

    Last edited by Yovav; April 25th, 2009 at 05:10 AM.
    Best Regards - Yovav

  3. #3
    Join Date
    Apr 2009
    Posts
    47

    Re: How to set focus on the next window after minimizing ?

    ....
    EnumWindows(&EnumWindowsProc, (LONG_PTR)this); //second param is the param that our callback below will receive
    ...

    #include <windowsx.h>
    BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lParam)
    {
    _if (current hwnd is top level)
    ShowWindow(hwnd, SW_MINIMIZE);
    return TRUE;
    }

    hth

  4. #4
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    Re: How to set focus on the next window after minimizing ?

    Thanks for the tip,

    it causes all the windows to close,

    What would be a good way to detect the current active window ?


    I tried this:

    if (GetActiveWindow() == hwnd)
    ShowWindow(hwnd, SW_SHOWMINIMIZED);

    if ((GetWindowLong(hwnd, GWL_STYLE) & WS_ACTIVECAPTION))
    ShowWindow(hwnd, SW_SHOWMINIMIZED);



    ?

    Best Regards - Yovav

  5. #5
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Exclamation Re: How to set focus on the next window after minimizing ?

    Do you want to minimize all the opened windows or some of the selected windows....???

  6. #6
    Join Date
    Apr 2001
    Location
    Las Vegas
    Posts
    539

    Re: How to set focus on the next window after minimizing ?

    Just the next window that gets the focus after the last one was minimized,

    I was using this:
    GetForegroundWindow()->ShowWindow(SW_SHOWMINIMIZED);
    // Put the focus on the next window under the cursor
    GetCursorPos(&pt);
    pCurrentWindow = WindowFromPoint(pt);
    pCurrentWindow->SetForegroundWindow();

    But its only good as long as the cursor (or mouse) is on the same area of the window,

    for example - if you move the mouse to the right top corner - it will not minimize anything else (just the desktop icons) but not the other open windows...

    Best Regards - Yovav

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured