If you want to make a tool box, you can generate a DialogBar directly, you can set this palette to ccolorpicker m_picker; m_picker.create ("KDFJ", "DFDF", WS_Visible, CRECT (0,0,400,50 ), this, 1023, NULL);! CColorPicker class #if defined (AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__INCLUDED _) # define AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__INCLUDED_
#if _msc_ver> 1000 # pragma overce # endif //_msc_ver> 1000 // colorPicker.h: header file //
/// ccolorpicker window
Class ccolorpicker: public cwnd {// constructionPublic: ccolorpicker (); uint m_nstyle; // attributespublic:
// OperationsPublic:
// Overrides // ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CColorPicker) public: virtual BOOL Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID, CCreateContext * pContext = NULL) ; //}} AFX_VIRTUAL
// ImplementationPublic: colorref getcolor (); virtual ~ ccolorpicker ();
// Generated message map functionsprotected: // {{AFX_MSG (CColorPicker) afx_msg void OnPaint (); afx_msg void OnLButtonDown (UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk (UINT nFlags, CPoint point); afx_msg BOOL OnEraseBkgnd (CDC * pDC ); //}} AFX_MSG DECLARE_MESSAGE_MAP () Private: ColorRef Color [25]; ColorRef m_color;
/
// {{AFX_INSERT_LOCATION}} // Microsoft Visual C Will Insert Additional Declarations Immediately Before The Previous Line.
#endif //! defined (AFX_COLORPICKER_H__30EE9CBC_5C0B_4B5E_88E7_95C6D42E3923__inCluded_) // colorPicker.cpp: importation file //
#include "stdafx.h"
#include "colorpicker.h"
#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF
/// ccolorpicker
CColorPicker :: ccolorpicker () {m_color = RGB (0, 0); Color [0] = RGB (0, 0); Color [1] = RGB (128, 0); Color [2] = RGB (0,128,0); Color [3] = RGB (128, 128, 0); Color [4] = RGB (0, 0, 128); Color [5] = RGB (128, 0, 128); Color [6] = RGB (0, 128, 128); Color [7] = RGB (192, 192, 192); Color [8] = RGB (192, 220, 192); Color [9] = RGB (166, 202, 240); Color [10] = RGB (255, 251, 240); color [11] = RGB (160, 160, 164); Color [12] = RGB (128, 128, 128); Color [13] = RGB (255, 0); Color [14] = RGB (0,255,0); Color [15] = RGB (255, 255, 0) COLOR [16] = RGB (0,0,255); Color [17] = RGB (255, 0, 0); Color [18] = RGB (255, 0, 255); Color [19] = RGB (0, 255, 255); Color [20] = RGB (255,255,255);
CColorPicker :: ~ ccolorpicker () {}
BEGIN_MESSAGE_MAP (CColorPicker, CWnd) // {{AFX_MSG_MAP (CColorPicker) ON_WM_PAINT () ON_WM_LBUTTONDOWN () ON_WM_LBUTTONDBLCLK () ON_WM_ERASEBKGND () //}} AFX_MSG_MAPEND_MESSAGE_MAP ()
/// CColorPicker Message Handlers
BOOL CColorPicker :: Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID, CCreateContext * pContext) {// TODO: Add your specialized code here and / or call the base class m_nStyle = dwStyle ; if (CWnd :: Create (AfxRegisterWndClass (CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, AfxGetApp () -> LoadStandardCursor (IDC_ARROW), (HBRUSH) GetStockObject (LTGRAY_BRUSH), NULL), NULL, dwStyle & ~ WS_CLIPCHILDREN | WS_CLIPSIBLINGS, rect, pParentWnd, nID )) RETURN TRUE; RETURN FALSE;
Return CWnd :: Create (LPSZClassName, Lpszwindowname, DWStyle, Rect, PparentWnd, NID, PCONText);
Void ccolorpicker :: onpaint () {CPAINTDC DC (this); // Device Context for Painting CRECT; CBRUSH BR; // CBrush * Pr; INT INDEX = 0; this-> getClientRect (& Re); long x1 = Rect. Left Rect.width () / 10, Y1 = Rect.Top, X2 = Rect.right-Rect.Width () / 10, Y2 = Rect.bottom; for (int i = x1; i
CWnd :: ONLBUTTONDOWN (NFLAGS, POINT);
void CColorPicker :: OnLButtonDblClk (UINT nFlags, CPoint point) {// TODO: Add your message handler code here and / or call default CColorDialog dlg; if (dlg.DoModal () == IDOK) {m_color = dlg.GetColor () } This-> invalidate (); cWnd :: ONLBUTTONDBLCLK (NFLAGS, POINT);
ColorRef ccolorpicker :: getColor () {return m_color;}
Bool ccolorpicker :: OneRaseBkGnd (CDC * PDC) {// Todo: add your message hand default return cWnd :: OneRaseBkGnd (PDC);} Demo