Trying to make a color piocker from a combobox
Hi,
I'm attempting to make a MS Word style color picker based on a
ComboBox. I created a ComboBox subclass CColorComboBox, and I added the
OnCtlColor message handler. I defined the folowing variables in
ColorComboBox.h -
CBrush m_bgBrush;
COLORREF m_bgColor;
and here is my OnCtlColor routine -
HBRUSH CColorComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Return a different brush if the default is not desired
//return hbr;
return m_bgBrush;
}
In ColorComboBox.cpp, I initialize the CBrush,COLOREF variables during
construction to verify that the color changes when the ComboBox is
created and it does. However, my real goal is to open a CColorDialog
when the user clicks on the dropdown and set the ColorComboBox
background to the selected color. Here is the code from my dialog
void Mydialog::OnDropdownColorpicker()
{
// TODO: Add your control notification handler code here
CColorDialog ColorDialog;
ColorDialog.DoModal();
COLORREF Ind_Color = ColorDialog.GetColor();
m_ColorPicker.m_bgColor = Ind_Color; //m_ColorPicker is the
instantated CColorComboBox
InvalidateRect(0,FALSE);
}
The problem is that OnCtlColor is only called once when the ComboBox is
created. I tried Invalidate() and InvalidateRect as shown and neither
generates a OnCtlColor message. I saw another example of something
similar where the programmer used the CWnd::draw function to
essentially redraw the control from scratch when changing the color. I
don't want to do this.
If this is a poor approach altogether I'm willing to use a packaged
color picker but I could not find a simple one.
Thanks