Results 1 to 8 of 8

Thread: Colour grabber

  1. #1

    Thread Starter
    Junior Member rjhare's Avatar
    Join Date
    Sep 2001
    Location
    Peterborough, UK
    Posts
    31

    Colour grabber

    Is there a call I can use that will let me grab the colour from another application/screen. I want to click on the screen and return an RGB value or Hex.

    Any help would be appreciated

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Kludge method:

    Get screen shot (press PRINTSCREEN)

    Open Paint

    Go to Edit/Paste

    Find the color you want

    Click the color grabber tool in Paint, click the color

    Go to Colors menu, Edit Colors (on Win2k, may be different elsewhere)

    Press Define Custom Colors >>

    You will see the red, green, blue in the boxes on the right.

    Now you can put that in RGB command, and use Hex(RGB(red,green,blue)) to get the hex of the color.

    Easy eh?
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you want to do it programmatically then use GetPixel API.
    Pass then hDC of the window and X and Y of the mouse pointer.

  4. #4
    Lively Member
    Join Date
    May 2001
    Posts
    96
    Better yet. I found the best thing to use is something like this
    needs button, picturebox, and 2 labels.
    Code:
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private Sub Command1_Click()
    dim dadc as long
    dim z as pointapi
    dadc = GetDC(0) 'Don't Know why this works but it does
    Do ' Does it until the program closes
    Doevents: Doevents 'For Protection
    GetCursorPos z ' Tells the computer where mouse is
    Picture1.Background = GetPixel(dadc, z.X, z.Y) 'tells it to show the color in a picture box
    Label1.Caption = GetPixel(dadc, z.X, z.Y) 'Gives you the number value
    Label2.Caption = "X: " & z.X & " " & "Y: " z.Y 'Tells where your mouse is
    DoEvents: Doevents 'Overkill,  but it works
    loop
    end sub

  5. #5

    Thread Starter
    Junior Member rjhare's Avatar
    Join Date
    Sep 2001
    Location
    Peterborough, UK
    Posts
    31
    Thanks to everyone that replied. All really helpful - and yes, I did want to get the colour from within my application.

    Richard

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Cogman; if you pass 0 into the GetDC() function, it will return the DC for the entire screen.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Lively Member
    Join Date
    May 2001
    Posts
    96
    still works.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well of course it does, your application is on the screen
    Anyway I only mentioned it because you said you didnt know why you were passing a 0...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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