rlm@1: // ColorButton.cpp : implementation file rlm@1: // rlm@1: rlm@1: #include "stdafx.h" rlm@1: #include "ColorButton.h" rlm@1: rlm@1: bool ColorButton::isRegistered = false; rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // ColorButton rlm@1: rlm@1: ColorButton::ColorButton() rlm@1: { rlm@1: color = 0; rlm@1: registerClass(); rlm@1: } rlm@1: rlm@1: ColorButton::~ColorButton() rlm@1: { rlm@1: } rlm@1: rlm@1: rlm@1: BEGIN_MESSAGE_MAP(ColorButton, CButton) rlm@1: //{{AFX_MSG_MAP(ColorButton) rlm@1: // NOTE - the ClassWizard will add and remove mapping macros here. rlm@1: //}}AFX_MSG_MAP rlm@1: END_MESSAGE_MAP() rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // ColorButton message handlers rlm@1: rlm@1: void ColorButton::PreSubclassWindow() rlm@1: { rlm@1: SetWindowLong(m_hWnd, GWL_STYLE, GetStyle() | BS_OWNERDRAW); rlm@1: CWnd::PreSubclassWindow(); rlm@1: } rlm@1: rlm@1: void ColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) rlm@1: { rlm@1: ASSERT(lpDrawItemStruct); rlm@1: rlm@1: int r = (color & 0x1f) << 3; rlm@1: int g = (color & 0x3e0) >> 2; rlm@1: int b = (color & 0x7c00) >> 7; rlm@1: rlm@1: HDC dc = lpDrawItemStruct->hDC; rlm@1: UINT state = lpDrawItemStruct->itemState; rlm@1: RECT rect = lpDrawItemStruct->rcItem; rlm@1: rlm@1: SIZE margins; rlm@1: margins.cx = ::GetSystemMetrics(SM_CXEDGE); rlm@1: margins.cy = ::GetSystemMetrics(SM_CYEDGE); rlm@1: rlm@1: if(GetState() & BST_PUSHED) rlm@1: DrawEdge(dc, &rect, EDGE_SUNKEN, BF_RECT); rlm@1: else rlm@1: DrawEdge(dc, &rect, EDGE_RAISED, BF_RECT); rlm@1: rlm@1: InflateRect(&rect, -margins.cx, -margins.cy); rlm@1: rlm@1: HBRUSH br = CreateSolidBrush((state & ODS_DISABLED) ? rlm@1: ::GetSysColor(COLOR_3DFACE) : RGB(r,g,b)); rlm@1: rlm@1: FillRect(dc, &rect, br); rlm@1: rlm@1: if(state & ODS_FOCUS) { rlm@1: InflateRect(&rect, -1, -1); rlm@1: DrawFocusRect(dc, &rect); rlm@1: } rlm@1: rlm@1: DeleteObject(br); rlm@1: } rlm@1: rlm@1: void ColorButton::setColor(u16 c) rlm@1: { rlm@1: color = c; rlm@1: Invalidate(); rlm@1: } rlm@1: rlm@1: void ColorButton::registerClass() rlm@1: { rlm@1: if(!isRegistered) { rlm@1: WNDCLASS wc; rlm@1: ZeroMemory(&wc, sizeof(wc)); rlm@1: wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; rlm@1: wc.lpfnWndProc = (WNDPROC)::DefWindowProc; rlm@1: wc.hInstance = AfxGetInstanceHandle(); rlm@1: wc.hIcon = LoadCursor(NULL, IDC_ARROW); rlm@1: wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH); rlm@1: wc.lpszMenuName = NULL; rlm@1: wc.lpszClassName = "VbaColorButton"; rlm@1: AfxRegisterClass(&wc); rlm@1: isRegistered = true; rlm@1: } rlm@1: }