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 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


Comments

  • Excellent

    Posted by Ajay Vijay on 11/20/2004 06:04am

    Great!

    Reply
  • Typo and fix for memory leaks...

    Posted by Legacy on 12/29/2000 12:00am

    Originally posted by: Chetan

    First, the typo :
    
    

    In PowerColorPicker.cpp, currently line 585 is

    currentColor = HLStoRGB(currentHue,currentSaturation,currentLuminance);

    to be changed to

    currentColor = HLStoRGB(currentHue,currentLuminance,currentSaturation);

    Second, these lines to be added to the class destructor, in the same file

    if (pickerDC)
    {
    delete pickerDC;
    pickerDC = NULL;
    }

    if (luminanceBarDC)
    {
    delete luminanceBarDC;
    luminanceBarDC = NULL;
    }

    That will remove the memory leaks.

    Otherwise, a very good piece of work.

    Thanks,
    Chetan.

    Reply
  • There are memory leaks!

    Posted by Legacy on 12/06/1999 12:00am

    Originally posted by: pxz

    There are memory leaks!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 13, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT APIs can be a great source of competitive advantage. The practice of exposing backend services as APIs has become pervasive, however their use varies widely across companies and industries. Some companies leverage APIs to create internal, operational and development efficiencies, while others use them to drive ancillary revenue channels. Many companies successfully support both public and private programs from the same API by varying levels …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds