PDA

Click to See Complete Forum and Search --> : Send Messages


007shahid
Feb 16th, 2001, 07:45 AM
How do I send messages using vb. I tried sendmessage API function, but it didnot work

pramod kumar
Feb 16th, 2001, 08:39 AM
'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

Feb 16th, 2001, 09:01 AM
What message were you trying to send? Maybe you were using incorrect syntax.

KrishnaSantosh
Feb 17th, 2001, 12:05 AM
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

Lord Orwell
Feb 17th, 2001, 01:26 AM
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.

Feb 17th, 2001, 11:34 AM
True is a constant for 1.

Lord Orwell
Feb 18th, 2001, 01:07 AM
i didn't think it was a long. How about TRUE&

007shahid
Feb 18th, 2001, 04:30 AM
I want to send messages to move the mouse cursor and make it click on some other program file

amitabh
Feb 18th, 2001, 04:47 AM
Why don't you use SetCursorPos for moving the cursor. You can then use the SendMessgae to emulate mouse Button down.

Feb 18th, 2001, 09:17 AM
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)

007shahid
Feb 19th, 2001, 01:23 AM
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 :(

Lord Orwell
Feb 19th, 2001, 01:41 AM
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

Feb 19th, 2001, 02:36 PM
To click the mouse:

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

Lord Orwell
Feb 20th, 2001, 01:47 AM
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.

007shahid
Feb 20th, 2001, 04:45 AM
Thankyou all who have helped me above