Mar 9th, 2008, 10:20 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Help with sendmessage please
I have a problem I try to send a message to a combobox on a app , the problem is there are two combobox with the same name ,my code is hitting the first one ,but I need it to send to the second one not the first one. How do i make loop though and send message to the second combobox? here me code
d Code:
Option Explicit
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 SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const WM_SETFOCUS = &H7
Private Sub Command1_Click()
Dim nPad As Long, editx As Long
nPad = FindWindow(vbNullString, "Login to NetZero")
editx = FindWindowEx(nPad, 0&, "zuicombobox", vbNullString)
If editx Then
Call SendMessageByString(editx, WM_SETTEXT, 0, "portland")
Text1.Text = "found it"
Else
Text1.Text = "No find"
'Call SendMessageByString(editx, BM_CLICK, 0, "Send Some")
End If
End Sub
Live life to the fullest!!
Mar 9th, 2008, 11:03 PM
#2
Re: Help with sendmessage please
Using the control id, you may be able to uniquely identify the controls.
Eidted : GetWindowLong() with GWL_ID Should help you to retrive the ID's
Last edited by Fazi; Mar 9th, 2008 at 11:19 PM .
Mar 10th, 2008, 12:02 AM
#3
Thread Starter
Fanatic Member
Re: Help with sendmessage please
how do I uses "GetWindowLong() with GWL_ID " ?
Originally Posted by
Fazi
Using the control id, you may be able to uniquely identify the controls.
Eidted : GetWindowLong() with GWL_ID Should help you to retrive the ID's
Live life to the fullest!!
Mar 10th, 2008, 12:34 AM
#4
Re: Help with sendmessage please
this is an example in API Guid. hope it will help you,
Code:
'This project needs a TextBox
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const ES_NUMBER = &H2000&
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
Dim curstyle As Long, newstyle As Long
'retrieve the window style
curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
If Flag Then
curstyle = curstyle Or ES_NUMBER
Else
curstyle = curstyle And (Not ES_NUMBER)
End If
'Set the new style
newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)
'refresh
NumberText.Refresh
End Sub
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
SetNumber Text1, True
Me.Caption = "Now, try typing some letters into the textbox"
End Sub
also you need to look at here for the documentation of the api
http://msdn2.microsoft.com/en-us/lib...84(VS.85).aspx
Mar 10th, 2008, 12:40 AM
#5
Re: Help with sendmessage please
Or if you enumerate the windows at that level you can loop through the windows to the next one seeing how its only got two combo boxes at that level.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 10th, 2008, 01:08 AM
#6
Thread Starter
Fanatic Member
Re: Help with sendmessage please
yes that what I want to do!! but how do I do that?
Originally Posted by
RobDog888
Or if you enumerate the windows at that level you can loop through the windows to the next one seeing how its only got two combo boxes at that level.
Live life to the fullest!!
Mar 10th, 2008, 01:15 AM
#7
Re: Help with sendmessage please
See if this helps you any, just change the FindWindow code in Command1 to reflect the "title" and "class" names of the window you are after.
Attached Files
Mar 10th, 2008, 01:50 AM
#8
Re: Help with sendmessage please
Originally Posted by
newprogram
yes that what I want to do!! but how do I do that?
Use the EnumWindows API.
Code:
Private Declare Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 10th, 2008, 01:55 AM
#9
Thread Starter
Fanatic Member
Re: Help with sendmessage please
OK so here what i got
the first one this is what my code is hitting now
zuicombobox: Hwnd=330288, Class=zuicombobox,IDType=class
and the second one this is the one I need to sendmessage to
zuicombobox: Hwnd=723584, Class=zuicombobox,IDType=class
I see the Hwnd is diffent but how to I send by the hwnd?
like
editx = FindWindowEx(nPad, 0&, "zuicombobox", "Hwnd=723584") 'Does the hwnd go here
Live life to the fullest!!
Mar 10th, 2008, 02:01 AM
#10
Re: Help with sendmessage please
Originally Posted by
newprogram
and the second one this is the one I need to sendmessage to
zuicombobox: Hwnd=723584, Class=zuicombobox,IDType=class
Once you have the Hwnd to the "edit" class of a combo box, text box or whatever just use that Hwnd...
SendMessageByString 723584, WM_SETTEXT, 0, "Sometext"
Last edited by Edgemeal; Mar 10th, 2008 at 02:07 AM .
Mar 10th, 2008, 02:06 AM
#11
Re: Help with sendmessage please
Originally Posted by
newprogram
OK so here what i got
the first one this is what my code is hitting now
zuicombobox: Hwnd=330288, Class=zuicombobox,IDType=class
and the second one this is the one I need to sendmessage to
zuicombobox: Hwnd=723584, Class=zuicombobox,IDType=class
I see the Hwnd is diffent but how to I send by the hwnd?
like
editx = FindWindowEx(nPad, 0&, "zuicombobox", "Hwnd=723584") 'Does the hwnd go here
You are not storing handles in variables are you? They change each time the windows are created.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 10th, 2008, 02:24 AM
#12
Thread Starter
Fanatic Member
Re: Help with sendmessage please
no I was going to grab them each time before sending the message.
Originally Posted by
RobDog888
You are not storing handles in variables are you? They change each time the windows are created.
Live life to the fullest!!
Mar 10th, 2008, 02:32 AM
#13
Re: Help with sendmessage please
Originally Posted by
newprogram
no I was going to grab them each time before sending the message.
From your first post I figured you knew that much!
Mar 10th, 2008, 02:57 AM
#14
Re: Help with sendmessage please
Yes, but you never know unless you are the one writting the code. Also from the example ...
"editx = FindWindowEx(nPad, 0&, "zuicombobox", "Hwnd=723584") "
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Mar 10th, 2008, 03:11 AM
#15
Re: Help with sendmessage please
Mar 10th, 2008, 03:13 AM
#16
Re: Help with sendmessage please
but control ID's never change, correct?
Mar 10th, 2008, 03:28 AM
#17
Re: Help with sendmessage please
Originally Posted by
Fazi
this is an example in API Guid. hope it will help you,
[CODE]
All that does is only allow numbers in a text box, I don't see what that has to do with the OPs question? Either I need sleep or you do.
Mar 10th, 2008, 04:09 AM
#18
Re: Help with sendmessage please
my example in no 4# is just an example of using getwindowlong()
Mar 10th, 2008, 12:11 PM
#19
Thread Starter
Fanatic Member
Re: Help with sendmessage please
I did it with your guys help!! I took Edgemeal program add some stuff to and it works great!!!
here the code
vb Code:
'in a module
Option Explicit
Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Function TrimNull(startstr As String) As String
Dim pos As Integer
pos = InStr(startstr, Chr$(0))
If pos Then
TrimNull = Left$(startstr, pos - 1)
Exit Function
End If
TrimNull = startstr
End Function
Private Function GetWindowIdentification(ByVal hwnd As Long, _
sIDType As String, sClass As String) As String
Dim nSize As Long
Dim sTitle As String
nSize = GetWindowTextLength(hwnd)
'if the return is 0, there is no title
If nSize > 0 Then
sTitle = Space$(nSize + 1)
Call GetWindowText(hwnd, sTitle, nSize + 1)
sIDType = "title"
sClass = Space$(64)
Call GetClassName(hwnd, sClass, 64)
Else
'no title, so get the class name instead
sTitle = Space$(64)
Call GetClassName(hwnd, sTitle, 64)
sClass = sTitle
sIDType = "class"
End If
GetWindowIdentification = TrimNull(sTitle)
End Function
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sTitle As String
Dim sClass As String
Dim sIDType As String
'get the window title/class name
sTitle = GetWindowIdentification(hwnd, sIDType, sClass)
'add to our list
Form1.List1.AddItem sTitle & ": Hwnd=" & hwnd & ", Class=" & TrimNull(sClass) & ", IDType=" & sIDType
EnumChildProc = 1
End Function
'in the form
Option Explicit
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 SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC
Private Const BM_CLICK = &HF5
Private Const WM_SETFOCUS = &H7
Private Sub Command1_Click()
Dim Lhwnd As Long
List1.Clear
' get hwnd to our dialog/program window
Lhwnd = FindWindow(vbNullString, "Login to NetZero")
If Lhwnd Then ' get childs
Call EnumChildWindows(Lhwnd, AddressOf EnumChildProc, &H0)
End If
End Sub
Private Sub Command2_Click()
Text1.Text = List1.List(4)
End Sub
Private Sub Command3_Click()
Call SendMessageByString(Text1.Text, WM_SETTEXT, 0, "portland")
End Sub
Private Sub Form_Load()
End Sub
Private Sub Text1_Change()
Text1.Text = Replace(Text1.Text, "zuicombobox: Hwnd=", "")
Text1.Text = Replace(Text1.Text, ", Class=zuicombobox, IDType=class", "")
End Sub
Live life to the fullest!!
Mar 10th, 2008, 07:20 PM
#20
Re: Help with sendmessage please
Originally Posted by
newprogram
I did it with your guys help!! I took Edgemeal program add some stuff to and it works great!!!
here the code
Code:
'
'
Private Sub Command3_Click()
Call SendMessageByString(Text1.Text , WM_SETTEXT, 0, "portland")
End Sub
'
'
You need a handle here not a text string
Mar 10th, 2008, 07:31 PM
#21
Re: Help with sendmessage please
Originally Posted by
jmsrickland
You need a handle here not a text string
Ya convert the text string to a long, since thats what the API expects.
Call SendMessageByString(Clng(Text1.Text), WM_SETTEXT, 0, "portland")
Mar 10th, 2008, 07:37 PM
#22
Re: [RESOLVED] Help with sendmessage please
He will first have to extract out the handle from the entire text string.
Mar 10th, 2008, 08:04 PM
#23
Re: [RESOLVED] Help with sendmessage please
Originally Posted by
jmsrickland
He will first have to extract out the handle from the entire text string.
I didn't study the code but it looks like that was done with the Replace command.
Mar 10th, 2008, 08:22 PM
#24
Re: [RESOLVED] Help with sendmessage please
Oh, OK, I tested it on my system but I changed the Title of the window so the Replace didn't work in my case because I saw the entire text message in the text1.
Mar 10th, 2008, 10:10 PM
#25
Thread Starter
Fanatic Member
Re: Help with sendmessage please
cool thanks!!
Originally Posted by
Edgemeal
Ya convert the text string to a long, since thats what the API expects.
Call SendMessageByString(Clng(Text1.Text), WM_SETTEXT, 0, "portland")
Live life to the fullest!!
Mar 10th, 2008, 10:14 PM
#26
Re: [RESOLVED] Help with sendmessage please
The API expects a Long that is the window handle so converting the textbox contents to a Integer will fail if the handle is larger then a Integer.
Last edited by RobDog888; Mar 10th, 2008 at 10:18 PM .
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width