Home > Archive > VC Language > May 2006 > Switch between active windows (different programs)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Switch between active windows (different programs)
|
|
| Joachim 2006-05-28, 7:13 pm |
| Is there a way to grab a handle or something else to be able to select and
bring to front (set as active window) a window from another program (which
you yourself is not the author of?
| |
| William DePalo [MVP VC++] 2006-05-28, 7:13 pm |
| "Joachim" <Joachim@discussions.microsoft.com> wrote in message
news:61D28A56-7FEC-4DB0-9767-4D67289852ED@microsoft.com...
> Is there a way to grab a handle or something else to be able to select and
> bring to front (set as active window) a window from another program (which
> you yourself is not the author of?
Well, maybe.
You need a window handle which usually can be gotten with FindWindow() or
EnumWindows(). Armed with that you can call SetWindowPos() to position where
you want in the Z-order.
Once upon a time, you could call SetForegroundWindow() which would both
bring the window to the fore and get it the keyboard focus. Since '98 and
2K, the function will instead flash the "button" associated with the target
window rather than set the focus.
Regards,
Will
| |
| Joachim 2006-05-28, 10:07 pm |
|
"William DePalo [MVP VC++]" wrote:
> "Joachim" <Joachim@discussions.microsoft.com> wrote in message
> news:61D28A56-7FEC-4DB0-9767-4D67289852ED@microsoft.com...
>
> Well, maybe.
>
> You need a window handle which usually can be gotten with FindWindow() or
> EnumWindows(). Armed with that you can call SetWindowPos() to position where
> you want in the Z-order.
>
> Once upon a time, you could call SetForegroundWindow() which would both
> bring the window to the fore and get it the keyboard focus. Since '98 and
> 2K, the function will instead flash the "button" associated with the target
> window rather than set the focus.
>
> Regards,
> Will
>
Thanks Will,
I did try the following small program
#include "stdafx.h"
#include <iostream>
#include <afxwin.h> //Req for CWnd
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM)
{
CString s;
CWnd::FromHandle(hwnd)->GetWindowText(s);
_tprintf(_T("Window Title: %s\n"), (LPCTSTR) s);
if (s == _T("Microsoft Outlook"))
{
RECT l_r;
CWnd::FromHandle(hwnd)->GetWindowRect(&l_r);
// CWnd::FromHandle(hwnd)->SetWindowPos(&CWnd::wndTop, l_r.left, l_r.top,
l_r.right - l_r.left, l_r.top - l_r.bottom, SWP_SHOWWINDOW);
BOOL l_res = CWnd::FromHandle(hwnd)->SetWindowPos(&CWnd::wndTop, 0, 0,
500, 500, SWP_SHOWWINDOW);
if (l_res == FALSE)
{
int a = 2;
}
}
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
EnumWindows(EnumWindowsProc, NULL);
char a;
std::cin >> a;
return 0;
}
and the SetWindowPos function succeeded for Microsoft Outlook, but it didn't
put the outlook window up front... :(
| |
| Joachim 2006-05-28, 10:07 pm |
|
"William DePalo [MVP VC++]" wrote:
> "Joachim" <Joachim@discussions.microsoft.com> wrote in message
> news:61D28A56-7FEC-4DB0-9767-4D67289852ED@microsoft.com...
>
> Well, maybe.
>
> You need a window handle which usually can be gotten with FindWindow() or
> EnumWindows(). Armed with that you can call SetWindowPos() to position where
> you want in the Z-order.
>
> Once upon a time, you could call SetForegroundWindow() which would both
> bring the window to the fore and get it the keyboard focus. Since '98 and
> 2K, the function will instead flash the "button" associated with the target
> window rather than set the focus.
>
> Regards,
> Will
>
Also, it did show a lot of no-titled windows and it didn't show the titles
of all the windows which I had opened.
|
|
|
|
|