> Windows All > Windows All win32
Read Usenet Home | Disclaimer | Report Adult Posts

Windows Usenet Topics on Windows All win32



Windows All win32 - "How to get active child window" in Windows All


Old 10-28-2003   #1
..o.. ..
 
Default How to get active child window

Hi,

I want to find out the active child window of an application, which has the
focus.
With GetForegroundWindow() I get the window in which the user is actually
working. But this is the parent window.
For example in VC if the user is typing in source code, i want to get only
the handly of the source code window.

I have tried GetFocus(), GetCapture(), GetForegroundWindow()-GetFocus() and
GetForegroundWindow()-GetCapture(). But none of this works.

Any Ideas?

Thanks for the help,
george


 
Old 10-28-2003   #2
..r.. ..k..
 
Default Re: How to get active child window


"Georg U." <tschortschi@gmx.atwrote in message
news:bnmhbp$122n74$1@ID-32516.news.uni-berlin.de...
Quote:
Hi,

I want to find out the active child window of an application, which has
the
Quote:
focus.
With GetForegroundWindow() I get the window in which the user is actually
working. But this is the parent window.
For example in VC if the user is typing in source code, i want to get only
the handly of the source code window.

I have tried GetFocus(), GetCapture(), GetForegroundWindow()-GetFocus()
and
Quote:
GetForegroundWindow()-GetCapture(). But none of this works.

Any Ideas?

Thanks for the help,
george
GetTopWindow ?

--
Derek


 
Old 10-28-2003   #3
..o.. ..
 
Default Re: How to get active child window


"Derek Baker" <me@XYZderekbaker.eclipse.co.ukschrieb im Newsbeitrag
news:1067371589.540920@ananke.eclipse.net.uk...
Quote:

GetTopWindow ?
Sorry, but this is also not working...


 
Old 10-28-2003   #4
..i ..
 
Default Re: How to get active child window

Where is this child window, is it part of your application or another
application. If another application, what handle to the other application do
you already have????

Ali R.

"Georg U." <tschortschi@gmx.atwrote in message
news:bnmhbp$122n74$1@ID-32516.news.uni-berlin.de...
Quote:
Hi,

I want to find out the active child window of an application, which has
the
Quote:
focus.
With GetForegroundWindow() I get the window in which the user is actually
working. But this is the parent window.
For example in VC if the user is typing in source code, i want to get only
the handly of the source code window.

I have tried GetFocus(), GetCapture(), GetForegroundWindow()-GetFocus()
and
Quote:
GetForegroundWindow()-GetCapture(). But none of this works.

Any Ideas?

Thanks for the help,
george

 
Old 10-28-2003   #5
..o.. ..
 
Default Re: How to get active child window


"Ali R." <nospam@mail.comschrieb im Newsbeitrag
news:FkAnb.165$4A5.40@newssvr24.news.prodigy.com.. .
Quote:
Where is this child window, is it part of your application or another
application. If another application, what handle to the other application
do
Quote:
you already have????
It is part of another application. For example the source window of Visual
C++.
My application wants to send key events to this child window.

I have the handle to the main window of Visual C++. To get this i use
GetForegroundWindow().


 
Old 10-29-2003   #6
.... ..dot..
 
Default Re: How to get active child window

Georg U. wrote:
Quote:
I want to find out the active child window of an application, which has
the focus.
With GetForegroundWindow() I get the window in which the user is actually
working. But this is the parent window.
For example in VC if the user is typing in source code, i want to get only
the handly of the source code window.

I have tried GetFocus(), GetCapture(), GetForegroundWindow()-GetFocus()
and GetForegroundWindow()-GetCapture(). But none of this works.
GetFocus is the function that you want to use, but the problem here is that
by default every thread has its own input state and, therefore, its own
focus window. When you call GetFocus in your thread, you retrieve the focus
window in your thread. GetFocus returns NULL because the focus is in a
window created by some other thread.

The solution is to use the AttachThreadInput function to have your thread to
share the input state with the thread that owns the focus window. How would
you know that thread owns that window? This is the same thread that owns the
foreground window, which you can easily retrieve with GetForegroundWindow.

Now we are ready to write the GetGlobalFocus function that is a system-wide
equivalent of GetFocus:

HWND GetGlobalFocus()
{
// remember the focus window of the current thread
HWND hWndLocalFocus = GetFocus();

// find foreground window
HWND hWndFore = GetForegroundWindow();
if (hWndFore == NULL)
return NULL;

// get IDs of the current thread and the thread that
// owns foreground window
DWORD dwCurrID = GetCurrentThreadId();
DWORD dwForeID = GetWindowThreadProcessId(hWndFore, NULL);

// if the current thread owns the foreground window then just
// return hWndLocalFocus
if (dwForeID == dwCurrID)
return hWndLocalFocus;

// attach input states of the current thread and the foreground thread
if (!AttachThreadInput(dwCurrID, dwForeID, TRUE))
return NULL;

// now the current thread and the foreground thread have common
// input state and we can query for the focus window
HWND hWndGlobalFocus = GetFocus();

// detach threads
AttachThreadInput(dwCurrID, dwForeID, FALSE);

// restore local focus
SetFocus(hWndLocalFocus);

return hWndGlobalFocus;
}

This is all very educational but not what you would use in the real life
unless you want to support plain Windows NT 4.0 and Windows 95. Beginning
with Windows NT 4.0 Service Pack 3 and Windows 98, the system provides the
GetGUIThreadInfo function that directly returns the window having the focus.
Take a look at the MSDN do***entation, you need the GUITHREADINFO.hwndFocus
member.

-- Alex Fedotov

 
Old 11-01-2003   #7
..o.. ..
 
Default Re: How to get active child window


"Alex Fedotov" <me@alexfedotov.comschrieb im Newsbeitrag
news:P9Gnb.40$sF1.394@news.oracle.com...
Quote:

This is all very educational but not what you would use in the real life
unless you want to support plain Windows NT 4.0 and Windows 95. Beginning
with Windows NT 4.0 Service Pack 3 and Windows 98, the system provides the
GetGUIThreadInfo function that directly returns the window having the
focus.
Quote:
Take a look at the MSDN do***entation, you need the
GUITHREADINFO.hwndFocus
Quote:
member.
That was exactly what I was looking for.
Thanks

george


 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.