Results 1 to 26 of 26

Thread: [RESOLVED] Help with sendmessage please

  1. #1

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Resolved [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:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. 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
    4. 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
    5. Private Const WM_SETTEXT = &HC
    6. Private Const BM_CLICK = &HF5
    7. Private Const WM_SETFOCUS = &H7
    8.  
    9.  
    10.  
    11.  
    12. Private Sub Command1_Click()
    13. Dim nPad As Long, editx As Long
    14.      nPad = FindWindow(vbNullString, "Login to NetZero")
    15.    editx = FindWindowEx(nPad, 0&, "zuicombobox", vbNullString)
    16.      If editx Then
    17.     Call SendMessageByString(editx, WM_SETTEXT, 0, "portland")
    18.     Text1.Text = "found it"
    19.     Else
    20.     Text1.Text = "No find"
    21.    
    22.     'Call SendMessageByString(editx, BM_CLICK, 0, "Send Some")
    23. End If
    24. End Sub
    Live life to the fullest!!

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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.

  3. #3

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Help with sendmessage please

    how do I uses "GetWindowLong() with GWL_ID " ?
    Quote 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!!

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    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

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Help with sendmessage please

    yes that what I want to do!! but how do I do that?
    Quote 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!!

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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 Attached Files

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help with sendmessage please

    Quote 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    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!!

  10. #10
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Help with sendmessage please

    Quote 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.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help with sendmessage please

    Quote 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Help with sendmessage please

    no I was going to grab them each time before sending the message.
    Quote 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!!

  13. #13
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Help with sendmessage please

    Quote 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!

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  15. #15
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Help with sendmessage please

    Quote Originally Posted by RobDog888
    Yes, but you never know unless you are the one writting the code. Also from the example ...

    "editx = FindWindowEx(nPad, 0&, "zuicombobox", "Hwnd=723584") "
    Ya Simple rookie mistake

  16. #16
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Help with sendmessage please

    but control ID's never change, correct?

  17. #17
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Help with sendmessage please

    Quote 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.

  18. #18
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Help with sendmessage please

    my example in no 4# is just an example of using getwindowlong()

  19. #19

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    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:
    1. 'in a module
    2. Option Explicit
    3.  
    4. Public Declare Function EnumChildWindows Lib "user32" _
    5.   (ByVal hWndParent As Long, _
    6.    ByVal lpEnumFunc As Long, _
    7.    ByVal lParam As Long) As Long
    8.    
    9. Public Declare Function FindWindow Lib "user32" _
    10.     Alias "FindWindowA" (ByVal lpClassName As String, _
    11.     ByVal lpWindowName As String) As Long
    12.  
    13. Private Declare Function GetWindowTextLength Lib "user32" _
    14.     Alias "GetWindowTextLengthA" _
    15.    (ByVal hwnd As Long) As Long
    16.    
    17. Private Declare Function GetWindowText Lib "user32" _
    18.     Alias "GetWindowTextA" _
    19.    (ByVal hwnd As Long, _
    20.     ByVal lpString As String, _
    21.     ByVal cch As Long) As Long
    22.    
    23. Private Declare Function GetClassName Lib "user32" _
    24.     Alias "GetClassNameA" _
    25.    (ByVal hwnd As Long, _
    26.     ByVal lpClassName As String, _
    27.     ByVal nMaxCount As Long) As Long
    28.  
    29. Private Function TrimNull(startstr As String) As String
    30.  
    31.   Dim pos As Integer
    32.  
    33.   pos = InStr(startstr, Chr$(0))
    34.  
    35.   If pos Then
    36.       TrimNull = Left$(startstr, pos - 1)
    37.       Exit Function
    38.   End If
    39.  
    40.   TrimNull = startstr
    41.  
    42. End Function
    43.  
    44. Private Function GetWindowIdentification(ByVal hwnd As Long, _
    45.    sIDType As String, sClass As String) As String
    46.  
    47.    Dim nSize As Long
    48.    Dim sTitle As String
    49.  
    50.    nSize = GetWindowTextLength(hwnd)
    51.    
    52.   'if the return is 0, there is no title
    53.    If nSize > 0 Then
    54.       sTitle = Space$(nSize + 1)
    55.       Call GetWindowText(hwnd, sTitle, nSize + 1)
    56.       sIDType = "title"
    57.       sClass = Space$(64)
    58.       Call GetClassName(hwnd, sClass, 64)
    59.    Else
    60.      'no title, so get the class name instead
    61.       sTitle = Space$(64)
    62.       Call GetClassName(hwnd, sTitle, 64)
    63.       sClass = sTitle
    64.       sIDType = "class"
    65.    End If
    66.    
    67.    GetWindowIdentification = TrimNull(sTitle)
    68.  
    69. End Function
    70.  
    71. Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    72.  
    73.    Dim sTitle As String
    74.    Dim sClass As String
    75.    Dim sIDType As String
    76.    
    77.   'get the window title/class name
    78.    sTitle = GetWindowIdentification(hwnd, sIDType, sClass)
    79.    'add to our list
    80.    Form1.List1.AddItem sTitle & ": Hwnd=" & hwnd & ", Class=" & TrimNull(sClass) & ", IDType=" & sIDType
    81.    EnumChildProc = 1
    82.    
    83. End Function
    84.  
    85.  
    86.  
    87.  
    88. 'in the form
    89. Option Explicit
    90. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    91. 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
    92. 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
    93. Private Const WM_SETTEXT = &HC
    94. Private Const BM_CLICK = &HF5
    95. Private Const WM_SETFOCUS = &H7
    96.  
    97.  
    98.  
    99. Private Sub Command1_Click()
    100.  
    101.     Dim Lhwnd As Long
    102.    
    103.     List1.Clear
    104.    
    105.     ' get hwnd to our dialog/program window
    106.     Lhwnd = FindWindow(vbNullString, "Login to NetZero")
    107.    
    108.     If Lhwnd Then ' get childs
    109.         Call EnumChildWindows(Lhwnd, AddressOf EnumChildProc, &H0)
    110.     End If
    111.    
    112. End Sub
    113.  
    114.  
    115. Private Sub Command2_Click()
    116. Text1.Text = List1.List(4)
    117.  
    118. End Sub
    119.  
    120. Private Sub Command3_Click()
    121. Call SendMessageByString(Text1.Text, WM_SETTEXT, 0, "portland")
    122.  
    123.    
    124. End Sub
    125.  
    126. Private Sub Form_Load()
    127.  
    128. End Sub
    129.  
    130. Private Sub Text1_Change()
    131. Text1.Text = Replace(Text1.Text, "zuicombobox: Hwnd=", "")
    132. Text1.Text = Replace(Text1.Text, ", Class=zuicombobox, IDType=class", "")
    133.  
    134. End Sub
    Live life to the fullest!!

  20. #20
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Help with sendmessage please

    Quote 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

  21. #21
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Help with sendmessage please

    Quote 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")

  22. #22
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Help with sendmessage please

    He will first have to extract out the handle from the entire text string.

  23. #23
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Help with sendmessage please

    Quote 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.

  24. #24
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  25. #25

    Thread Starter
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Help with sendmessage please

    cool thanks!!
    Quote 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!!

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width