This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorButton.cpp
83 lines (67 loc) · 2.15 KB
/
ColorButton.cpp
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
// ColorButton.cpp: implementation of the CColorButton class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zsIRC.h"
#include "ColorButton.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CColorButton::CColorButton() : m_Color(0xFFFF80FF)
{
}
CColorButton::~CColorButton()
{
}
BEGIN_MESSAGE_MAP(CColorButton, CButton)
//{{AFX_MSG_MAP(CColorButton)
ON_WM_PAINT()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CColorButton::SetColor(COLORREF colFace)
{
m_Color = colFace;
if (::IsWindow(m_hWnd)) InvalidateRect(NULL);
}
COLORREF CColorButton::GetColor()
{
return m_Color;
}
void CColorButton::OnPaint()
{
CPaintDC dc(this);
RECT rcButton;
GetClientRect(&rcButton);
CBrush b;
b.CreateSolidBrush(m_Color);
dc.FillRect(&rcButton,&b);
dc.Draw3dRect(rcButton.left,rcButton.top,rcButton.right-rcButton.left,rcButton.bottom-rcButton.top,0,0);
}
typedef BOOL (APIENTRY * LPCHOOSECOLORFUNC) (LPCHOOSECOLOR);
void CColorButton::OnLButtonUp(UINT nFlags, CPoint point) {
COLORREF savedcol[16];
ZeroMemory(savedcol,16*sizeof(COLORREF));
CHOOSECOLOR cc;
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.hwndOwner = GetParent()->GetSafeHwnd();
cc.lpCustColors = savedcol;
cc.rgbResult = GetColor();
cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
HINSTANCE pCommonDialogDLL = LoadLibrary(_T("commdlg.dll"));
if (pCommonDialogDLL) {
LPCHOOSECOLORFUNC lpChooseColorFunc = (LPCHOOSECOLORFUNC)GetProcAddress(pCommonDialogDLL,_T("ChooseColor"));
if (lpChooseColorFunc) {
if (lpChooseColorFunc(&cc)) SetColor(cc.rgbResult);
} else {
MessageBox(_T("Sorry, something went really weird! o_O"));
}
} else {
MessageBox(_T("Sorry, your device doesn't support common dialogs (Samsung and Motorola Q Smartphone?), so you have to get commdlg.dll from somewhere first!"));
}
}