|
-
Oct 15th, 2010, 02:49 PM
#1
Thread Starter
New Member
Click on form [VB6]
Hey guys, im resently making a program which clicks a color just for the fun of it. So if it see's it, my mouse will move over to it. Without the clicking or with it.
I have made a program that use's a picture box and scans for the color, and if it finds it. Than a message will tell me everywhere it is. I get that like 109, 127. But when I make my program move the mouse to it, the spot isnt the same. I know that its the forms x, y instead of the screens. So how do I move my mouse to the forms x, y and not the screens? Thanks
-
Oct 15th, 2010, 02:59 PM
#2
Re: Click on form [VB6]
What code are you using to position the pointer/cursor? SetCursorPos API?
-
Oct 15th, 2010, 03:02 PM
#3
Thread Starter
New Member
-
Oct 15th, 2010, 03:04 PM
#4
Re: Click on form [VB6]
Could we see some code then?
-
Oct 15th, 2010, 03:16 PM
#5
Thread Starter
New Member
Re: Click on form [VB6]
Sure
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, _
ByVal Y As Long, ByVal crColor As Long) As Long
Private Sub Command1_Click()
Dim X As Long, Y As Long
vbTreeGreen = RGB(28, 26, 14)
For X = 0 To Picture2.Width
For Y = 0 To Picture2.Height
If GetPixel(Picture2.hdc, X, Y) = vbTreeGreen Then
Text1.Text = Text1.Text & vbNewLine & "Black Pixel found at X = " & CStr(X) & ", Y = " & CStr(Y)
End If
Next
Next
End Sub
Private Sub Form_Load()
Picture2.ScaleMode = vbPixels
Picture2.AutoSize = True
End Sub
Thats the code for the pixel thing itself.
Here is for the click one:
Private 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)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetWindowPos& Lib "user32" _
(ByVal hWnd&, ByVal hWndInsertAfter&, _
ByVal x&, ByVal y&, ByVal Wid&, _
ByVal Hgt&, ByVal Flags&)
Const SWP_NOSIZE = 1
Const SWP_NOMOVE = 2
Const HWND_TOPMOST = -1
Public HL As Integer
SetCursorPos 109, 127
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
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
|