Link to home
Start Free TrialLog in
Avatar of schworak
schworak

asked on

hWnd of the Word 97 document windows?

I am able to get the hWnd of the Word application window. But what I really need is the hwnd of the document window. This way I could make a custom form a child of the document instead of the application.

Anyone know how to get it?
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of egsemsem
egsemsem

I think you will need to enumerate Word child windows, for example (WordHWnd is the handle of Word application window):


'in a form
Private Sub Form_Load()
    Me.AutoRedraw = True
    EnumChildWindows WordHWnd, AddressOf EnumChildProc, ByVal 0&
End Sub


'in a module
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sSave As String
    'Get the windowtext length
    sSave = Space$(GetWindowTextLength(hwnd) + 1)
    'get the window text
    GetWindowText hwnd, sSave, Len(sSave)
    'remove the last Chr$(0)
    sSave = Left$(sSave, Len(sSave) - 1)
    If sSave <> "" Then Form1.Print sSave & " Handle: " & hwnd
    'continue enumeration
    EnumChildProc = 1
End Function
Avatar of schworak

ASKER

Wish I could make it an A+ because that is exactly what I was looking for!
thanks for the grade, and glad i could help