-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorButton.cpp
More file actions
87 lines (66 loc) · 1.86 KB
/
ColorButton.cpp
File metadata and controls
87 lines (66 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ColorButton.cpp : implementation file
//
#include "stdafx.h"
#include "fireplus.h"
#include "ColorButton.h"
#include ".\colorbutton.h"
// CColorButton
IMPLEMENT_DYNAMIC(CColorButton, CButton)
CColorButton::CColorButton()
{
color = RGB(0,0,0);
brush = CreateSolidBrush(color);
}
CColorButton::~CColorButton()
{
if(brush)
::DeleteObject(brush);
}
BEGIN_MESSAGE_MAP(CColorButton, CButton)
ON_CONTROL_REFLECT(BN_CLICKED, OnBnClicked)
END_MESSAGE_MAP()
// CColorButton message handlers
void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle);
// Get the button's text.
//CString strText;
//GetWindowText(strText);
CRect rect = lpDrawItemStruct->rcItem;
rect.DeflateRect(2, 2);
::FillRect(lpDrawItemStruct->hDC, &rect, brush);
// Draw the button text using the text color red.
//COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
//::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
//&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
//::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
COLORREF CColorButton::GetColor(void)
{
return color;
}
COLORREF CColorButton::SetColor(COLORREF _color)
{
color = _color;
if(brush)
::DeleteObject(brush);
brush = CreateSolidBrush(color);
return color;
}
void CColorButton::OnBnClicked()
{
CColorDialog colorDialog(color, 0, this);
if(colorDialog.DoModal() == IDOK)
{
SetColor(colorDialog.GetColor());
Invalidate();
}
}