I need to get the handle of an MDI form (child window) that has the focus. When I use the GetForeGroundWindow API, all it does is return the parent window's handle.
How do I get the handle of the active child window?
Thanks,
Jordan
Printable View
I need to get the handle of an MDI form (child window) that has the focus. When I use the GetForeGroundWindow API, all it does is return the parent window's handle.
How do I get the handle of the active child window?
Thanks,
Jordan
If it's a form of your own app, then you can use this code:
Code:Handle = MDIForm1.ActiveForm.hWnd
Sorry, I meant to say that its for another app.
I haven't found anything yet as to how to get the active child window in an external app.
Any Ideas?
These APIs may be of use to you:
Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
parameters:
· hWnd
Identifies the window whose parent window handle is to be retrieved.
Declare Function IsChild Lib "user32" Alias "IsChild" (ByVal hWndParent As Long, ByVal hwnd As Long) As Long
parameters:
· hWndParent
Identifies the parent window.
· hWnd
Identifies the window to be tested.
Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
no parameters
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
parameters:
· hWndParent
Identifies the parent window whose child windows are to be enumerated.
· lpEnumFunc
Points to an application-defined callback function. For more information about the callback function, see the EnumChildProc callback function.
· lParam
Specifies a 32-bit, application-defined value to be passed to the callback function.
See this link for more information on the EnumChildProc callback function.
[Edited by dsy5 on 10-07-2000 at 05:43 PM]
Thanks, but I tried GetActiveWindow and it still returns the handle of the Parent window when I need the handle of the active child window. :-\
Actually, if it helps any, all I really need to know is if the external child window doesn't have the focus. Still haven't been able to figure this one out.
Nevermind.. I got it :)
It turns out that you need to globally subclass the form and watch for WM_MDIACTIVATE message. If the wParam = the handle of your MDI window, then its being deactivated. If the lParam = the handle of your MDI window, then its being activated.
Thanks for the help though :)
-Jordan
Could you post a small snippet of the routine to subclass; it could be useful to others(me, too!)