Results 1 to 11 of 11

Thread: Window Handles.....

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    59

    Unhappy

    Hello, I am trying to code a program that would send keystrokes to an application, and i don't want to use the sendkeys utilities. First I want to get the handles for Intenet Explorer but i keep getting a handle of 0 which is invalid. I use the FindWindow API but when i put this code on the commnad button: intStr=FindWindow("IExplorer",vbNullString) all it gives me is a 0, which is not the handle. Can somebody please help me out. I want to get the Hanldes for Internet Explorer. Do i have to use a different API or what? i neeedddd heeelppp thanxx.

  2. #2
    Guest
    I don't think IExplorer is the correct classname. I believe it's IEFrame.

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    
    Private Sub Command1_Click()
    
        'Get the Handle of IE
        Retval = FindWindow("IEFrame", 0&)
        
    End Sub

  3. #3
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Im new to classes, how do you determine class names of other program sis there a api function??
    thanks
    Matt

  4. #4
    Guest
    Use GetClassName

    Code:
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    
    Private Sub Command1_Click()
    
        Dim sClass As String
        sClass = Space(255)
        
        'Get the ClassName of Command1
        GetClassName Command1.hwnd, sClass, 255
        'Remove the Null character at the end of the String
        sClass = Left(sClass, InStr(1, sClass, vbNullChar) - 1)
        
        MsgBox sClass
    
    End Sub

  5. #5
    Guest
    If you want to get the ClassName of a Window on a foreign App: (Make sure to pre-open Calculator)

    Code:
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As Any, ByVal lpsz2 As Any) As Long
    
    Private Sub Command1_Click()
    
        Dim sClass As String
        Dim hParent As Long
        Dim hChild As Long
        sClass = Space(255)
        
        'Get the Handle of the Parent Window (Calculator)
        hParent = FindWindow(0&, "Calculator")
        'Get the Handle of a ChildWindow with a name of "Hex"
        hChild = FindWindowEx(hParent, 0&, 0&, "Hex")
        'Get the Classname
        GetClassName hChild, sClass, 255
        'Remove the Null Character
        sClass = Left(sClass, InStr(1, sClass, vbNullChar) - 1)
        
        MsgBox sClass
    
    End Sub

  6. #6
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Thanks megatron..ill having to experiment some with it
    Matt

  7. #7
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    megatron I don't get anything when I tried that code. I had calcultor open..??
    Matt

  8. #8
    Guest
    Is you Calculator set to Scientific? (In Calculator, go to View > Scientific and then try it)

  9. #9
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    I got some of it to work within the form. I tried to get the class name of the form and it said thunderform. do you know if that is valid??Thanks for your help
    Matt

  10. #10
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Wink

    yes now it works..I was wondering where it was going to find "hex"
    Matt

  11. #11
    Guest
    Yes, that Thunder stuff is normal because it's the class name for the Form. In VB, most of the classes have a prefix of Thunder, ie:

    Code:
    Visual Basic            Windows
    ===============================
    ThunderCommandButton    Button
    ThunderComboBox         ComboBox
    ThunderListBox          ListBox
    ThunderTextBox          Edit
    
    etc.
    [Edited by Megatron on 08-09-2000 at 02:14 PM]

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