Click to See Complete Forum and Search --> : Textbox handle
Orfen
Aug 17th, 2000, 04:33 AM
Hi,
I would like to edit a textbox, but I don't know how to
get its handle.
Should I use SendMessage ?
Thanks for your answers.
oetje
Aug 17th, 2000, 05:17 AM
dim Handle as long
Handle=Text1.Hwnd
Orfen
Aug 17th, 2000, 06:04 AM
Thanks oetje,
But the Window I would edit is not one of my VB program.
It's a Window from another program, and I want to write a
text in one of its textbox.
Use FindWindowEx. This example will send the A key to Notepad. (so make sure Notepad is pre-opened)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CHAR = &H102
Private Sub Command1_Click()
Dim hParent As Long
Dim hChild As Long
'Get the hWnd of parent window
hParent = FindWindow("Notepad", vbNullString)
'Get the hWnd of the Edit Control
hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
'Send the "A" key to it
Call SendMessage(hChild, WM_CHAR, vbKeyA, 0)
End Sub
Orfen
Aug 17th, 2000, 09:49 AM
I didn't exactly know if I had to use the parent window,
now it's ok for me.
Thank for your help.
Specifing the parent window will narrow it down. If you don't specify the parent window, it will just use desktop window.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.