|
-
Nov 13th, 2001, 11:56 AM
#1
Thread Starter
Junior Member
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
-
Nov 13th, 2001, 01:30 PM
#2
Frenzied Member
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?
-
Nov 13th, 2001, 02:49 PM
#3
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.
-
Nov 13th, 2001, 03:47 PM
#4
Lively Member
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
-
Nov 14th, 2001, 01:55 AM
#5
Thread Starter
Junior Member
Thanks to everyone that replied. All really helpful - and yes, I did want to get the colour from within my application.
Richard
-
Nov 14th, 2001, 05:23 AM
#6
Retired VBF Adm1nistrator
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]
-
Nov 14th, 2001, 02:25 PM
#7
Lively Member
still works.
-
Nov 15th, 2001, 03:25 AM
#8
Retired VBF Adm1nistrator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|