Results 1 to 7 of 7

Thread: Eye Dropper

  1. #1
    Yash_Kumar
    Guest

    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

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Yash_Kumar
    Guest

    what do we fill in hdc?

    what do we fill in hdc?

  4. #4
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    the handle to the device context that you want to use.

    i.e.

    Form.hDC
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  5. #5
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    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

  6. #6
    Megatron
    Guest
    Add the following to a Form with a Timer. Set it's Interval to 1 (or a higher number).
    VB Code:
    1. Private Type POINTAPI
    2.     x As Long
    3.     y As Long
    4. End Type
    5. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    6. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    7. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    8. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    9.  
    10. Private Sub Timer1_Timer()
    11.     Dim dc As Long, pt As POINTAPI
    12.     GetCursorPos pt
    13.     dc = GetWindowDC(GetDesktopWindow)
    14.     colour = GetPixel(dc, pt.x, pt.y)
    15.     Me.BackColor = colour
    16. End Sub

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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
  •  



Click Here to Expand Forum to Full Width