Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC
Article

Screen Color Picker

Rate me:
Please Sign up or sign in to vote.
4.91/5 (19 votes)
25 Mar 20021 min read 92.5K   3.3K   37   8
A simple application that retrieves the color codes from any area of your screen, with some cool options.

Sample Image

Introduction

Color Picker is a simple application that retrieves the color codes from any area of your desktop (including any running applications). The program can copy that code - by pressing the SPACE key - to clipboard either in Hex (0x...) or in HTML compatible color code (#...). The color is shown even if the program has lost focus, but you can't copy the value to clipboard. You can choose if you want the application's window to be modal (stay on top) or not.

Initially I make the window modal. In OnInitDialog :
SetWindowPos(&wndTopMost,0,0,0,0,SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE);

I use a timer to refresh the color code of the current pixel pointed by the mouse pointer.

SetTimer(m_nTimer,10,NULL);

To retrieve the color code of any pixel on the screen we must get the device context of the entire screen. We can make that with:

HDC hDC;
hDC = CreateDC("DISPLAY",0,0,0);
The CreateDC function creates a device context (DC) for a device by using it's name. After we take the handle to the device context of the entire display, we can get the position of the cursor.
CPoint point;
GetCursorPos(&point);
And finally we can get the color code of that point!
COLORREF color;
color = GetPixel(hDC,point.x,point.y);
After that we can release the device context: 
DeleteDC(hDC);

This application is useful for web designers and programmers, too. I needed this application for designing the colors of my controls.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Captain Price30-Mar-13 4:15
professionalCaptain Price30-Mar-13 4:15 
Generaldesktop Pin
asadullah khan1-Aug-10 6:54
asadullah khan1-Aug-10 6:54 
QuestionGet Tray clock text color Pin
Motiram P Patil5-Apr-10 2:17
Motiram P Patil5-Apr-10 2:17 
QuestionWhat does one use (code) to "show" the color that the pointer is over? Pin
Richard Perrine8-Jan-09 2:47
Richard Perrine8-Jan-09 2:47 
GeneralGreat program Pin
JoseMenendez4-May-08 11:15
JoseMenendez4-May-08 11:15 
Generalnice! Pin
Razmar3-Apr-06 23:24
Razmar3-Apr-06 23:24 
GeneralFYI Pin
Jeremy Falcon27-Mar-02 3:54
professionalJeremy Falcon27-Mar-02 3:54 
Generaland Pin
gok29-Apr-02 10:21
professionalgok29-Apr-02 10:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.