|
-
Feb 17th, 2007, 03:08 AM
#1
Thread Starter
Addicted Member
Getting pixel color?
Hello, I was wondering is it possible from a VB program to grab the color of a pixel at a given location(Like.. 20x 40y)? And if so... How?
-
Feb 17th, 2007, 03:45 AM
#2
Re: Getting pixel color?
You mean this?
VB Code:
Private Declare Function GetPixel Lib "gdi32" (ByVal Hdc As Long, ByVal x As Long, ByVal y As Long) As Long
-
Feb 17th, 2007, 04:21 AM
#3
Thread Starter
Addicted Member
Re: Getting pixel color?
How exactly would I use it? Because when I try it returns -1?... What I am trying to do is get a color value from a web page, then press a key/click something if the color is there.
-
Feb 17th, 2007, 04:34 AM
#4
-
Feb 17th, 2007, 04:46 AM
#5
Thread Starter
Addicted Member
-
Feb 17th, 2007, 05:27 AM
#6
Thread Starter
Addicted Member
Re: Getting pixel color?
Sorry for the double post, but how would I make it so when I clicked the left mouse button it would output the color, mouse x and mouse y?
-
Feb 17th, 2007, 06:46 AM
#7
Re: Getting pixel color?
Try this:
VB Code:
' Add a commandbutton in your form and paste this code.
' set the scalemode of the form to Pixels
' run the project, click the command button then click anywhere on the screen
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Dim pt As POINTAPI
Private Sub Command1_Click()
SetCapture Me.hwnd
Command1.Enabled = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
pt.X = X
pt.Y = Y
ClientToScreen Me.hwnd, pt
ReleaseCapture
MsgBox "Clicked at " & pt.X & ":" & pt.Y & vbCrLf & _
"Get the color of pixel here"
Me.Caption = "Form1"
Command1.Enabled = True
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not Command1.Enabled Then
' this code is not running sometimes when mouse is over taskbar
pt.X = X
pt.Y = Y
ClientToScreen Me.hwnd, pt
Me.Caption = pt.X & ":" & pt.Y
End If
End Sub
Download APIGuide and API Viewer from the links in my sig. In APIGuide you'll find many other mouse-related APIs and their description.
-
Feb 17th, 2007, 04:12 PM
#8
Thread Starter
Addicted Member
Re: Getting pixel color?
Works great thanks.
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
|