rlm@1: // ColorControl.cpp : implementation file rlm@1: // rlm@1: rlm@1: #include "stdafx.h" rlm@1: #include "ColorControl.h" rlm@1: rlm@1: bool ColorControl::isRegistered = false; rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // ColorControl rlm@1: rlm@1: ColorControl::ColorControl() rlm@1: { rlm@1: color = 0; rlm@1: registerClass(); rlm@1: } rlm@1: rlm@1: ColorControl::~ColorControl() rlm@1: { rlm@1: } rlm@1: rlm@1: rlm@1: BEGIN_MESSAGE_MAP(ColorControl, CWnd) rlm@1: //{{AFX_MSG_MAP(ColorControl) rlm@1: ON_WM_PAINT() rlm@1: ON_WM_ERASEBKGND() rlm@1: //}}AFX_MSG_MAP rlm@1: END_MESSAGE_MAP() rlm@1: rlm@1: rlm@1: ///////////////////////////////////////////////////////////////////////////// rlm@1: // ColorControl message handlers rlm@1: rlm@1: void ColorControl::OnPaint() rlm@1: { rlm@1: CPaintDC dc(this); // device context for painting rlm@1: } rlm@1: rlm@1: BOOL ColorControl::OnEraseBkgnd(CDC* pDC) 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: CBrush br; rlm@1: br.CreateSolidBrush(RGB(r,g,b)); rlm@1: rlm@1: RECT rect; rlm@1: GetClientRect(&rect); rlm@1: pDC->FillRect(&rect,&br); rlm@1: pDC->DrawEdge(&rect, EDGE_SUNKEN, BF_RECT); rlm@1: br.DeleteObject(); rlm@1: return TRUE; rlm@1: } rlm@1: rlm@1: void ColorControl::setColor(u16 c) rlm@1: { rlm@1: color = c; rlm@1: Invalidate(); rlm@1: } rlm@1: rlm@1: void ColorControl::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 = NULL; rlm@1: wc.hCursor = LoadCursor(NULL, IDC_ARROW); rlm@1: wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH); rlm@1: wc.lpszMenuName = NULL; rlm@1: wc.lpszClassName = "VbaColorControl"; rlm@1: AfxRegisterClass(&wc); rlm@1: isRegistered = true; rlm@1: } rlm@1: }