Click to See Complete Forum and Search --> : Color ID utility?


January 8th, 2000, 11:30 AM
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.

Aaron Young
January 10th, 2000, 01:05 PM
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
ajyoung@pressenter.com
aarony@redwingsoftware.com

January 10th, 2000, 02:29 PM
Thanks a lot. Also refound the code - it was "getpixel.zip" from http://matthart.com/vbhelp/vbapi.htm