Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add color picker in mfc?

Tags:

visual-c++

mfc

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 powerful. Could you explain to me exactly how to add it to my project? I also want the color itself and it code appears in picture box and textbox.

like image 601
karthik Avatar asked Oct 15 '25 15:10

karthik


2 Answers

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

like image 99
karthik Avatar answered Oct 18 '25 13:10

karthik


CMFCColorDialog or CColorDialog 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).

CColorDialog creates the "old standard" color picker dialog, like this:

enter image description here

CMFCColorDialog creates the somewhat newer color picker, like this one:

enter image description here

like image 30
Jerry Coffin Avatar answered Oct 18 '25 15:10

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!