-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathButtonST.h
251 lines (211 loc) · 7.95 KB
/
ButtonST.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//
// Class: CButtonST
//
// Compiler: Visual C++
// Tested on: Visual C++ 5.0
// Visual C++ 6.0
//
// Version: See GetVersionC() or GetVersionI()
//
// Created: xx/xxxx/1998
// Updated: 18/April/2002
//
// Author: Davide Calabro' [email protected]
// http://www.softechsoftware.it
//
// Note: Code for the PreSubclassWindow and OnSetStyle functions
// has been taken from the COddButton class
// published by Paolo Messina and Jerzy Kaczorowski
//
// Disclaimer
// ----------
// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
// RISK OF USING THIS SOFTWARE.
//
// Terms of use
// ------------
// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
// ARE GENTLY ASKED TO DONATE 1$ (ONE U.S. DOLLAR) TO THE AUTHOR:
//
// Davide Calabro'
// P.O. Box 65
// 21019 Somma Lombardo (VA)
// Italy
//
#ifndef _BTNST_H
#define _BTNST_H
// Uncomment the following 2 lines to enable support for BCMenu class
#define BTNST_USE_BCMENU
#include "BCMenu.h"
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// Return values
#ifndef BTNST_OK
#define BTNST_OK 0
#endif
#ifndef BTNST_INVALIDRESOURCE
#define BTNST_INVALIDRESOURCE 1
#endif
#ifndef BTNST_FAILEDMASK
#define BTNST_FAILEDMASK 2
#endif
#ifndef BTNST_INVALIDINDEX
#define BTNST_INVALIDINDEX 3
#endif
#ifndef BTNST_INVALIDALIGN
#define BTNST_INVALIDALIGN 4
#endif
#ifndef BTNST_BADPARAM
#define BTNST_BADPARAM 5
#endif
// Dummy identifier for grayscale icon
#ifndef BTNST_AUTO_GRAY
#define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L)
#endif
class CButtonST : public CButton
{
public:
CButtonST();
~CButtonST();
enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right
ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom
ST_ALIGN_HORIZ_RIGHT // Icon/bitmap on the right, text on the left
};
enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside
BTNST_COLOR_FG_IN, // Text color when mouse is INside
BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside
BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside
BTNST_COLOR_BK_FOCUS, // Background color when the button is focused
BTNST_COLOR_FG_FOCUS, // Text color when the button is focused
BTNST_MAX_COLORS
};
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CButtonST)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PreSubclassWindow();
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
//}}AFX_VIRTUAL
public:
DWORD SetDefaultColors(BOOL bRepaint = TRUE);
DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE);
DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor);
DWORD OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint = TRUE);
DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE);
int GetCheck();
DWORD SetURL(LPCTSTR lpszURL = NULL);
void DrawTransparent(BOOL bRepaint = FALSE);
BOOL GetDefault();
DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE);
void SetTooltipText(int nText, BOOL bActivate = TRUE);
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
void ActivateTooltip(BOOL bEnable = TRUE);
DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE);
DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE);
DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE);
DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE);
DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE);
DWORD SetIcon(int nIconIn, int nIconOut = NULL);
DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL);
DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut = NULL, COLORREF crTransColorOut = 0);
DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0);
#ifdef BTNST_USE_BCMENU
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle = TRUE, UINT nToolbarID = NULL, CSize sizeToolbarIcon = CSize(16, 16), COLORREF crToolbarBk = RGB(255, 0, 255), BOOL bRepaint = TRUE);
#else
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE);
#endif
static short GetVersionI() {return 35;}
static LPCTSTR GetVersionC() {return (LPCTSTR)_T("3.5");}
BOOL m_bShowDisabledBitmap;
protected:
//{{AFX_MSG(CButtonST)
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSysColorChange();
afx_msg BOOL OnClicked();
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnEnable(BOOL bEnable);
afx_msg void OnCancelMode();
afx_msg UINT OnGetDlgCode();
//}}AFX_MSG
#ifdef BTNST_USE_BCMENU
afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
#endif
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
HICON CreateGrayscaleIcon(HICON hIcon);
virtual DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect);
virtual DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect);
BOOL m_bIsFlat; // Is a flat button?
BOOL m_bMouseOnButton; // Is mouse over the button?
BOOL m_bDrawTransparent; // Draw transparent?
BOOL m_bIsPressed; // Is button pressed?
BOOL m_bIsFocused; // Is button focused?
BOOL m_bIsDisabled; // Is button disabled?
BOOL m_bIsDefault; // Is default button?
BOOL m_bIsCheckBox; // Is the button a checkbox?
BYTE m_byAlign; // Align mode
BOOL m_bDrawBorder; // Draw border?
BOOL m_bDrawFlatFocus; // Draw focus rectangle for flat button?
COLORREF m_crColors[BTNST_MAX_COLORS]; // Colors to be used
HWND m_hParentWndMenu; // Handle to window for menu selection
BOOL m_bMenuDisplayed; // Is menu displayed ?
#ifdef BTNST_USE_BCMENU
BCMenu m_menuPopup; // BCMenu class instance
#else
HMENU m_hMenu; // Handle to associated menu
#endif
private:
LRESULT OnSetCheck(WPARAM wParam, LPARAM lParam);
LRESULT OnGetCheck(WPARAM wParam, LPARAM lParam);
LRESULT OnSetStyle(WPARAM wParam, LPARAM lParam);
LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
void CancelHover();
void FreeResources(BOOL bCheckForNULL = TRUE);
void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);
HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);
void DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, BOOL bIsDisabled);
void DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT *rItem, CRect *rCaption, BOOL bIsPressed, BOOL bIsDisabled);
void PaintBk(CDC* pDC);
void InitToolTip();
HCURSOR m_hCursor; // Handle to cursor
CToolTipCtrl m_ToolTip; // Tooltip
CDC m_dcBk;
CBitmap m_bmpBk;
CBitmap* m_pbmpOldBk;
BOOL m_bAlwaysTrack; // Always hilight button?
int m_nCheck; // Current value for checkbox
UINT m_nTypeStyle; // Button style
TCHAR m_szURL[_MAX_PATH]; // URL to open when clicked
#pragma pack(1)
typedef struct _STRUCT_ICONS
{
HICON hIcon; // Handle to icon
DWORD dwWidth; // Width of icon
DWORD dwHeight; // Height of icon
} STRUCT_ICONS;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_BITMAPS
{
HBITMAP hBitmap; // Handle to bitmap
DWORD dwWidth; // Width of bitmap
DWORD dwHeight; // Height of bitmap
HBITMAP hMask; // Handle to mask bitmap
COLORREF crTransparent; // Transparent color
} STRUCT_BITMAPS;
#pragma pack()
STRUCT_ICONS m_csIcons[2];
STRUCT_BITMAPS m_csBitmaps[2];
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif