diff src/win32/ColorControl.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/ColorControl.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,78 @@
     1.4 +// ColorControl.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "ColorControl.h"
     1.9 +
    1.10 +bool ColorControl::isRegistered = false;
    1.11 +
    1.12 +/////////////////////////////////////////////////////////////////////////////
    1.13 +// ColorControl
    1.14 +
    1.15 +ColorControl::ColorControl()
    1.16 +{
    1.17 +  color = 0;
    1.18 +  registerClass();
    1.19 +}
    1.20 +
    1.21 +ColorControl::~ColorControl()
    1.22 +{
    1.23 +}
    1.24 +
    1.25 +
    1.26 +BEGIN_MESSAGE_MAP(ColorControl, CWnd)
    1.27 +  //{{AFX_MSG_MAP(ColorControl)
    1.28 +  ON_WM_PAINT()
    1.29 +  ON_WM_ERASEBKGND()
    1.30 +  //}}AFX_MSG_MAP
    1.31 +  END_MESSAGE_MAP()
    1.32 +
    1.33 +
    1.34 +  /////////////////////////////////////////////////////////////////////////////
    1.35 +// ColorControl message handlers
    1.36 +
    1.37 +void ColorControl::OnPaint() 
    1.38 +{
    1.39 +  CPaintDC dc(this); // device context for painting
    1.40 +}
    1.41 +
    1.42 +BOOL ColorControl::OnEraseBkgnd(CDC* pDC) 
    1.43 +{
    1.44 +  int r = (color & 0x1f) << 3;
    1.45 +  int g = (color & 0x3e0) >> 2;
    1.46 +  int b = (color & 0x7c00) >> 7;
    1.47 +
    1.48 +  CBrush br;
    1.49 +  br.CreateSolidBrush(RGB(r,g,b));
    1.50 +
    1.51 +  RECT rect;
    1.52 +  GetClientRect(&rect);
    1.53 +  pDC->FillRect(&rect,&br);
    1.54 +  pDC->DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
    1.55 +  br.DeleteObject();
    1.56 +  return TRUE;
    1.57 +}
    1.58 +
    1.59 +void ColorControl::setColor(u16 c)
    1.60 +{
    1.61 +  color = c;
    1.62 +  Invalidate();
    1.63 +}
    1.64 +
    1.65 +void ColorControl::registerClass()
    1.66 +{
    1.67 +  if(!isRegistered) {
    1.68 +    WNDCLASS wc;
    1.69 +    ZeroMemory(&wc, sizeof(wc));
    1.70 +    wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
    1.71 +    wc.lpfnWndProc = (WNDPROC)::DefWindowProc;
    1.72 +    wc.hInstance = AfxGetInstanceHandle();
    1.73 +    wc.hIcon = NULL;
    1.74 +    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    1.75 +    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
    1.76 +    wc.lpszMenuName = NULL;
    1.77 +    wc.lpszClassName = "VbaColorControl";
    1.78 +    AfxRegisterClass(&wc);
    1.79 +    isRegistered = true;
    1.80 +  }
    1.81 +}