Results 1 to 20 of 20

Thread: Sendmessage help?

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Sendmessage help?

    Since my other post seems to have gone off-topic, here we go:
    I have used this code to find the IM window on trillian:

    VB Code:
    1. Option Explicit
    2. 'declare API:
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    4.   (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    6. Private Const My_Message As Long = 10001
    7.  
    8. Private Sub Form_Load()
    9.   'Class Name of the window:
    10.   Dim strClassName As String, lhWnd As Long, strclassname2 As String, lhWnd2 As Long
    11.   strClassName = "icoPMsgMSN"
    12.   strclassname2 = "icoPMsgAIM"
    13.   lhWnd = FindWindow(strClassName, vbNullString)
    14.   lhWnd2 = FindWindow(strclassname2, vbNullString)
    15.  
    16.   'if the result is 0, window was not found:
    17.   'If lhWnd = 0 & lhWnd2 = 0 Then
    18.    ' MsgBox "Could not find window..."
    19.    ' Unload Form1
    20.   'Else
    21.     MsgBox "Window found: " & "MSN:" & lhWnd & "AIM:" & lhWnd2
    22.  ' End If

    i added SendMessage lhWnd, "Yo", 0&, 0&, <--to send the that window defined as lhwnd, that gives me an error as i assumed, but i need to find the textbox of the window im sending too with spy++, and i dont know what to look for, it gave me a page full of children..

    My question is, how can i send a message to a textbox inside of an app, by its classname? the class name im looking for is: icoPMsgMSN <(which i do find)>


    BTW im using trillian

    thanks in advance

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

    Re: Sendmessage help?

    For starters I dont have MSN but you can not get a child window handle with just FindWindow alone.
    You need FindWindowEx to get any child window handle. Then once you have the correct handle you can do like this...
    SendMessage lhWnd, WM_SETTEXT, 2&, ByVal "Yo".
    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

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    The answers to your questions are in this thread which I know you've visited.

  4. #4

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    well, first ive never seen that thread, but i did visit another one of your threads that got me this far..
    edit**my stupidity, i see my own post on there, although i dont remember it..


    added this to a module:
    VB Code:
    1. Option Explicit
    2.  
    3. 'Functions, constants and types for the hook
    4. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
    5.     ByVal idHook As Long, _
    6.     ByVal lpfn As Long, _
    7.     ByVal hmod As Long, _
    8.     ByVal dwThreadId As Long _
    9. ) As Long
    10.  
    11. Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
    12.     ByVal hHook As Long _
    13. ) As Long
    14.  
    15. Private Declare Function CallNextHookEx Lib "user32" ( _
    16.     ByVal hHook As Long, _
    17.     ByVal ncode As Long, _
    18.     ByVal wParam As Long, _
    19.     lParam As Any _
    20. ) As Long
    21.  
    22. Public Const WH_MOUSE_LL = 14
    23.  
    24. Public Type POINTAPI
    25.         x As Long
    26.         y As Long
    27. End Type
    28.  
    29. Public Type MSLLHOOKSTRUCT
    30.     pt As POINTAPI
    31.     mouseData As Long
    32.     flags As Long
    33.     time As Long
    34.     dwExtraInfo As Long
    35. End Type
    36.  
    37. Private hHook As Long
    38. Public IsHooked As Boolean
    39.  
    40. 'functions for getting windows properties
    41. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
    42.     ByVal hwnd As Long, _
    43.     ByVal lpString As String, _
    44.     ByVal cch As Long _
    45. ) As Long
    46.  
    47. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
    48.     ByVal hwnd As Long, _
    49.     ByVal lpClassName As String, _
    50.     ByVal nMaxCount As Long _
    51. ) As Long
    52.  
    53. Private Declare Function WindowFromPoint Lib "user32" ( _
    54.     ByVal xPoint As Long, _
    55.     ByVal yPoint As Long _
    56. ) As Long
    57.  
    58. Sub GetWindowData(x As Long, y As Long)
    59.  Dim hWndFrm As Long
    60.  Dim lpClassName As String, lpString As String
    61.  lpClassName = Space(100)
    62.  lpString = Space(100)
    63.  'get handle to window
    64.  hWndFrm = WindowFromPoint(CLng(x), CLng(y))
    65.  If hWndFrm = 0 Then Exit Sub
    66.  'get window text (caption)
    67.  Call GetWindowText(hWndFrm, lpString, Len(lpString))
    68.  'get window class name
    69.  Call GetClassName(hWndFrm, lpClassName, Len(lpClassName))
    70.  
    71.  With Form1
    72.   .txthandle = Hex(hWndFrm)
    73.   .txtCaption = lpString
    74.   .txtClassName = lpClassName
    75.  End With
    76. End Sub
    77.  
    78. Public Sub SetMouseHook()
    79.     If IsHooked Then
    80.         MsgBox "Don't hook the MOUSE_LL hook twice or you'll be sorry."
    81.     Else
    82.         'This has to be set up as a system-wide hook
    83.         hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0)
    84.         IsHooked = True
    85.     End If
    86. End Sub
    87.  
    88. Public Sub RemoveMouseHook()
    89.     Dim temp As Long
    90.     temp = UnhookWindowsHookEx(hHook)
    91.     IsHooked = False
    92. End Sub
    93.  
    94.  
    95. Public Function MouseProc(ByVal uCode As Long, ByVal wParam As Long, lParam As MSLLHOOKSTRUCT) As Long
    96.     If uCode >= 0 Then
    97.         Call GetWindowData(lParam.pt.x, lParam.pt.y)
    98.     End If
    99.                 MouseProc = CallNextHookEx(hHook, uCode, wParam, lParam)
    100. End Function

    Added this to a form:
    VB Code:
    1. Option Explicit
    2.  
    3. 'Always on top stuff
    4. Private Const HWND_TOPMOST = -1
    5. Private Const SWP_NOSIZE = &H1
    6. Private Const SWP_NOMOVE = &H2
    7. Private Const SWP_NOACTIVATE = &H10
    8. Private Const SWP_SHOWWINDOW = &H40
    9.  
    10. Private Declare Sub SetWindowPos Lib "user32" ( _
    11.     ByVal hwnd As Long, _
    12.     ByVal hWndInsertAfter As Long, _
    13.     ByVal x As Long, _
    14.     ByVal y As Long, _
    15.     ByVal cx As Long, _
    16.     ByVal cy As Long, _
    17.     ByVal wFlags As Long _
    18. )
    19.  
    20. Private Sub cmdStart_Click()
    21. 'make window always on top
    22.  SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    23.     SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    24.  'set the system-wide low level mouse hook
    25.  Call SetMouseHook
    26. End Sub
    27.  
    28. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    29.  Call RemoveMouseHook
    30. End Sub

    But nothing happends, the textboxs say text1, text2, and text3 no matter what i do. i am positive ive set nothing wrong.
    Last edited by |2eM!x; Feb 23rd, 2005 at 04:56 PM.

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    I have a joke:
    Q: How many I.T. administrators does it take to changes a light bulb?
    A: It works for me...

    OK, I won't give the typical IT response

    Let's check:
    Are you using VB 6?
    Did you put the module code in a module and the form code in a form?
    Did you compile the code to check for errors?
    Option Explicit everywhere?
    did you press the cmdStart button?
    If the answers to all these is yes, yes, yes, yes, yes
    check to see if your mouse hook is working...
    put a debug.print statement in there
    Let me know

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    yes to all, lemme check out that print stuff

    VB Code:
    1. Public Sub SetMouseHook()
    2.     If IsHooked Then
    3.         MsgBox "Don't hook the MOUSE_LL hook twice or you'll be sorry."
    4.     Else
    5.         'This has to be set up as a system-wide hook
    6.         hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0)
    7.         IsHooked = True
    8.         MsgBox "hello"
    9.     End If
    10. End Sub
    No messagebox hello after clicking cmdstart

    edit2**
    figured it out, after my computer crashed i forgot to rename command1 to cmdstart.shoot. sorry for your time.

    in txthandle it says: 1049E
    ib txtcaption & txtclassname it says "trillian display"

    btw, the txthandle changes for each msg, so if i open up 2 im windows, the textboxes will have different handles..how can i do this, if they handles change?<the only thing that stays the same is icoPMsgAIM, or icoPMsgMSN, <--thats the main one, its the parent is it called? is this still doable still?
    Last edited by |2eM!x; Feb 23rd, 2005 at 07:34 PM.

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    So far so bad,

    What is return value, hHook?
    VB Code:
    1. hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0)

  8. #8

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    94438373 is value of Hhook

  9. #9
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    Can you think of anything you did that might prevent the mouse messages from being received by your App?

    Do you have any other hooks installed, or is your App subclassed?

  10. #10

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    Ive uploaded my project files..you can see exactly what i did, im not sure how to answer your question, all i did was follow that link you sent me
    Attached Files Attached Files

  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    Downloaded your project
    Ran it on My computer (XP pro)
    Worked as it should.

    I don't know why it doesn't work on your computer

  12. #12

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    it does work, i just dont know what to do with the values ive gotten. Im not sure what to input in the sendmessage function..

    also, how will this work, if the class is always the same ("icoPMsgMSN"), and the textbox is always the same, but the handle isnt the same?

    thx for all your help

  13. #13
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    Aaaahh...! I need an icon for pulling out my hair.

    OK, now that that is cleared up. Now that you have the values for classname and caption you can get the handle to the window you want to send the message to.

    Define these functions:
    VB Code:
    1. Option Explicit
    2. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    3. ByVal lpClassName As String, _
    4. ByVal lpWindowName As String _
    5. ) As Long
    6.  
    7. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    8. ByVal hwnd As Long, _
    9. ByVal wMsg As Long, _
    10. ByVal wParam As Long, _
    11. lParam As Any _
    12. ) As Long
    13.  
    14. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    15. ByVal hWnd1 As Long, _
    16. ByVal hWnd2 As Long, _
    17. ByVal lpsz1 As String, _
    18. ByVal lpsz2 As String _
    19. ) As Long
    Assuming the program you want to send the message to is running. You can get the handle to the text box you want
    here are the variables: set them to the values you know
    VB Code:
    1. Dim hWndFrm As Long
    2.  Dim hWndtxtBox As Long
    3.  Dim strCaptionFrm As String
    4.  Dim strClassNameTxtBox As String
    5.  Dim strCaptionTxtBox As String
    Now get the handle
    VB Code:
    1. hWndFrm = FindWindow(vbNullString, strCaptionFrm)
    2.  hWndtxtBox = FindWindowEx(hWndFrm, 0, strClassNameTxtBox, strCaptionTxtBox)
    Now you can send the message; for example
    VB Code:
    1. Call SendMessage(hWndtxtBox, WM_NULL, 0, 0)

  14. #14

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    VB Code:
    1. Option Explicit
    2. 'Always on top stuff
    3. Private Const HWND_TOPMOST = -1
    4. Private Const SWP_NOSIZE = &H1
    5. Private Const SWP_NOMOVE = &H2
    6. Private Const SWP_NOACTIVATE = &H10
    7. Private Const SWP_SHOWWINDOW = &H40
    8.  
    9. Private Declare Sub SetWindowPos Lib "user32" ( _
    10.     ByVal hwnd As Long, _
    11.     ByVal hWndInsertAfter As Long, _
    12.     ByVal x As Long, _
    13.     ByVal y As Long, _
    14.     ByVal cx As Long, _
    15.     ByVal cy As Long, _
    16.     ByVal wFlags As Long _
    17. )
    18. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    19. ByVal lpClassName As String, _
    20. ByVal lpWindowName As String _
    21. ) As Long
    22.  
    23. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    24. ByVal hwnd As Long, _
    25. ByVal wMsg As Long, _
    26. ByVal wParam As Long, _
    27. lParam As Any _
    28. ) As Long
    29.  
    30. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    31. ByVal hWnd1 As Long, _
    32. ByVal hWnd2 As Long, _
    33. ByVal lpsz1 As String, _
    34. ByVal lpsz2 As String _
    35. ) As Long
    36. Dim hWndFrm As Long
    37. Dim hWndtxtBox As Long
    38.  Dim strCaptionFrm As String
    39.  Dim strClassNameTxtBox As String
    40.  Dim strCaptionTxtBox As String
    41.  
    42. Private Sub cmdStart_Click()
    43. 'make window always on top
    44.  SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _
    45.     SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    46.  'set the system-wide low level mouse hook
    47.  Call SetMouseHook
    48.  hWndFrm = FindWindow(vbNullString, strCaptionFrm)
    49.  hWndtxtBox = FindWindowEx(hWndFrm, 0, strClassNameTxtBox, strCaptionTxtBox)
    50. End Sub
    51.  
    52.  
    53. Private Sub Form_Load()
    54. strCaptionFrm = "icopmsgAIM"
    55. strClassNameTxtBox = txtclassname.Text
    56. strCaptionTxtBox = txtcaption.Text
    57. End Sub
    58.  
    59. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    60.  Call RemoveMouseHook
    61. End Sub

    still nothing.man this is way hard for such a simple thing.

  15. #15
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    OK, I'll try one more time.
    Forget about the code you got from another thread.
    Use the code I gave you in my last thread.
    You said that you already know the values for captions and class names so just plug those values in and
    SEND YOUR MESSAGE

    It is very simple.

  16. #16

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    well, you dont have to get angry...you dont need to help if you dont want to...

    anyways, i think ive figured it out:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    4. ByVal lpClassName As String, _
    5. ByVal lpWindowName As String _
    6. ) As Long
    7.  
    8. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    9. ByVal hwnd As Long, _
    10. ByVal wMsg As Long, _
    11. ByVal wParam As Long, _
    12. lParam As Any _
    13. ) As Long
    14.  
    15. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    16. ByVal hWnd1 As Long, _
    17. ByVal hWnd2 As Long, _
    18. ByVal lpsz1 As String, _
    19. ByVal lpsz2 As String _
    20. ) As Long
    21.  
    22.  Dim hWndFrm As Long
    23.  Dim hWndtxtBox As Long
    24.  Dim strCaptionFrm As String
    25.  Dim strClassNameTxtBox As String
    26.  Dim strCaptionTxtBox As String
    27. Const WM_NULL = 1
    28.  
    29. Private Sub Form_Load()
    30. strCaptionFrm = "160432"
    31. strClassNameTxtBox = "trillian display"
    32. strCaptionTxtBox = "trillian display"
    33. hWndFrm = FindWindow(vbNullString, strCaptionFrm)
    34. hWndtxtBox = FindWindowEx(hWndFrm, 0, strClassNameTxtBox, strCaptionTxtBox)
    35. Call SendMessage(hWndtxtBox, WM_NULL, 0, 0)
    36. End Sub

    i just dont know where to type in my text..,if this is to much dont respond

  17. #17
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Sendmessage help?

    I'm not angry, just frustrated.
    1. You don't clearly describe the problem you are trying to solve
    2. You bring in code from other posts that don't have anything to do with your problem, claim it dosn't work, then claim it does work
    3. You don't read other posts which have solved the same problem
    4. You don't pay attention to posts I and others have made to try to help you

    Good luck on that approach

  18. #18

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    im frusterated too
    1.)Im trying to sendmessage...ive never used it before, its not like it is that easy..
    2.)I used code from the link you sent me. I just didnt understand it.
    3.)I definately have.Except mine is different. I dont post unless i dont find it first..
    4.)ok..[edit]discovered that both the text i was typing, and the text i was recieving had the same classname and same caption but not the same handle.That is my problem, i dont know how to send messages to a handle

    thanks.ill just end this topic right here.
    Last edited by |2eM!x; Feb 24th, 2005 at 07:50 PM.

  19. #19
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: Sendmessage help?

    I didn't really read through any posts past the first few.

    Just some advice that i always give in this forum:

    www.patorjk.com For SIMPLE api stuff, just use the API Spy....instead of spending 20 minutes looking through spy++ for messages being sent and handles.

    Also other neat api programs at their site.
    ONLY time i have to use spy++ is when im dealing more so with treeview/listview and menu ids. Of course theres other circumstances...but 70% of the time ill just use api spy and be done in 5 minutes.
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  20. #20

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sendmessage help?

    thx, good links

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