YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


MFC Example Retrieve color from desktop with CreateDC and GetCursorPos, GetPixel

 
 

Code Snippet

Download source - 12 Kb

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 :

Collapse Copy Code
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.

Collapse Copy Code
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:

Collapse Copy Code
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.
Collapse Copy Code
CPoint point;
GetCursorPos(&point);
And finally we can get the color code of that point!
Collapse Copy Code
COLORREF color;
color = GetPixel(hDC,point.x,point.y);
After that we can release the device context: 
Collapse Copy Code
DeleteDC(hDC);

 

 

Copyright ?1998-2009 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net