The CExtColorButton
class implements the button control displaying the color popup menu. The CExtColorButton
class is derived from the CExtButton
class. Both CExtColorButton
and CExtColorButton
classes are designed for using as button controls in dialogs and other windows. Both of them are HWND
-based UI elements. Of course, you can create these windows inside a CExtToolControlBar
window and use them, but we recommend you use the non HWND
-based toolbar buttons instead. Each toolbar button is an instance of the CExtBarButton
class or derived from it. The CExtBarColorButton
class implements the color picker button in toolbar like you need. This class is used in the DRAWCLI sample for selecting fill and border colors of drawn document objects. The CMainFrame
class has the following members:
CExtBarColorButton * m_pBtnColorFillS, * m_pBtnColorOutlineS;
They are initialized in the
CMainFrame::OnCreate()
method:
m_pBtnColorFillS =
new CExtBarColorButton(
&m_wndToolBarStandard,
ID_OBJECT_FILLCOLOR, 0, COLORREF(-1), RGB(0,0,0),
ID_OBJECT_FILLCOLOR, true, true,
(LPCTSTR)sNoFill, NULL,
CExtBarColorButton::__DIT_CHAR
);
m_pBtnColorFillS->SetSeparatedDropDown();
VERIFY(
m_wndToolBarStandard.InsertSpecButton(
nBtnIdx,
m_pBtnColorFillS,
FALSE
)
);
nBtnIdx = m_wndToolBarStandard.CommandToIndex(ID_OBJECT_LINECOLOR);
m_wndToolBarStandard.SetButtonCtrlVisibleVertically( nBtnIdx, true );
VERIFY(
m_wndToolBarStandard.RemoveButton(
nBtnIdx,
FALSE
)
);
m_pBtnColorOutlineS =
new CExtBarColorButton(
&m_wndToolBarStandard,
ID_OBJECT_LINECOLOR, 0, COLORREF(-1), RGB(0,0,0),
ID_OBJECT_LINECOLOR, true, true,
(LPCTSTR)sNoOutline, NULL,
CExtBarColorButton::__DIT_FRAME
);
VERIFY(
m_wndToolBarStandard.InsertSpecButton(
nBtnIdx,
m_pBtnColorOutlineS,
FALSE
)
);
The color changing and custom color button clicking events are also handled by the main frame window:
// color popup menu
ON_REGISTERED_MESSAGE(
CExtPopupColorMenuWnd::g_nMsgNotifyColorChangedFinally,
OnColorChangedFinally
)
ON_REGISTERED_MESSAGE(
CExtPopupColorMenuWnd::g_nMsgNotifyCustColor,
OnColorSelectCustom
)
LRESULT CMainFrame::OnColorChangedFinally(WPARAM wParam, LPARAM lParam)
{
. . .
}
LRESULT CMainFrame::OnColorSelectCustom(WPARAM wParam, LPARAM lParam)
{
. . .
}
But the
DRAWCLI sample is an MDI project. That is why the
CMainFrame::OnColorChangedFinally()
and
CMainFrame::OnColorSelectCustom()
handler methods are re-sending the
CExtPopupColorMenuWnd::g_nMsgNotifyColorChangedFinally
and
CExtPopupColorMenuWnd::g_nMsgNotifyCustColor
color notification messages into the active view window in the MDI environment. You can do the same in the SDI environment or handle color notification messages in the main frame window. In the
DRAWCLI sample application you can see the same handler methods implemented in the
CDrawView
class class. The
CDrawView::OnColorChangedFinally()
method changes the color of selected objects when the color cell in the popup menu is clicked. The
CDrawView::OnColorSelectCustom()
method posts the command messages for displaying the color picker dialog.