-
April 25th, 2009, 03:30 AM
#1
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
-
April 25th, 2009, 03:54 AM
#2
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
-
April 26th, 2009, 05:24 PM
#3
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
-
April 27th, 2009, 06:59 PM
#4
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
-
April 27th, 2009, 11:03 PM
#5
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....???
-
April 28th, 2009, 12:20 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|