How to add color picker in mfc?

12,836

Solution 1

Use CColorDialog class in mfc is used to pick the color from mfc

 // Get the selected color from the CColorDialog. 
 CColorDialog dlg; 
 if (dlg.DoModal() == IDOK) 
 { 
      COLORREF color = dlg.GetColor(); 

 }

This sample will popup dialog to select the color and after selecting the color and click ok button then color variable will contain the selected color.

Use this color in your application.

EDIT

You can customize your combo box or list box to add the color pick tool.

Refer this link : CodeProjectSample

Solution 2

Since you don't seem to have the MFC Feature Pack, check the Ultimate Toolbox at http://www.codeproject.com/KB/MFC/UltimateToolbox.aspx. Its Graphical User Interface classes have a Color Picker.

Solution 3

CMFCColorDialog is what you seem to be looking for. To make it act like a drop-down, you'll need to position it below the down-arrow button (e.g., using MoveWindow).

Share:
12,836
karthik
Author by

karthik

.NET Developer having experience in MVC, Web Development, WCF Services.

Updated on June 13, 2022

Comments

  • karthik
    karthik almost 2 years

    i want be able to select any color i want, just like the attached pic.

    COLOR PICKER

    yes i want to learn this c++ or mfc . I find it more powerfull . Could u explain to me exactly how to add it to my project. I also want the color iteslf and it code appers in picture box and textbox.

    Thanks

  • karthik
    karthik almost 13 years
    @user : This will popup the dialog but i want like the above attachment.
  • karthik
    karthik almost 13 years
    how to include CMFCColorDialog in to my application.when i use this , it will show the error as CMFCColorDialog undeclared identifier.
  • Jerry Coffin
    Jerry Coffin almost 13 years
    You need either VS 2008 with the Feature Pack or SP1, or else VS 2010 to use it. Assuming you have that, #include <afxcolordialog.h>.
  • karthik
    karthik almost 13 years
    I am not having that version.Is any other possible way to achieve this?
  • Jerry Coffin
    Jerry Coffin almost 13 years
    With older versions/compilers, it's easiest to use a CColorDialog instead (or you can call ChooseColor directly). At least in theory, you should be able to create the drop-down color picker directly via its COM interface, but I've never tried it, so I can't really say much about how to do it.
  • karthik
    karthik almost 13 years
    @karthik: For that you have to customize the combobox and write in the way you like.