PDA

Click to See Complete Forum and Search --> : Window Handles.....


Archon
Aug 5th, 2000, 06:16 PM
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.

Aug 5th, 2000, 06:27 PM
I don't think IExplorer is the correct classname. I believe it's IEFrame.


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

MPrestonf12
Aug 8th, 2000, 07:25 PM
Im new to classes, how do you determine class names of other program sis there a api function??
thanks

Aug 8th, 2000, 07:39 PM
Use GetClassName


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

Aug 8th, 2000, 07:45 PM
If you want to get the ClassName of a Window on a foreign App: (Make sure to pre-open Calculator)


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

MPrestonf12
Aug 8th, 2000, 07:45 PM
Thanks megatron..ill having to experiment some with it

MPrestonf12
Aug 9th, 2000, 12:50 PM
megatron I don't get anything when I tried that code. I had calcultor open..??

Aug 9th, 2000, 12:58 PM
Is you Calculator set to Scientific? (In Calculator, go to View > Scientific and then try it)

MPrestonf12
Aug 9th, 2000, 12:58 PM
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

MPrestonf12
Aug 9th, 2000, 01:01 PM
yes now it works..I was wondering where it was going to find "hex"

Aug 9th, 2000, 01:10 PM
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:


Visual Basic Windows
===============================
ThunderCommandButton Button
ThunderComboBox ComboBox
ThunderListBox ListBox
ThunderTextBox Edit

etc.


[Edited by Megatron on 08-09-2000 at 02:14 PM]