Power Color Picker | CodeGuru

Power Color Picker

Features : This new control derived from CWnd provides an interface for users to select colors for an object. It is more intuitive than CColorDialog in windows API. Interface description : right rectangle : luminance. left rectangle : saturation on x axis, hue on y axis. bottom rectangle : currently selected color. This control is […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 6, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Features :

This new control derived from CWnd provides an interface for users to select
colors for an object. It is more intuitive than CColorDialog in windows API.

Interface description :

  • right rectangle : luminance.
  • left rectangle : saturation on x axis, hue on y axis.
  • bottom rectangle : currently selected color.

This control is fully resizable on the fly. You could specify a size for
each rectangle.
When you move the cursor with shift or ctrl, the color change only on one
axis (hue or saturation)

 

How to use it in a dialog :

  • a member variable must be added to the dialog :
    ...protected:	PowerColorPicker picker;
    ...

  • create the picker in the method OnInitDialog() of your dialog :

//specify the control size
RECT rect={10,10,390,300}; 

//create control in OnInitDialog()
 picker.Create(NULL,”Haha”,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS ,rect,this, NULL, NULL);
…
  • define a callback when the user click/move on picker :
    //define a callback
    void testfunc(COLORREF ref,void *ClientData)
    {
    	CColorPickerDlg * local= (CColorPickerDlg*)ClientData;
    
    	char str[256];
    	sprintf(str,"RED: %ld\nGREEN: %ld\nBLUE: %ld",GetRValue(ref),GetGValue(ref),GetBValue(ref));
    
    	OutputDebugString(str);
    
    }
    
    
    ...
    
    //register callbacks in OnInitDialog()
     
    picker.RegisterCallbackOnMove(testfunc,this); picker.RegisterCallbackOnLButtonDown(testfunc,this);
    
    ...
  • you could define the width of the luminance bar anywhere in your source
    :
    ...
    
    
    picker.SetLuminanceBarWidth(20);
    
    ...

Downloads

Download Source Code – 31 Kb
Download Demo Application – 9 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.