Results 1 to 15 of 15

Thread: Send Messages

  1. #1

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Wink

    How do I send messages using vb. I tried sendmessage API function, but it didnot work

  2. #2
    Member
    Join Date
    Feb 2001
    Location
    Kerala, India
    Posts
    42

    Thumbs up

    'This project needs a ListBox, named List1 and a TextBox, named Text1

    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
    Const LB_FINDSTRING = &H18F
    Private Sub Form_Load()
    'Add some items to the listbox
    With List1
    .AddItem "Computer"
    .AddItem "Screen"
    .AddItem "Modem"
    .AddItem "Printer"
    .AddItem "Scanner"
    .AddItem "Sound Blaster"
    .AddItem "Keyboard"
    .AddItem "CD-Rom"
    .AddItem "Mouse"
    End With
    End Sub
    Private Sub Text1_Change()
    'Retrieve the item's listindex
    List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
    End Sub

  3. #3
    Guest
    What message were you trying to send? Maybe you were using incorrect syntax.

  4. #4
    Addicted Member KrishnaSantosh's Avatar
    Join Date
    Feb 2001
    Location
    Coimbatore
    Posts
    210
    Const EM_SETREADONLY=&HCF 'Edit Box Read Only Prop

    Private Declare Function SendMessage Lib "User32" _
    Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
    ByVal lParam As Long) As Long


    private sub Form_Load()

    End Sub

    Private sub Text1_Change()

    End Sub

    private sub Command1_Click()

    dim lResult As Long

    'Make Text1 Read Only

    lResult=SendMessage((Text1.hWnd), _ EM_SETREADONLY,True,0&)

    ' To Allow Changes Repl. True With False Above.
    End Sub

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    textboxes already have that property. if textbox is text1, then text1.locked = true will lock it.
    as for your code, try replacing "true" with a number other than zero.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    Guest
    True is a constant for 1.

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    i didn't think it was a long. How about TRUE&
    Last edited by Lord Orwell; Feb 18th, 2001 at 02:17 AM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Unhappy Send Messages on...

    I want to send messages to move the mouse cursor and make it click on some other program file

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Why don't you use SetCursorPos for moving the cursor. You can then use the SendMessgae to emulate mouse Button down.

  10. #10
    Guest
    Originally posted by Lord Orwell
    i didn't think it was a long. How about TRUE&
    Since you didn't declare any variable as a boolean, the API function will interpret it as '1' (long data type)

  11. #11

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562
    Thats the problem, I can move the cursor using SetCursorPos. But the more important thing in clicking the mouse button is what I don't know

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    send a mouse event, using the api call Mouse_event
    Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As _

    Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    notice the buttons parameter.
    It is just there to throw you off. It is actually unused.
    to simulate button presses, use the following values in place of the dwFlags (any or all of them)
    MOUSEEVENTF_ABSOLUTE: dx and dy specify an absolute position in mouse coordinates which divide the screen into 65,535 units horizontally and vertically.
    Public Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
    Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
    Public Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
    Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13
    Guest
    To click the mouse:
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    Private Sub Command1_Click()
        PostMessage hwnd_of_window, WM_LBUTTONDOWN, MK_LBUTTON, 0
        PostMessage hwnd_of_window, WM_LBUTTONUP, MK_LBUTTON, 0
    End Sub

  14. #14
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Very good. If he knows the handle of the window. I had (foolishly perhaps ) assumed he wanted to click on something without a handle, or was making a macro program, since he was talking about moving the mouse.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  15. #15

    Thread Starter
    Fanatic Member 007shahid's Avatar
    Join Date
    Feb 2001
    Posts
    562

    Talking Thanks

    Thankyou all who have helped me above

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