CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Color ID utility?

    Is there a VB utility anywhere that allows the user to point at anything on the screen and have its RGB value displayed? Thought I saw an API utility somewhere that does this but don't remember where I found it.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Color ID utility?

    Add a Timer Control to a Form, then use this code and point to anywhere on your screen to have the RGB value appear in the Forms Caption.

    private Type POINTAPI
    x as Long
    y as Long
    End Type

    private Declare Function GetPixel Lib "gdi32" (byval hdc as Long, byval x as Long, byval y as Long) as Long
    private Declare Function GetCursorPos Lib "user32" (lpPoint as POINTAPI) as Long
    private Declare Function GetWindowDC Lib "user32" (byval hwnd as Long) as Long

    private Sub Form_Load()
    Timer1.Interval = 100
    End Sub

    private Sub Timer1_Timer()
    Dim tPOS as POINTAPI
    Dim sTmp as string
    Dim lColor as Long
    Dim lDC as Long

    lDC = GetWindowDC(0)
    Call GetCursorPos(tPOS)
    lColor = GetPixel(lDC, tPOS.x, tPOS.y)
    sTmp = Right$("000000" & Hex(lColor), 6)
    Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2)
    End Sub




    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Guest

    Re: Color ID utility?

    Thanks a lot. Also refound the code - it was "getpixel.zip" from http://matthart.com/vbhelp/vbapi.htm


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

Featured