|
|||||
|
|
#1 |
|
|
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 |
|
|
#2 | |||
|
|
"Georg U." <tschortschi@gmx.atwrote in message news:bnmhbp$122n74$1@ID-32516.news.uni-berlin.de... Quote:
Quote:
Quote:
-- Derek |
|||
|
|
#3 | |
|
|
"Derek Baker" <me@XYZderekbaker.eclipse.co.ukschrieb im Newsbeitrag news:1067371589.540920@ananke.eclipse.net.uk... Quote:
|
|
|
|
#4 | |||
|
|
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:
Quote:
Quote:
|
|||
|
|
#5 | ||
|
|
"Ali R." <nospam@mail.comschrieb im Newsbeitrag news:FkAnb.165$4A5.40@newssvr24.news.prodigy.com.. . Quote:
Quote:
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(). |
||
|
|
#6 | |
|
|
Georg U. wrote:
Quote:
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 |
|
|
|
#7 | |||
|
|
"Alex Fedotov" <me@alexfedotov.comschrieb im Newsbeitrag news:P9Gnb.40$sF1.394@news.oracle.com... Quote:
Quote:
Quote:
Thanks george |
|||