|
-
May 24th, 2001, 11:23 AM
#1
Thread Starter
Member
How To Get MDI Child Window Handle
Hi,
I have an application running say "TestApp" which has two child windows opened say Window1 and Window2. Now I need to write a program, which can give me all the Opened Child Windows Handle Number and Its Window Title. How To do it. I tried using GetTopWindows(), EnumChildWindows(), FindWindowEx() functions. But I am Unsuccessful. I am able to get the Main application Title and Handle Number using the Findwindow() Function. Can any one help me...Thanks in Advance...
-
May 24th, 2001, 01:25 PM
#2
Use EnumChildWindows. Here is the simplest form:
Add to a Module
Code:
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Debug.Print hwnd
End Function
Usage:
Code:
EnumChildWindows hwnd, AddressOf EnumChildProc, 0
-
May 26th, 2001, 10:46 AM
#3
PowerPoster
How abt the FindWindowEx API?
-
May 26th, 2001, 10:50 AM
#4
No, FindWindowEx will get the first child window, then you need to use GetWindow to retrieve the other windows.
-
May 26th, 2001, 10:56 AM
#5
PowerPoster
-
May 26th, 2001, 11:32 AM
#6
Sorry, it should be GetNextWindow (It's even simpler than GetWindow).
-
May 26th, 2001, 11:51 AM
#7
Here's a simple example.
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Sub Command1_Click()
Dim hChild As Long
hChild = FindWindowEx(Me.hwnd, 0, vbNullString, vbNullString)
Do While hChild <> 0
DoEvents
Debug.Print hChild
hChild = GetNextWindow(hChild, 2)
Loop
End Sub
-
May 26th, 2001, 10:15 PM
#8
Actually you can just use FindWindowEx to loop through all children. Here is an example:
Code:
Dim lngHWnd As Long
lngHWnd = FindWindowEx(Form1.hWnd, 0, vbNullString, vbNullString)
Do Until lngHWnd = 0
Debug.Print lngHWnd
lngHWnd = FindWindowEx(Form1.hWnd, lngHWnd, vbNullString, vbNullString)
Loop
Notice second parameter? This will tell function to look for the next child window after the hWnd passed as a second parameter.
-
May 27th, 2001, 12:08 AM
#9
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
|