-
I've created a Word application in my VB app using the Word Object Library. I need to be able to get the handle of this word application, as I want to show a form through my VB app with Word as it's owner,
Ie: frmWordFunctions.Show 1, hWndWordApp
Any ideas ????
Ps. Any info on getting another windows handle full stop would also be appreciated.
Thanx!!!!
-
if you know the caption of Word (the title bar), you can use this code
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Function GetWindowsHandle(WindowsCaption as string) as long
GetWindowsHandle = FindWindow(CLng(0), WindowsCaption)
End Function
-
Use the FindWindow API. Here is an example of how to get the handle for Calculator.
Code for a module.
Code:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
' lpClassName is the name of the Window Class
' lpWindowName is the title of the window
Code for a CommandButton.
Code:
'If you pass 0 as the parameter, it will find a window
'with any class or any name.
CalcHandle = FindWindow(CLng(0), "Calculator")
-
If you have a variable caption you could find the window by it's classname:
Code:
hwnd = FindWindow(classname, vbnullstring)