|
-
Feb 25th, 2002, 07:57 AM
#1
Eye Dropper
Does anyone have some code that would take a one pixel screen shot of the area the mouse is over, then determine the color of that pixel... could someone write me the code or even has just a part of it
Thnx in advance
-
Feb 25th, 2002, 08:14 AM
#2
Bouncy Member
use the GetPixel API, it returns the Red, Green and Blue value of a single pixel at specified co-ordinates - which you can use as the mouse x and y 
This is the API declaration...
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
-
Feb 25th, 2002, 08:38 AM
#3
-
Feb 25th, 2002, 09:50 AM
#4
Bouncy Member
the handle to the device context that you want to use.
i.e.
Form.hDC
-
Mar 1st, 2002, 01:48 PM
#5
Frenzied Member
but the problem I am having with this method is that I would like to get the actual screen pixel there. This method will not do that if the object whose device context is being called is behind another object. I would like for the pixel value returned to be that of the frontmost object.
Is that possible?
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Mar 1st, 2002, 04:22 PM
#6
Add the following to a Form with a Timer. Set it's Interval to 1 (or a higher number).
VB Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Timer1_Timer()
Dim dc As Long, pt As POINTAPI
GetCursorPos pt
dc = GetWindowDC(GetDesktopWindow)
colour = GetPixel(dc, pt.x, pt.y)
Me.BackColor = colour
End Sub
-
Mar 1st, 2002, 06:14 PM
#7
The picture isn't missing
i think GetWindowDC(0) will get the desktop dc so you dont need GetDesktopWindow
Remember, if someone's post was not helpful, you can always rate their post negatively  .
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
|