|
-
Feb 16th, 2001, 08:45 AM
#1
Thread Starter
Fanatic Member
How do I send messages using vb. I tried sendmessage API function, but it didnot work
-
Feb 16th, 2001, 09:39 AM
#2
Member
'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, 10:01 AM
#3
What message were you trying to send? Maybe you were using incorrect syntax.
-
Feb 17th, 2001, 01:05 AM
#4
Addicted Member
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
-
Feb 17th, 2001, 02:26 AM
#5
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, 12:34 PM
#6
True is a constant for 1.
-
Feb 18th, 2001, 02:07 AM
#7
i didn't think it was a long. How about TRUE&
Last edited by Lord Orwell; Feb 18th, 2001 at 02:17 AM.
-
Feb 18th, 2001, 05:30 AM
#8
Thread Starter
Fanatic Member
Send Messages on...
I want to send messages to move the mouse cursor and make it click on some other program file
-
Feb 18th, 2001, 05:47 AM
#9
PowerPoster
Why don't you use SetCursorPos for moving the cursor. You can then use the SendMessgae to emulate mouse Button down.
-
Feb 18th, 2001, 10:17 AM
#10
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)
-
Feb 19th, 2001, 02:23 AM
#11
Thread Starter
Fanatic Member
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
-
Feb 19th, 2001, 02:41 AM
#12
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, 03:36 PM
#13
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
-
Feb 20th, 2001, 02:47 AM
#14
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.
-
Feb 20th, 2001, 05:45 AM
#15
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|