Results 1 to 4 of 4

Thread: Get a window's handle

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    63
    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!!!!

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    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
    KWell

  3. #3
    Guest
    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")

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you have a variable caption you could find the window by it's classname:
    Code:
    hwnd = FindWindow(classname, vbnullstring)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width