|
1
|
|
-#include "stdafx.h"
|
|
2
|
|
-#include "BtnST.h"
|
|
3
|
|
-
|
|
4
|
|
-#ifdef BTNST_USE_SOUND
|
|
5
|
|
-#pragma comment(lib, "winmm.lib")
|
|
6
|
|
-#include <Mmsystem.h>
|
|
7
|
|
-#endif
|
|
8
|
|
-
|
|
9
|
|
-#ifdef _DEBUG
|
|
10
|
|
-#define new DEBUG_NEW
|
|
11
|
|
-#undef THIS_FILE
|
|
12
|
|
-static char THIS_FILE[] = __FILE__;
|
|
13
|
|
-#endif
|
|
14
|
|
-
|
|
15
|
|
-/////////////////////////////////////////////////////////////////////////////
|
|
16
|
|
-// CButtonST
|
|
17
|
|
-
|
|
18
|
|
-// Mask for control's type
|
|
19
|
|
-#define BS_TYPEMASK SS_TYPEMASK
|
|
20
|
|
-
|
|
21
|
|
-#ifndef TTM_SETTITLE
|
|
22
|
|
-#define TTM_SETTITLEA (WM_USER + 32) // wParam = TTI_*, lParam = char* szTitle
|
|
23
|
|
-#define TTM_SETTITLEW (WM_USER + 33) // wParam = TTI_*, lParam = wchar* szTitle
|
|
24
|
|
-#ifdef UNICODE
|
|
25
|
|
-#define TTM_SETTITLE TTM_SETTITLEW
|
|
26
|
|
-#else
|
|
27
|
|
-#define TTM_SETTITLE TTM_SETTITLEA
|
|
28
|
|
-#endif
|
|
29
|
|
-#endif
|
|
30
|
|
-
|
|
31
|
|
-#ifndef TTS_BALLOON
|
|
32
|
|
-#define TTS_BALLOON 0x40
|
|
33
|
|
-#endif
|
|
34
|
|
-
|
|
35
|
|
-CButtonST::CButtonST()
|
|
36
|
|
-{
|
|
37
|
|
- m_bIsPressed = FALSE;
|
|
38
|
|
- m_bIsFocused = FALSE;
|
|
39
|
|
- m_bIsDisabled = FALSE;
|
|
40
|
|
- m_bMouseOnButton = FALSE;
|
|
41
|
|
-
|
|
42
|
|
- FreeResources(FALSE);
|
|
43
|
|
-
|
|
44
|
|
- // Default type is "flat" button
|
|
45
|
|
- m_bIsFlat = TRUE;
|
|
46
|
|
- // Button will be tracked also if when the window is inactive (like Internet Explorer)
|
|
47
|
|
- m_bAlwaysTrack = TRUE;
|
|
48
|
|
-
|
|
49
|
|
- // By default draw border in "flat" button
|
|
50
|
|
- m_bDrawBorder = TRUE;
|
|
51
|
|
-
|
|
52
|
|
- // By default icon is aligned horizontally
|
|
53
|
|
- m_byAlign = ST_ALIGN_HORIZ;
|
|
54
|
|
-
|
|
55
|
|
- // By default use usual pressed style
|
|
56
|
|
- SetPressedStyle(BTNST_PRESSED_LEFTRIGHT, FALSE);
|
|
57
|
|
-
|
|
58
|
|
- // By default, for "flat" button, don't draw the focus rect
|
|
59
|
|
- m_bDrawFlatFocus = FALSE;
|
|
60
|
|
-
|
|
61
|
|
- // By default the button is not the default button
|
|
62
|
|
- m_bIsDefault = FALSE;
|
|
63
|
|
- // Invalid value, since type still unknown
|
|
64
|
|
- m_nTypeStyle = BS_TYPEMASK;
|
|
65
|
|
-
|
|
66
|
|
- // By default the button is not a checkbox
|
|
67
|
|
- m_bIsCheckBox = FALSE;
|
|
68
|
|
- m_nCheck = 0;
|
|
69
|
|
-
|
|
70
|
|
- // Set default colors
|
|
71
|
|
- SetDefaultColors(FALSE);
|
|
72
|
|
-
|
|
73
|
|
- // No tooltip created
|
|
74
|
|
- m_ToolTip.m_hWnd = NULL;
|
|
75
|
|
- m_dwToolTipStyle = 0;
|
|
76
|
|
-
|
|
77
|
|
- // Do not draw as a transparent button
|
|
78
|
|
- m_bDrawTransparent = FALSE;
|
|
79
|
|
- m_pbmpOldBk = NULL;
|
|
80
|
|
-
|
|
81
|
|
- // No URL defined
|
|
82
|
|
- SetURL(NULL);
|
|
83
|
|
-
|
|
84
|
|
- // No cursor defined
|
|
85
|
|
- m_hCursor = NULL;
|
|
86
|
|
-
|
|
87
|
|
- // No associated menu
|
|
88
|
|
-#ifndef BTNST_USE_BCMENU
|
|
89
|
|
- m_hMenu = NULL;
|
|
90
|
|
-#endif
|
|
91
|
|
- m_hParentWndMenu = NULL;
|
|
92
|
|
- m_bMenuDisplayed = FALSE;
|
|
93
|
|
-
|
|
94
|
|
- m_bShowDisabledBitmap = TRUE;
|
|
95
|
|
-
|
|
96
|
|
- m_ptImageOrg.x = 3;
|
|
97
|
|
- m_ptImageOrg.y = 3;
|
|
98
|
|
-
|
|
99
|
|
- // No defined callbacks
|
|
100
|
|
- ::ZeroMemory(&m_csCallbacks, sizeof(m_csCallbacks));
|
|
101
|
|
-
|
|
102
|
|
-#ifdef BTNST_USE_SOUND
|
|
103
|
|
- // No defined sounds
|
|
104
|
|
- ::ZeroMemory(&m_csSounds, sizeof(m_csSounds));
|
|
105
|
|
-#endif
|
|
106
|
|
-} // End of CButtonST
|
|
107
|
|
-
|
|
108
|
|
-CButtonST::~CButtonST()
|
|
109
|
|
-{
|
|
110
|
|
- // Restore old bitmap (if any)
|
|
111
|
|
- if (m_dcBk.m_hDC && m_pbmpOldBk)
|
|
112
|
|
- {
|
|
113
|
|
- m_dcBk.SelectObject(m_pbmpOldBk);
|
|
114
|
|
- } // if
|
|
115
|
|
-
|
|
116
|
|
- FreeResources();
|
|
117
|
|
-
|
|
118
|
|
- // Destroy the cursor (if any)
|
|
119
|
|
- if (m_hCursor) ::DestroyCursor(m_hCursor);
|
|
120
|
|
-
|
|
121
|
|
- // Destroy the menu (if any)
|
|
122
|
|
-#ifdef BTNST_USE_BCMENU
|
|
123
|
|
- if (m_menuPopup.m_hMenu) m_menuPopup.DestroyMenu();
|
|
124
|
|
-#else
|
|
125
|
|
- if (m_hMenu) ::DestroyMenu(m_hMenu);
|
|
126
|
|
-#endif
|
|
127
|
|
-} // End of ~CButtonST
|
|
128
|
|
-
|
|
129
|
|
-BEGIN_MESSAGE_MAP(CButtonST, CButton)
|
|
130
|
|
- //{{AFX_MSG_MAP(CButtonST)
|
|
131
|
|
- ON_WM_SETCURSOR()
|
|
132
|
|
- ON_WM_KILLFOCUS()
|
|
133
|
|
- ON_WM_MOUSEMOVE()
|
|
134
|
|
- ON_WM_SYSCOLORCHANGE()
|
|
135
|
|
- ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)
|
|
136
|
|
- ON_WM_ACTIVATE()
|
|
137
|
|
- ON_WM_ENABLE()
|
|
138
|
|
- ON_WM_CANCELMODE()
|
|
139
|
|
- ON_WM_GETDLGCODE()
|
|
140
|
|
- ON_WM_CTLCOLOR_REFLECT()
|
|
141
|
|
- //}}AFX_MSG_MAP
|
|
142
|
|
-#ifdef BTNST_USE_BCMENU
|
|
143
|
|
- ON_WM_MENUCHAR()
|
|
144
|
|
- ON_WM_MEASUREITEM()
|
|
145
|
|
-#endif
|
|
146
|
|
-
|
|
147
|
|
- ON_MESSAGE(BM_SETSTYLE, OnSetStyle)
|
|
148
|
|
- ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
|
|
149
|
|
- ON_MESSAGE(BM_SETCHECK, OnSetCheck)
|
|
150
|
|
- ON_MESSAGE(BM_GETCHECK, OnGetCheck)
|
|
151
|
|
-END_MESSAGE_MAP()
|
|
152
|
|
-
|
|
153
|
|
-void CButtonST::FreeResources(BOOL bCheckForNULL)
|
|
154
|
|
-{
|
|
155
|
|
- if (bCheckForNULL)
|
|
156
|
|
- {
|
|
157
|
|
- // Destroy icons
|
|
158
|
|
- // Note: the following two lines MUST be here! even if
|
|
159
|
|
- // BoundChecker says they are unnecessary!
|
|
160
|
|
- if (m_csIcons[0].hIcon) ::DestroyIcon(m_csIcons[0].hIcon);
|
|
161
|
|
- if (m_csIcons[1].hIcon) ::DestroyIcon(m_csIcons[1].hIcon);
|
|
162
|
|
-
|
|
163
|
|
- // Destroy bitmaps
|
|
164
|
|
- if (m_csBitmaps[0].hBitmap) ::DeleteObject(m_csBitmaps[0].hBitmap);
|
|
165
|
|
- if (m_csBitmaps[1].hBitmap) ::DeleteObject(m_csBitmaps[1].hBitmap);
|
|
166
|
|
-
|
|
167
|
|
- // Destroy mask bitmaps
|
|
168
|
|
- if (m_csBitmaps[0].hMask) ::DeleteObject(m_csBitmaps[0].hMask);
|
|
169
|
|
- if (m_csBitmaps[1].hMask) ::DeleteObject(m_csBitmaps[1].hMask);
|
|
170
|
|
- } // if
|
|
171
|
|
-
|
|
172
|
|
- ::ZeroMemory(&m_csIcons, sizeof(m_csIcons));
|
|
173
|
|
- ::ZeroMemory(&m_csBitmaps, sizeof(m_csBitmaps));
|
|
174
|
|
-} // End of FreeResources
|
|
175
|
|
-
|
|
176
|
|
-void CButtonST::PreSubclassWindow()
|
|
177
|
|
-{
|
|
178
|
|
- UINT nBS;
|
|
179
|
|
-
|
|
180
|
|
- nBS = GetButtonStyle();
|
|
181
|
|
-
|
|
182
|
|
- // Set initial control type
|
|
183
|
|
- m_nTypeStyle = nBS & BS_TYPEMASK;
|
|
184
|
|
-
|
|
185
|
|
- // Check if this is a checkbox
|
|
186
|
|
- if (nBS & BS_CHECKBOX) m_bIsCheckBox = TRUE;
|
|
187
|
|
-
|
|
188
|
|
- // Set initial default state flag
|
|
189
|
|
- if (m_nTypeStyle == BS_DEFPUSHBUTTON)
|
|
190
|
|
- {
|
|
191
|
|
- // Set default state for a default button
|
|
192
|
|
- m_bIsDefault = TRUE;
|
|
193
|
|
-
|
|
194
|
|
- // Adjust style for default button
|
|
195
|
|
- m_nTypeStyle = BS_PUSHBUTTON;
|
|
196
|
|
- } // If
|
|
197
|
|
-
|
|
198
|
|
- // You should not set the Owner Draw before this call
|
|
199
|
|
- // (don't use the resource editor "Owner Draw" or
|
|
200
|
|
- // ModifyStyle(0, BS_OWNERDRAW) before calling PreSubclassWindow() )
|
|
201
|
|
- ASSERT(m_nTypeStyle != BS_OWNERDRAW);
|
|
202
|
|
-
|
|
203
|
|
- // Switch to owner-draw
|
|
204
|
|
- ModifyStyle(BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED);
|
|
205
|
|
-
|
|
206
|
|
- CButton::PreSubclassWindow();
|
|
207
|
|
-} // End of PreSubclassWindow
|
|
208
|
|
-
|
|
209
|
|
-UINT CButtonST::OnGetDlgCode()
|
|
210
|
|
-{
|
|
211
|
|
- UINT nCode = CButton::OnGetDlgCode();
|
|
212
|
|
-
|
|
213
|
|
- // Tell the system if we want default state handling
|
|
214
|
|
- // (losing default state always allowed)
|
|
215
|
|
- nCode |= (m_bIsDefault ? DLGC_DEFPUSHBUTTON : DLGC_UNDEFPUSHBUTTON);
|
|
216
|
|
-
|
|
217
|
|
- return nCode;
|
|
218
|
|
-} // End of OnGetDlgCode
|
|
219
|
|
-
|
|
220
|
|
-BOOL CButtonST::PreTranslateMessage(MSG* pMsg)
|
|
221
|
|
-{
|
|
222
|
|
- InitToolTip();
|
|
223
|
|
- m_ToolTip.RelayEvent(pMsg);
|
|
224
|
|
-
|
|
225
|
|
- if (pMsg->message == WM_LBUTTONDBLCLK)
|
|
226
|
|
- pMsg->message = WM_LBUTTONDOWN;
|
|
227
|
|
-
|
|
228
|
|
- return CButton::PreTranslateMessage(pMsg);
|
|
229
|
|
-} // End of PreTranslateMessage
|
|
230
|
|
-
|
|
231
|
|
-HBRUSH CButtonST::CtlColor(CDC* pDC, UINT nCtlColor)
|
|
232
|
|
-{
|
|
233
|
|
- return (HBRUSH)::GetStockObject(NULL_BRUSH);
|
|
234
|
|
-} // End of CtlColor
|
|
235
|
|
-
|
|
236
|
|
-void CButtonST::OnSysColorChange()
|
|
237
|
|
-{
|
|
238
|
|
- CButton::OnSysColorChange();
|
|
239
|
|
-
|
|
240
|
|
- m_dcBk.DeleteDC();
|
|
241
|
|
- m_bmpBk.DeleteObject();
|
|
242
|
|
- SetDefaultColors();
|
|
243
|
|
-} // End of OnSysColorChange
|
|
244
|
|
-
|
|
245
|
|
-LRESULT CButtonST::OnSetStyle(WPARAM wParam, LPARAM lParam)
|
|
246
|
|
-{
|
|
247
|
|
- UINT nNewType = (wParam & BS_TYPEMASK);
|
|
248
|
|
-
|
|
249
|
|
- // Update default state flag
|
|
250
|
|
- if (nNewType == BS_DEFPUSHBUTTON)
|
|
251
|
|
- {
|
|
252
|
|
- m_bIsDefault = TRUE;
|
|
253
|
|
- } // if
|
|
254
|
|
- else if (nNewType == BS_PUSHBUTTON)
|
|
255
|
|
- {
|
|
256
|
|
- // Losing default state always allowed
|
|
257
|
|
- m_bIsDefault = FALSE;
|
|
258
|
|
- } // if
|
|
259
|
|
-
|
|
260
|
|
- // Can't change control type after owner-draw is set.
|
|
261
|
|
- // Let the system process changes to other style bits
|
|
262
|
|
- // and redrawing, while keeping owner-draw style
|
|
263
|
|
- return DefWindowProc(BM_SETSTYLE,
|
|
264
|
|
- (wParam & ~BS_TYPEMASK) | BS_OWNERDRAW, lParam);
|
|
265
|
|
-} // End of OnSetStyle
|
|
266
|
|
-
|
|
267
|
|
-LRESULT CButtonST::OnSetCheck(WPARAM wParam, LPARAM lParam)
|
|
268
|
|
-{
|
|
269
|
|
- ASSERT(m_bIsCheckBox);
|
|
270
|
|
-
|
|
271
|
|
- switch (wParam)
|
|
272
|
|
- {
|
|
273
|
|
- case BST_CHECKED:
|
|
274
|
|
- case BST_INDETERMINATE: // Indeterminate state is handled like checked state
|
|
275
|
|
- SetCheck(1);
|
|
276
|
|
- break;
|
|
277
|
|
- default:
|
|
278
|
|
- SetCheck(0);
|
|
279
|
|
- break;
|
|
280
|
|
- } // switch
|
|
281
|
|
-
|
|
282
|
|
- return 0;
|
|
283
|
|
-} // End of OnSetCheck
|
|
284
|
|
-
|
|
285
|
|
-LRESULT CButtonST::OnGetCheck(WPARAM wParam, LPARAM lParam)
|
|
286
|
|
-{
|
|
287
|
|
- ASSERT(m_bIsCheckBox);
|
|
288
|
|
- return GetCheck();
|
|
289
|
|
-} // End of OnGetCheck
|
|
290
|
|
-
|
|
291
|
|
-#ifdef BTNST_USE_BCMENU
|
|
292
|
|
-LRESULT CButtonST::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
|
|
293
|
|
-{
|
|
294
|
|
- LRESULT lResult;
|
|
295
|
|
- if (BCMenu::IsMenu(pMenu))
|
|
296
|
|
- lResult = BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
|
|
297
|
|
- else
|
|
298
|
|
- lResult = CButton::OnMenuChar(nChar, nFlags, pMenu);
|
|
299
|
|
- return lResult;
|
|
300
|
|
-} // End of OnMenuChar
|
|
301
|
|
-#endif
|
|
302
|
|
-
|
|
303
|
|
-#ifdef BTNST_USE_BCMENU
|
|
304
|
|
-void CButtonST::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
|
|
305
|
|
-{
|
|
306
|
|
- BOOL bSetFlag = FALSE;
|
|
307
|
|
- if (lpMeasureItemStruct->CtlType == ODT_MENU)
|
|
308
|
|
- {
|
|
309
|
|
- if (IsMenu((HMENU)lpMeasureItemStruct->itemID) && BCMenu::IsMenu((HMENU)lpMeasureItemStruct->itemID))
|
|
310
|
|
- {
|
|
311
|
|
- m_menuPopup.MeasureItem(lpMeasureItemStruct);
|
|
312
|
|
- bSetFlag = TRUE;
|
|
313
|
|
- } // if
|
|
314
|
|
- } // if
|
|
315
|
|
- if (!bSetFlag) CButton::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
|
|
316
|
|
-} // End of OnMeasureItem
|
|
317
|
|
-#endif
|
|
318
|
|
-
|
|
319
|
|
-void CButtonST::OnEnable(BOOL bEnable)
|
|
320
|
|
-{
|
|
321
|
|
- CButton::OnEnable(bEnable);
|
|
322
|
|
-
|
|
323
|
|
- if (bEnable == FALSE)
|
|
324
|
|
- {
|
|
325
|
|
- CWnd* pWnd = GetParent()->GetNextDlgTabItem(this);
|
|
326
|
|
- if (pWnd)
|
|
327
|
|
- pWnd->SetFocus();
|
|
328
|
|
- else
|
|
329
|
|
- GetParent()->SetFocus();
|
|
330
|
|
-
|
|
331
|
|
- CancelHover();
|
|
332
|
|
- } // if
|
|
333
|
|
-} // End of OnEnable
|
|
334
|
|
-
|
|
335
|
|
-void CButtonST::OnKillFocus(CWnd * pNewWnd)
|
|
336
|
|
-{
|
|
337
|
|
- CButton::OnKillFocus(pNewWnd);
|
|
338
|
|
- CancelHover();
|
|
339
|
|
-} // End of OnKillFocus
|
|
340
|
|
-
|
|
341
|
|
-void CButtonST::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
|
|
342
|
|
-{
|
|
343
|
|
- CButton::OnActivate(nState, pWndOther, bMinimized);
|
|
344
|
|
- if (nState == WA_INACTIVE) CancelHover();
|
|
345
|
|
-} // End of OnActivate
|
|
346
|
|
-
|
|
347
|
|
-void CButtonST::OnCancelMode()
|
|
348
|
|
-{
|
|
349
|
|
- CButton::OnCancelMode();
|
|
350
|
|
- CancelHover();
|
|
351
|
|
-} // End of OnCancelMode
|
|
352
|
|
-
|
|
353
|
|
-BOOL CButtonST::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
354
|
|
-{
|
|
355
|
|
- // If a cursor was specified then use it!
|
|
356
|
|
- if (m_hCursor != NULL)
|
|
357
|
|
- {
|
|
358
|
|
- ::SetCursor(m_hCursor);
|
|
359
|
|
- return TRUE;
|
|
360
|
|
- } // if
|
|
361
|
|
-
|
|
362
|
|
- return CButton::OnSetCursor(pWnd, nHitTest, message);
|
|
363
|
|
-} // End of OnSetCursor
|
|
364
|
|
-
|
|
365
|
|
-void CButtonST::CancelHover()
|
|
366
|
|
-{
|
|
367
|
|
- // Only for flat buttons
|
|
368
|
|
- if (m_bIsFlat)
|
|
369
|
|
- {
|
|
370
|
|
- if (m_bMouseOnButton)
|
|
371
|
|
- {
|
|
372
|
|
- m_bMouseOnButton = FALSE;
|
|
373
|
|
- Invalidate();
|
|
374
|
|
- } // if
|
|
375
|
|
- } // if
|
|
376
|
|
-} // End of CancelHover
|
|
377
|
|
-
|
|
378
|
|
-void CButtonST::OnMouseMove(UINT nFlags, CPoint point)
|
|
379
|
|
-{
|
|
380
|
|
- CWnd* wndUnderMouse = NULL;
|
|
381
|
|
- CWnd* wndActive = this;
|
|
382
|
|
- TRACKMOUSEEVENT csTME;
|
|
383
|
|
-
|
|
384
|
|
- CButton::OnMouseMove(nFlags, point);
|
|
385
|
|
-
|
|
386
|
|
- ClientToScreen(&point);
|
|
387
|
|
- wndUnderMouse = WindowFromPoint(point);
|
|
388
|
|
-
|
|
389
|
|
- // If the mouse enter the button with the left button pressed then do nothing
|
|
390
|
|
- if (nFlags & MK_LBUTTON && m_bMouseOnButton == FALSE) return;
|
|
391
|
|
-
|
|
392
|
|
- // If our button is not flat then do nothing
|
|
393
|
|
- if (m_bIsFlat == FALSE) return;
|
|
394
|
|
-
|
|
395
|
|
- if (m_bAlwaysTrack == FALSE) wndActive = GetActiveWindow();
|
|
396
|
|
-
|
|
397
|
|
- if (wndUnderMouse && wndUnderMouse->m_hWnd == m_hWnd && wndActive)
|
|
398
|
|
- {
|
|
399
|
|
- if (!m_bMouseOnButton)
|
|
400
|
|
- {
|
|
401
|
|
- m_bMouseOnButton = TRUE;
|
|
402
|
|
-
|
|
403
|
|
- Invalidate();
|
|
404
|
|
-
|
|
405
|
|
-#ifdef BTNST_USE_SOUND
|
|
406
|
|
- // Play sound ?
|
|
407
|
|
- if (m_csSounds[0].lpszSound)
|
|
408
|
|
- ::PlaySound(m_csSounds[0].lpszSound, m_csSounds[0].hMod, m_csSounds[0].dwFlags);
|
|
409
|
|
-#endif
|
|
410
|
|
-
|
|
411
|
|
- csTME.cbSize = sizeof(csTME);
|
|
412
|
|
- csTME.dwFlags = TME_LEAVE;
|
|
413
|
|
- csTME.hwndTrack = m_hWnd;
|
|
414
|
|
- ::_TrackMouseEvent(&csTME);
|
|
415
|
|
- } // if
|
|
416
|
|
- } else CancelHover();
|
|
417
|
|
-} // End of OnMouseMove
|
|
418
|
|
-
|
|
419
|
|
-// Handler for WM_MOUSELEAVE
|
|
420
|
|
-LRESULT CButtonST::OnMouseLeave(WPARAM wParam, LPARAM lParam)
|
|
421
|
|
-{
|
|
422
|
|
- CancelHover();
|
|
423
|
|
- return 0;
|
|
424
|
|
-} // End of OnMouseLeave
|
|
425
|
|
-
|
|
426
|
|
-BOOL CButtonST::OnClicked()
|
|
427
|
|
-{
|
|
428
|
|
- SetFocus();
|
|
429
|
|
-
|
|
430
|
|
-#ifdef BTNST_USE_SOUND
|
|
431
|
|
- // Play sound ?
|
|
432
|
|
- if (m_csSounds[1].lpszSound)
|
|
433
|
|
- ::PlaySound(m_csSounds[1].lpszSound, m_csSounds[1].hMod, m_csSounds[1].dwFlags);
|
|
434
|
|
-#endif
|
|
435
|
|
-
|
|
436
|
|
- if (m_bIsCheckBox)
|
|
437
|
|
- {
|
|
438
|
|
- m_nCheck = !m_nCheck;
|
|
439
|
|
- Invalidate();
|
|
440
|
|
- } // if
|
|
441
|
|
- else
|
|
442
|
|
- {
|
|
443
|
|
- // Handle the menu (if any)
|
|
444
|
|
-#ifdef BTNST_USE_BCMENU
|
|
445
|
|
- if (m_menuPopup.m_hMenu)
|
|
446
|
|
-#else
|
|
447
|
|
- if (m_hMenu)
|
|
448
|
|
-#endif
|
|
449
|
|
- {
|
|
450
|
|
- CRect rWnd;
|
|
451
|
|
- GetWindowRect(rWnd);
|
|
452
|
|
-
|
|
453
|
|
- m_bMenuDisplayed = TRUE;
|
|
454
|
|
- Invalidate();
|
|
455
|
|
-
|
|
456
|
|
-#ifdef BTNST_USE_BCMENU
|
|
457
|
|
- BCMenu* psub = (BCMenu*)m_menuPopup.GetSubMenu(0);
|
|
458
|
|
- if (m_csCallbacks.hWnd) ::SendMessage(m_csCallbacks.hWnd, m_csCallbacks.nMessage, (WPARAM)psub, m_csCallbacks.lParam);
|
|
459
|
|
- DWORD dwRetValue = psub->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, rWnd.left, rWnd.bottom, this, NULL);
|
|
460
|
|
-#else
|
|
461
|
|
- HMENU hSubMenu = ::GetSubMenu(m_hMenu, 0);
|
|
462
|
|
- if (m_csCallbacks.hWnd) ::SendMessage(m_csCallbacks.hWnd, m_csCallbacks.nMessage, (WPARAM)hSubMenu, m_csCallbacks.lParam);
|
|
463
|
|
- DWORD dwRetValue = ::TrackPopupMenuEx(hSubMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, rWnd.left, rWnd.bottom, m_hParentWndMenu, NULL);
|
|
464
|
|
-#endif
|
|
465
|
|
-
|
|
466
|
|
- m_bMenuDisplayed = FALSE;
|
|
467
|
|
- Invalidate();
|
|
468
|
|
-
|
|
469
|
|
- if (dwRetValue)
|
|
470
|
|
- ::PostMessage(m_hParentWndMenu, WM_COMMAND, MAKEWPARAM(dwRetValue, 0), (LPARAM)NULL);
|
|
471
|
|
- } // if
|
|
472
|
|
- else
|
|
473
|
|
- {
|
|
474
|
|
- // Handle the URL (if any)
|
|
475
|
|
- if (_tcslen(m_szURL) > 0)
|
|
476
|
|
- {
|
|
477
|
|
- SHELLEXECUTEINFO csSEI;
|
|
478
|
|
-
|
|
479
|
|
- memset(&csSEI, 0, sizeof(csSEI));
|
|
480
|
|
- csSEI.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
481
|
|
- csSEI.fMask = SEE_MASK_FLAG_NO_UI;
|
|
482
|
|
- csSEI.lpVerb = _T("open");
|
|
483
|
|
- csSEI.lpFile = m_szURL;
|
|
484
|
|
- csSEI.nShow = SW_SHOWMAXIMIZED;
|
|
485
|
|
- ::ShellExecuteEx(&csSEI);
|
|
486
|
|
- } // if
|
|
487
|
|
- } // else
|
|
488
|
|
- } // else
|
|
489
|
|
-
|
|
490
|
|
- return FALSE;
|
|
491
|
|
-} // End of OnClicked
|
|
492
|
|
-
|
|
493
|
|
-void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
|
|
494
|
|
-{
|
|
495
|
|
- CDC* pDC = CDC::FromHandle(lpDIS->hDC);
|
|
496
|
|
-
|
|
497
|
|
- // Checkbox?
|
|
498
|
|
- if (m_bIsCheckBox)
|
|
499
|
|
- {
|
|
500
|
|
- m_bIsPressed = (lpDIS->itemState & ODS_SELECTED) || (m_nCheck != 0);
|
|
501
|
|
- } // if
|
|
502
|
|
- else // Normal button OR other button style ...
|
|
503
|
|
- {
|
|
504
|
|
- m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
|
|
505
|
|
-
|
|
506
|
|
- // If there is a menu and it's displayed, draw the button as pressed
|
|
507
|
|
- if (
|
|
508
|
|
-#ifdef BTNST_USE_BCMENU
|
|
509
|
|
- m_menuPopup.m_hMenu
|
|
510
|
|
-#else
|
|
511
|
|
- m_hMenu
|
|
512
|
|
-#endif
|
|
513
|
|
- && m_bMenuDisplayed) m_bIsPressed = TRUE;
|
|
514
|
|
- } // else
|
|
515
|
|
-
|
|
516
|
|
- m_bIsFocused = (lpDIS->itemState & ODS_FOCUS);
|
|
517
|
|
- m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);
|
|
518
|
|
-
|
|
519
|
|
- CRect itemRect = lpDIS->rcItem;
|
|
520
|
|
-
|
|
521
|
|
- pDC->SetBkMode(TRANSPARENT);
|
|
522
|
|
-
|
|
523
|
|
- // Prepare draw... paint button background
|
|
524
|
|
-
|
|
525
|
|
- // Draw transparent?
|
|
526
|
|
- if (m_bDrawTransparent)
|
|
527
|
|
- PaintBk(pDC);
|
|
528
|
|
- else
|
|
529
|
|
- OnDrawBackground(pDC, &itemRect);
|
|
530
|
|
-
|
|
531
|
|
- // Draw button border
|
|
532
|
|
- OnDrawBorder(pDC, &itemRect);
|
|
533
|
|
-
|
|
534
|
|
- // Read the button's title
|
|
535
|
|
- CString sTitle;
|
|
536
|
|
- GetWindowText(sTitle);
|
|
537
|
|
-
|
|
538
|
|
- CRect captionRect = lpDIS->rcItem;
|
|
539
|
|
-
|
|
540
|
|
- // Draw the icon
|
|
541
|
|
- if (m_csIcons[0].hIcon)
|
|
542
|
|
- {
|
|
543
|
|
- DrawTheIcon(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
|
|
544
|
|
- } // if
|
|
545
|
|
-
|
|
546
|
|
- if (m_csBitmaps[0].hBitmap)
|
|
547
|
|
- {
|
|
548
|
|
- pDC->SetBkColor(RGB(255,255,255));
|
|
549
|
|
- DrawTheBitmap(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
|
|
550
|
|
- } // if
|
|
551
|
|
-
|
|
552
|
|
- // Write the button title (if any)
|
|
553
|
|
- if (sTitle.IsEmpty() == FALSE)
|
|
554
|
|
- {
|
|
555
|
|
- DrawTheText(pDC, (LPCTSTR)sTitle, &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
|
|
556
|
|
- } // if
|
|
557
|
|
-
|
|
558
|
|
- if (m_bIsFlat == FALSE || (m_bIsFlat && m_bDrawFlatFocus))
|
|
559
|
|
- {
|
|
560
|
|
- // Draw the focus rect
|
|
561
|
|
- if (m_bIsFocused)
|
|
562
|
|
- {
|
|
563
|
|
- CRect focusRect = itemRect;
|
|
564
|
|
- focusRect.DeflateRect(3, 3);
|
|
565
|
|
- pDC->DrawFocusRect(&focusRect);
|
|
566
|
|
- } // if
|
|
567
|
|
- } // if
|
|
568
|
|
-} // End of DrawItem
|
|
569
|
|
-
|
|
570
|
|
-void CButtonST::PaintBk(CDC* pDC)
|
|
571
|
|
-{
|
|
572
|
|
- CClientDC clDC(GetParent());
|
|
573
|
|
- CRect rect;
|
|
574
|
|
- CRect rect1;
|
|
575
|
|
-
|
|
576
|
|
- GetClientRect(rect);
|
|
577
|
|
-
|
|
578
|
|
- GetWindowRect(rect1);
|
|
579
|
|
- GetParent()->ScreenToClient(rect1);
|
|
580
|
|
-
|
|
581
|
|
- if (m_dcBk.m_hDC == NULL)
|
|
582
|
|
- {
|
|
583
|
|
- m_dcBk.CreateCompatibleDC(&clDC);
|
|
584
|
|
- m_bmpBk.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
|
|
585
|
|
- m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);
|
|
586
|
|
- m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
|
|
587
|
|
- } // if
|
|
588
|
|
-
|
|
589
|
|
- pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);
|
|
590
|
|
-} // End of PaintBk
|
|
591
|
|
-
|
|
592
|
|
-HBITMAP CButtonST::CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor)
|
|
593
|
|
-{
|
|
594
|
|
- HBITMAP hMask = NULL;
|
|
595
|
|
- HDC hdcSrc = NULL;
|
|
596
|
|
- HDC hdcDest = NULL;
|
|
597
|
|
- HBITMAP hbmSrcT = NULL;
|
|
598
|
|
- HBITMAP hbmDestT = NULL;
|
|
599
|
|
- COLORREF crSaveBk;
|
|
600
|
|
- COLORREF crSaveDestText;
|
|
601
|
|
-
|
|
602
|
|
- hMask = ::CreateBitmap(dwWidth, dwHeight, 1, 1, NULL);
|
|
603
|
|
- if (hMask == NULL) return NULL;
|
|
604
|
|
-
|
|
605
|
|
- hdcSrc = ::CreateCompatibleDC(NULL);
|
|
606
|
|
- hdcDest = ::CreateCompatibleDC(NULL);
|
|
607
|
|
-
|
|
608
|
|
- hbmSrcT = (HBITMAP)::SelectObject(hdcSrc, hSourceBitmap);
|
|
609
|
|
- hbmDestT = (HBITMAP)::SelectObject(hdcDest, hMask);
|
|
610
|
|
-
|
|
611
|
|
- crSaveBk = ::SetBkColor(hdcSrc, crTransColor);
|
|
612
|
|
-
|
|
613
|
|
- ::BitBlt(hdcDest, 0, 0, dwWidth, dwHeight, hdcSrc, 0, 0, SRCCOPY);
|
|
614
|
|
-
|
|
615
|
|
- crSaveDestText = ::SetTextColor(hdcSrc, RGB(255, 255, 255));
|
|
616
|
|
- ::SetBkColor(hdcSrc,RGB(0, 0, 0));
|
|
617
|
|
-
|
|
618
|
|
- ::BitBlt(hdcSrc, 0, 0, dwWidth, dwHeight, hdcDest, 0, 0, SRCAND);
|
|
619
|
|
-
|
|
620
|
|
- SetTextColor(hdcDest, crSaveDestText);
|
|
621
|
|
-
|
|
622
|
|
- ::SetBkColor(hdcSrc, crSaveBk);
|
|
623
|
|
- ::SelectObject(hdcSrc, hbmSrcT);
|
|
624
|
|
- ::SelectObject(hdcDest, hbmDestT);
|
|
625
|
|
-
|
|
626
|
|
- ::DeleteDC(hdcSrc);
|
|
627
|
|
- ::DeleteDC(hdcDest);
|
|
628
|
|
-
|
|
629
|
|
- return hMask;
|
|
630
|
|
-} // End of CreateBitmapMask
|
|
631
|
|
-
|
|
632
|
|
-//
|
|
633
|
|
-// Parameters:
|
|
634
|
|
-// [IN] bHasTitle
|
|
635
|
|
-// TRUE if the button has a text
|
|
636
|
|
-// [IN] rpItem
|
|
637
|
|
-// A pointer to a RECT structure indicating the allowed paint area
|
|
638
|
|
-// [IN/OUT]rpTitle
|
|
639
|
|
-// A pointer to a CRect object indicating the paint area reserved for the
|
|
640
|
|
-// text. This structure will be modified if necessary.
|
|
641
|
|
-// [IN] bIsPressed
|
|
642
|
|
-// TRUE if the button is currently pressed
|
|
643
|
|
-// [IN] dwWidth
|
|
644
|
|
-// Width of the image (icon or bitmap)
|
|
645
|
|
-// [IN] dwHeight
|
|
646
|
|
-// Height of the image (icon or bitmap)
|
|
647
|
|
-// [OUT] rpImage
|
|
648
|
|
-// A pointer to a CRect object that will receive the area available to the image
|
|
649
|
|
-//
|
|
650
|
|
-void CButtonST::PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage)
|
|
651
|
|
-{
|
|
652
|
|
- CRect rBtn;
|
|
653
|
|
-
|
|
654
|
|
- rpImage->CopyRect(rpItem);
|
|
655
|
|
-
|
|
656
|
|
- switch (m_byAlign)
|
|
657
|
|
- {
|
|
658
|
|
- case ST_ALIGN_HORIZ:
|
|
659
|
|
- if (bHasTitle == FALSE)
|
|
660
|
|
- {
|
|
661
|
|
- // Center image horizontally
|
|
662
|
|
- rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
|
|
663
|
|
- }
|
|
664
|
|
- else
|
|
665
|
|
- {
|
|
666
|
|
- // Image must be placed just inside the focus rect
|
|
667
|
|
- rpImage->left += m_ptImageOrg.x;
|
|
668
|
|
- rpTitle->left += dwWidth + m_ptImageOrg.x;
|
|
669
|
|
- }
|
|
670
|
|
- // Center image vertically
|
|
671
|
|
- rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
|
|
672
|
|
- break;
|
|
673
|
|
-
|
|
674
|
|
- case ST_ALIGN_HORIZ_RIGHT:
|
|
675
|
|
- GetClientRect(&rBtn);
|
|
676
|
|
- if (bHasTitle == FALSE)
|
|
677
|
|
- {
|
|
678
|
|
- // Center image horizontally
|
|
679
|
|
- rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
|
|
680
|
|
- }
|
|
681
|
|
- else
|
|
682
|
|
- {
|
|
683
|
|
- // Image must be placed just inside the focus rect
|
|
684
|
|
- rpTitle->right = rpTitle->Width() - dwWidth - m_ptImageOrg.x;
|
|
685
|
|
- rpTitle->left = m_ptImageOrg.x;
|
|
686
|
|
- rpImage->left = rBtn.right - dwWidth - m_ptImageOrg.x;
|
|
687
|
|
- // Center image vertically
|
|
688
|
|
- rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
|
|
689
|
|
- }
|
|
690
|
|
- break;
|
|
691
|
|
-
|
|
692
|
|
- case ST_ALIGN_VERT:
|
|
693
|
|
- // Center image horizontally
|
|
694
|
|
- rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);
|
|
695
|
|
- if (bHasTitle == FALSE)
|
|
696
|
|
- {
|
|
697
|
|
- // Center image vertically
|
|
698
|
|
- rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);
|
|
699
|
|
- }
|
|
700
|
|
- else
|
|
701
|
|
- {
|
|
702
|
|
- rpImage->top = m_ptImageOrg.y;
|
|
703
|
|
- rpTitle->top += dwHeight;
|
|
704
|
|
- }
|
|
705
|
|
- break;
|
|
706
|
|
-
|
|
707
|
|
- case ST_ALIGN_OVERLAP:
|
|
708
|
|
- break;
|
|
709
|
|
- } // switch
|
|
710
|
|
-
|
|
711
|
|
- // If button is pressed then press image also
|
|
712
|
|
- if (bIsPressed && m_bIsCheckBox == FALSE)
|
|
713
|
|
- rpImage->OffsetRect(m_ptPressedOffset.x, m_ptPressedOffset.y);
|
|
714
|
|
-} // End of PrepareImageRect
|
|
715
|
|
-
|
|
716
|
|
-void CButtonST::DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
|
|
717
|
|
-{
|
|
718
|
|
- BYTE byIndex = 0;
|
|
719
|
|
-
|
|
720
|
|
- // Select the icon to use
|
|
721
|
|
- if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))
|
|
722
|
|
- byIndex = 0;
|
|
723
|
|
- else
|
|
724
|
|
- byIndex = (m_csIcons[1].hIcon == NULL ? 0 : 1);
|
|
725
|
|
-
|
|
726
|
|
- CRect rImage;
|
|
727
|
|
- PrepareImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, m_csIcons[byIndex].dwWidth, m_csIcons[byIndex].dwHeight, &rImage);
|
|
728
|
|
-
|
|
729
|
|
- // Ole'!
|
|
730
|
|
- pDC->DrawState( rImage.TopLeft(),
|
|
731
|
|
- rImage.Size(),
|
|
732
|
|
- m_csIcons[byIndex].hIcon,
|
|
733
|
|
- (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
|
|
734
|
|
- (CBrush*)NULL);
|
|
735
|
|
-} // End of DrawTheIcon
|
|
736
|
|
-
|
|
737
|
|
-void CButtonST::DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
|
|
738
|
|
-{
|
|
739
|
|
- HDC hdcBmpMem = NULL;
|
|
740
|
|
- HBITMAP hbmOldBmp = NULL;
|
|
741
|
|
- HDC hdcMem = NULL;
|
|
742
|
|
- HBITMAP hbmT = NULL;
|
|
743
|
|
-
|
|
744
|
|
- BYTE byIndex = 0;
|
|
745
|
|
-
|
|
746
|
|
- // Select the bitmap to use
|
|
747
|
|
- if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))
|
|
748
|
|
- byIndex = 0;
|
|
749
|
|
- else
|
|
750
|
|
- byIndex = (m_csBitmaps[1].hBitmap == NULL ? 0 : 1);
|
|
751
|
|
-
|
|
752
|
|
- CRect rImage;
|
|
753
|
|
- PrepareImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, &rImage);
|
|
754
|
|
-
|
|
755
|
|
- hdcBmpMem = ::CreateCompatibleDC(pDC->m_hDC);
|
|
756
|
|
-
|
|
757
|
|
- hbmOldBmp = (HBITMAP)::SelectObject(hdcBmpMem, m_csBitmaps[byIndex].hBitmap);
|
|
758
|
|
-
|
|
759
|
|
- hdcMem = ::CreateCompatibleDC(NULL);
|
|
760
|
|
-
|
|
761
|
|
- hbmT = (HBITMAP)::SelectObject(hdcMem, m_csBitmaps[byIndex].hMask);
|
|
762
|
|
-
|
|
763
|
|
- if (bIsDisabled && m_bShowDisabledBitmap)
|
|
764
|
|
- {
|
|
765
|
|
- HDC hDC = NULL;
|
|
766
|
|
- HBITMAP hBitmap = NULL;
|
|
767
|
|
-
|
|
768
|
|
- hDC = ::CreateCompatibleDC(pDC->m_hDC);
|
|
769
|
|
- hBitmap = ::CreateCompatibleBitmap(pDC->m_hDC, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight);
|
|
770
|
|
- HBITMAP hOldBmp2 = (HBITMAP)::SelectObject(hDC, hBitmap);
|
|
771
|
|
-
|
|
772
|
|
- RECT rRect;
|
|
773
|
|
- rRect.left = 0;
|
|
774
|
|
- rRect.top = 0;
|
|
775
|
|
- rRect.right = rImage.right + 1;
|
|
776
|
|
- rRect.bottom = rImage.bottom + 1;
|
|
777
|
|
- ::FillRect(hDC, &rRect, (HBRUSH)RGB(255, 255, 255));
|
|
778
|
|
-
|
|
779
|
|
- COLORREF crOldColor = ::SetBkColor(hDC, RGB(255,255,255));
|
|
780
|
|
-
|
|
781
|
|
- ::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);
|
|
782
|
|
- ::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);
|
|
783
|
|
-
|
|
784
|
|
- ::SetBkColor(hDC, crOldColor);
|
|
785
|
|
- ::SelectObject(hDC, hOldBmp2);
|
|
786
|
|
- ::DeleteDC(hDC);
|
|
787
|
|
-
|
|
788
|
|
- pDC->DrawState( CPoint(rImage.left/*+1*/, rImage.top),
|
|
789
|
|
- CSize(m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight),
|
|
790
|
|
- hBitmap, DST_BITMAP | DSS_DISABLED);
|
|
791
|
|
-
|
|
792
|
|
- ::DeleteObject(hBitmap);
|
|
793
|
|
- } // if
|
|
794
|
|
- else
|
|
795
|
|
- {
|
|
796
|
|
- ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);
|
|
797
|
|
-
|
|
798
|
|
- ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);
|
|
799
|
|
- } // else
|
|
800
|
|
-
|
|
801
|
|
- ::SelectObject(hdcMem, hbmT);
|
|
802
|
|
- ::DeleteDC(hdcMem);
|
|
803
|
|
-
|
|
804
|
|
- ::SelectObject(hdcBmpMem, hbmOldBmp);
|
|
805
|
|
- ::DeleteDC(hdcBmpMem);
|
|
806
|
|
-} // End of DrawTheBitmap
|
|
807
|
|
-
|
|
808
|
|
-void CButtonST::DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
|
|
809
|
|
-{
|
|
810
|
|
- // Draw the button's title
|
|
811
|
|
- // If button is pressed then "press" title also
|
|
812
|
|
- if (m_bIsPressed && m_bIsCheckBox == FALSE)
|
|
813
|
|
- rpCaption->OffsetRect(m_ptPressedOffset.x, m_ptPressedOffset.y);
|
|
814
|
|
-
|
|
815
|
|
- // ONLY FOR DEBUG
|
|
816
|
|
- //CBrush brBtnShadow(RGB(255, 0, 0));
|
|
817
|
|
- //pDC->FrameRect(rCaption, &brBtnShadow);
|
|
818
|
|
-
|
|
819
|
|
- // Center text
|
|
820
|
|
- CRect centerRect = rpCaption;
|
|
821
|
|
- pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
|
|
822
|
|
- rpCaption->OffsetRect((centerRect.Width() - rpCaption->Width())/2, (centerRect.Height() - rpCaption->Height())/2);
|
|
823
|
|
- /* RFU
|
|
824
|
|
- rpCaption->OffsetRect(0, (centerRect.Height() - rpCaption->Height())/2);
|
|
825
|
|
- rpCaption->OffsetRect((centerRect.Width() - rpCaption->Width())-4, (centerRect.Height() - rpCaption->Height())/2);
|
|
826
|
|
- */
|
|
827
|
|
-
|
|
828
|
|
- pDC->SetBkMode(TRANSPARENT);
|
|
829
|
|
- /*
|
|
830
|
|
- pDC->DrawState(rCaption->TopLeft(), rCaption->Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),
|
|
831
|
|
- TRUE, 0, (CBrush*)NULL);
|
|
832
|
|
- */
|
|
833
|
|
- if (m_bIsDisabled)
|
|
834
|
|
- {
|
|
835
|
|
- rpCaption->OffsetRect(1, 1);
|
|
836
|
|
- pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
|
|
837
|
|
- pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
|
|
838
|
|
- rpCaption->OffsetRect(-1, -1);
|
|
839
|
|
- pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
|
|
840
|
|
- pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
|
|
841
|
|
- } // if
|
|
842
|
|
- else
|
|
843
|
|
- {
|
|
844
|
|
- if (m_bMouseOnButton || m_bIsPressed)
|
|
845
|
|
- {
|
|
846
|
|
- pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);
|
|
847
|
|
- pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);
|
|
848
|
|
- } // if
|
|
849
|
|
- else
|
|
850
|
|
- {
|
|
851
|
|
- if (m_bIsFocused)
|
|
852
|
|
- {
|
|
853
|
|
- pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_FOCUS]);
|
|
854
|
|
- pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_FOCUS]);
|
|
855
|
|
- } // if
|
|
856
|
|
- else
|
|
857
|
|
- {
|
|
858
|
|
- pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);
|
|
859
|
|
- pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);
|
|
860
|
|
- } // else
|
|
861
|
|
- } // else
|
|
862
|
|
- pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);
|
|
863
|
|
- } // if
|
|
864
|
|
-} // End of DrawTheText
|
|
865
|
|
-
|
|
866
|
|
-// This function creates a grayscale bitmap starting from a given bitmap.
|
|
867
|
|
-// The resulting bitmap will have the same size of the original one.
|
|
868
|
|
-//
|
|
869
|
|
-// Parameters:
|
|
870
|
|
-// [IN] hBitmap
|
|
871
|
|
-// Handle to the original bitmap.
|
|
872
|
|
-// [IN] dwWidth
|
|
873
|
|
-// Specifies the bitmap width, in pixels.
|
|
874
|
|
-// [IN] dwHeight
|
|
875
|
|
-// Specifies the bitmap height, in pixels.
|
|
876
|
|
-// [IN] crTrans
|
|
877
|
|
-// Color to be used as transparent color. This color will be left unchanged.
|
|
878
|
|
-//
|
|
879
|
|
-// Return value:
|
|
880
|
|
-// If the function succeeds, the return value is the handle to the newly created
|
|
881
|
|
-// grayscale bitmap.
|
|
882
|
|
-// If the function fails, the return value is NULL.
|
|
883
|
|
-//
|
|
884
|
|
-HBITMAP CButtonST::CreateGrayscaleBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans)
|
|
885
|
|
-{
|
|
886
|
|
- HBITMAP hGrayBitmap = NULL;
|
|
887
|
|
- HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;
|
|
888
|
|
- HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;
|
|
889
|
|
-
|
|
890
|
|
- hMainDC = ::GetDC(NULL);
|
|
891
|
|
- if (hMainDC == NULL) return NULL;
|
|
892
|
|
- hMemDC1 = ::CreateCompatibleDC(hMainDC);
|
|
893
|
|
- if (hMemDC1 == NULL)
|
|
894
|
|
- {
|
|
895
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
896
|
|
- return NULL;
|
|
897
|
|
- } // if
|
|
898
|
|
- hMemDC2 = ::CreateCompatibleDC(hMainDC);
|
|
899
|
|
- if (hMemDC2 == NULL)
|
|
900
|
|
- {
|
|
901
|
|
- ::DeleteDC(hMemDC1);
|
|
902
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
903
|
|
- return NULL;
|
|
904
|
|
- } // if
|
|
905
|
|
-
|
|
906
|
|
- hGrayBitmap = ::CreateCompatibleBitmap(hMainDC, dwWidth, dwHeight);
|
|
907
|
|
- if (hGrayBitmap)
|
|
908
|
|
- {
|
|
909
|
|
- hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, hGrayBitmap);
|
|
910
|
|
- hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, hBitmap);
|
|
911
|
|
-
|
|
912
|
|
- //::BitBlt(hMemDC1, 0, 0, dwWidth, dwHeight, hMemDC2, 0, 0, SRCCOPY);
|
|
913
|
|
-
|
|
914
|
|
- DWORD dwLoopY = 0, dwLoopX = 0;
|
|
915
|
|
- COLORREF crPixel = 0;
|
|
916
|
|
- BYTE byNewPixel = 0;
|
|
917
|
|
-
|
|
918
|
|
- for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)
|
|
919
|
|
- {
|
|
920
|
|
- for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)
|
|
921
|
|
- {
|
|
922
|
|
- crPixel = ::GetPixel(hMemDC2, dwLoopX, dwLoopY);
|
|
923
|
|
- byNewPixel = (BYTE)((GetRValue(crPixel) * 0.299) + (GetGValue(crPixel) * 0.587) + (GetBValue(crPixel) * 0.114));
|
|
924
|
|
-
|
|
925
|
|
- if (crPixel != crTrans)
|
|
926
|
|
- ::SetPixel(hMemDC1, dwLoopX, dwLoopY, RGB(byNewPixel, byNewPixel, byNewPixel));
|
|
927
|
|
- else
|
|
928
|
|
- ::SetPixel(hMemDC1, dwLoopX, dwLoopY, crPixel);
|
|
929
|
|
- } // for
|
|
930
|
|
- } // for
|
|
931
|
|
-
|
|
932
|
|
- ::SelectObject(hMemDC1, hOldBmp1);
|
|
933
|
|
- ::SelectObject(hMemDC2, hOldBmp2);
|
|
934
|
|
- } // if
|
|
935
|
|
-
|
|
936
|
|
- ::DeleteDC(hMemDC1);
|
|
937
|
|
- ::DeleteDC(hMemDC2);
|
|
938
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
939
|
|
-
|
|
940
|
|
- return hGrayBitmap;
|
|
941
|
|
-} // End of CreateGrayscaleBitmap
|
|
942
|
|
-
|
|
943
|
|
-// This function creates a bitmap that is 25% darker than the original.
|
|
944
|
|
-// The resulting bitmap will have the same size of the original one.
|
|
945
|
|
-//
|
|
946
|
|
-// Parameters:
|
|
947
|
|
-// [IN] hBitmap
|
|
948
|
|
-// Handle to the original bitmap.
|
|
949
|
|
-// [IN] dwWidth
|
|
950
|
|
-// Specifies the bitmap width, in pixels.
|
|
951
|
|
-// [IN] dwHeight
|
|
952
|
|
-// Specifies the bitmap height, in pixels.
|
|
953
|
|
-// [IN] crTrans
|
|
954
|
|
-// Color to be used as transparent color. This color will be left unchanged.
|
|
955
|
|
-//
|
|
956
|
|
-// Return value:
|
|
957
|
|
-// If the function succeeds, the return value is the handle to the newly created
|
|
958
|
|
-// darker bitmap.
|
|
959
|
|
-// If the function fails, the return value is NULL.
|
|
960
|
|
-//
|
|
961
|
|
-HBITMAP CButtonST::CreateDarkerBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans)
|
|
962
|
|
-{
|
|
963
|
|
- HBITMAP hGrayBitmap = NULL;
|
|
964
|
|
- HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;
|
|
965
|
|
- HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;
|
|
966
|
|
-
|
|
967
|
|
- hMainDC = ::GetDC(NULL);
|
|
968
|
|
- if (hMainDC == NULL) return NULL;
|
|
969
|
|
- hMemDC1 = ::CreateCompatibleDC(hMainDC);
|
|
970
|
|
- if (hMemDC1 == NULL)
|
|
971
|
|
- {
|
|
972
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
973
|
|
- return NULL;
|
|
974
|
|
- } // if
|
|
975
|
|
- hMemDC2 = ::CreateCompatibleDC(hMainDC);
|
|
976
|
|
- if (hMemDC2 == NULL)
|
|
977
|
|
- {
|
|
978
|
|
- ::DeleteDC(hMemDC1);
|
|
979
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
980
|
|
- return NULL;
|
|
981
|
|
- } // if
|
|
982
|
|
-
|
|
983
|
|
- hGrayBitmap = ::CreateCompatibleBitmap(hMainDC, dwWidth, dwHeight);
|
|
984
|
|
- if (hGrayBitmap)
|
|
985
|
|
- {
|
|
986
|
|
- hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, hGrayBitmap);
|
|
987
|
|
- hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, hBitmap);
|
|
988
|
|
-
|
|
989
|
|
- //::BitBlt(hMemDC1, 0, 0, dwWidth, dwHeight, hMemDC2, 0, 0, SRCCOPY);
|
|
990
|
|
-
|
|
991
|
|
- DWORD dwLoopY = 0, dwLoopX = 0;
|
|
992
|
|
- COLORREF crPixel = 0;
|
|
993
|
|
-
|
|
994
|
|
- for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)
|
|
995
|
|
- {
|
|
996
|
|
- for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)
|
|
997
|
|
- {
|
|
998
|
|
- crPixel = ::GetPixel(hMemDC2, dwLoopX, dwLoopY);
|
|
999
|
|
-
|
|
1000
|
|
- if (crPixel != crTrans)
|
|
1001
|
|
- ::SetPixel(hMemDC1, dwLoopX, dwLoopY, DarkenColor(crPixel, 0.25));
|
|
1002
|
|
- else
|
|
1003
|
|
- ::SetPixel(hMemDC1, dwLoopX, dwLoopY, crPixel);
|
|
1004
|
|
- } // for
|
|
1005
|
|
- } // for
|
|
1006
|
|
-
|
|
1007
|
|
- ::SelectObject(hMemDC1, hOldBmp1);
|
|
1008
|
|
- ::SelectObject(hMemDC2, hOldBmp2);
|
|
1009
|
|
- } // if
|
|
1010
|
|
-
|
|
1011
|
|
- ::DeleteDC(hMemDC1);
|
|
1012
|
|
- ::DeleteDC(hMemDC2);
|
|
1013
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
1014
|
|
-
|
|
1015
|
|
- return hGrayBitmap;
|
|
1016
|
|
-} // End of CreateDarkerBitmap
|
|
1017
|
|
-
|
|
1018
|
|
-// This function creates a grayscale icon starting from a given icon.
|
|
1019
|
|
-// The resulting icon will have the same size of the original one.
|
|
1020
|
|
-//
|
|
1021
|
|
-// Parameters:
|
|
1022
|
|
-// [IN] hIcon
|
|
1023
|
|
-// Handle to the original icon.
|
|
1024
|
|
-//
|
|
1025
|
|
-// Return value:
|
|
1026
|
|
-// If the function succeeds, the return value is the handle to the newly created
|
|
1027
|
|
-// grayscale icon.
|
|
1028
|
|
-// If the function fails, the return value is NULL.
|
|
1029
|
|
-//
|
|
1030
|
|
-// Updates:
|
|
1031
|
|
-// 26/Nov/2002 Restored 1 BitBlt operation
|
|
1032
|
|
-// 03/May/2002 Removed dependancy from m_hWnd
|
|
1033
|
|
-// Removed 1 BitBlt operation
|
|
1034
|
|
-//
|
|
1035
|
|
-HICON CButtonST::CreateGrayscaleIcon(HICON hIcon)
|
|
1036
|
|
-{
|
|
1037
|
|
- HICON hGrayIcon = NULL;
|
|
1038
|
|
- HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;
|
|
1039
|
|
- BITMAP bmp;
|
|
1040
|
|
- HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;
|
|
1041
|
|
- ICONINFO csII, csGrayII;
|
|
1042
|
|
- BOOL bRetValue = FALSE;
|
|
1043
|
|
-
|
|
1044
|
|
- bRetValue = ::GetIconInfo(hIcon, &csII);
|
|
1045
|
|
- if (bRetValue == FALSE) return NULL;
|
|
1046
|
|
-
|
|
1047
|
|
- hMainDC = ::GetDC(NULL);
|
|
1048
|
|
- hMemDC1 = ::CreateCompatibleDC(hMainDC);
|
|
1049
|
|
- hMemDC2 = ::CreateCompatibleDC(hMainDC);
|
|
1050
|
|
- if (hMainDC == NULL || hMemDC1 == NULL || hMemDC2 == NULL) return NULL;
|
|
1051
|
|
-
|
|
1052
|
|
- if (::GetObject(csII.hbmColor, sizeof(BITMAP), &bmp))
|
|
1053
|
|
- {
|
|
1054
|
|
- DWORD dwWidth = csII.xHotspot*2;
|
|
1055
|
|
- DWORD dwHeight = csII.yHotspot*2;
|
|
1056
|
|
-
|
|
1057
|
|
- csGrayII.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
|
|
1058
|
|
- if (csGrayII.hbmColor)
|
|
1059
|
|
- {
|
|
1060
|
|
- hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, csII.hbmColor);
|
|
1061
|
|
- hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, csGrayII.hbmColor);
|
|
1062
|
|
-
|
|
1063
|
|
- //::BitBlt(hMemDC2, 0, 0, dwWidth, dwHeight, hMemDC1, 0, 0, SRCCOPY);
|
|
1064
|
|
-
|
|
1065
|
|
- DWORD dwLoopY = 0, dwLoopX = 0;
|
|
1066
|
|
- COLORREF crPixel = 0;
|
|
1067
|
|
- BYTE byNewPixel = 0;
|
|
1068
|
|
-
|
|
1069
|
|
- for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)
|
|
1070
|
|
- {
|
|
1071
|
|
- for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)
|
|
1072
|
|
- {
|
|
1073
|
|
- crPixel = ::GetPixel(hMemDC1, dwLoopX, dwLoopY);
|
|
1074
|
|
- byNewPixel = (BYTE)((GetRValue(crPixel) * 0.299) + (GetGValue(crPixel) * 0.587) + (GetBValue(crPixel) * 0.114));
|
|
1075
|
|
-
|
|
1076
|
|
- if (crPixel)
|
|
1077
|
|
- ::SetPixel(hMemDC2, dwLoopX, dwLoopY, RGB(byNewPixel, byNewPixel, byNewPixel));
|
|
1078
|
|
- else
|
|
1079
|
|
- ::SetPixel(hMemDC2, dwLoopX, dwLoopY, crPixel);
|
|
1080
|
|
- } // for
|
|
1081
|
|
- } // for
|
|
1082
|
|
-
|
|
1083
|
|
- ::SelectObject(hMemDC1, hOldBmp1);
|
|
1084
|
|
- ::SelectObject(hMemDC2, hOldBmp2);
|
|
1085
|
|
-
|
|
1086
|
|
- csGrayII.hbmMask = csII.hbmMask;
|
|
1087
|
|
-
|
|
1088
|
|
- csGrayII.fIcon = TRUE;
|
|
1089
|
|
- hGrayIcon = ::CreateIconIndirect(&csGrayII);
|
|
1090
|
|
- } // if
|
|
1091
|
|
-
|
|
1092
|
|
- ::DeleteObject(csGrayII.hbmColor);
|
|
1093
|
|
- //::DeleteObject(csGrayII.hbmMask);
|
|
1094
|
|
- } // if
|
|
1095
|
|
-
|
|
1096
|
|
- ::DeleteObject(csII.hbmColor);
|
|
1097
|
|
- ::DeleteObject(csII.hbmMask);
|
|
1098
|
|
- ::DeleteDC(hMemDC1);
|
|
1099
|
|
- ::DeleteDC(hMemDC2);
|
|
1100
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
1101
|
|
-
|
|
1102
|
|
- return hGrayIcon;
|
|
1103
|
|
-} // End of CreateGrayscaleIcon
|
|
1104
|
|
-
|
|
1105
|
|
-// This function creates a icon that is 25% darker than the original.
|
|
1106
|
|
-// The resulting icon will have the same size of the original one.
|
|
1107
|
|
-//
|
|
1108
|
|
-// Parameters:
|
|
1109
|
|
-// [IN] hIcon
|
|
1110
|
|
-// Handle to the original icon.
|
|
1111
|
|
-//
|
|
1112
|
|
-// Return value:
|
|
1113
|
|
-// If the function succeeds, the return value is the handle to the newly created
|
|
1114
|
|
-// darker icon.
|
|
1115
|
|
-// If the function fails, the return value is NULL.
|
|
1116
|
|
-//
|
|
1117
|
|
-HICON CButtonST::CreateDarkerIcon(HICON hIcon)
|
|
1118
|
|
-{
|
|
1119
|
|
- HICON hGrayIcon = NULL;
|
|
1120
|
|
- HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;
|
|
1121
|
|
- BITMAP bmp;
|
|
1122
|
|
- HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;
|
|
1123
|
|
- ICONINFO csII, csGrayII;
|
|
1124
|
|
- BOOL bRetValue = FALSE;
|
|
1125
|
|
-
|
|
1126
|
|
- bRetValue = ::GetIconInfo(hIcon, &csII);
|
|
1127
|
|
- if (bRetValue == FALSE) return NULL;
|
|
1128
|
|
-
|
|
1129
|
|
- hMainDC = ::GetDC(NULL);
|
|
1130
|
|
- hMemDC1 = ::CreateCompatibleDC(hMainDC);
|
|
1131
|
|
- hMemDC2 = ::CreateCompatibleDC(hMainDC);
|
|
1132
|
|
- if (hMainDC == NULL || hMemDC1 == NULL || hMemDC2 == NULL) return NULL;
|
|
1133
|
|
-
|
|
1134
|
|
- if (::GetObject(csII.hbmColor, sizeof(BITMAP), &bmp))
|
|
1135
|
|
- {
|
|
1136
|
|
- DWORD dwWidth = csII.xHotspot*2;
|
|
1137
|
|
- DWORD dwHeight = csII.yHotspot*2;
|
|
1138
|
|
-
|
|
1139
|
|
- csGrayII.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);
|
|
1140
|
|
- if (csGrayII.hbmColor)
|
|
1141
|
|
- {
|
|
1142
|
|
- hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, csII.hbmColor);
|
|
1143
|
|
- hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, csGrayII.hbmColor);
|
|
1144
|
|
-
|
|
1145
|
|
- //::BitBlt(hMemDC2, 0, 0, dwWidth, dwHeight, hMemDC1, 0, 0, SRCCOPY);
|
|
1146
|
|
-
|
|
1147
|
|
- DWORD dwLoopY = 0, dwLoopX = 0;
|
|
1148
|
|
- COLORREF crPixel = 0;
|
|
1149
|
|
-
|
|
1150
|
|
- for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)
|
|
1151
|
|
- {
|
|
1152
|
|
- for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)
|
|
1153
|
|
- {
|
|
1154
|
|
- crPixel = ::GetPixel(hMemDC1, dwLoopX, dwLoopY);
|
|
1155
|
|
-
|
|
1156
|
|
- if (crPixel)
|
|
1157
|
|
- ::SetPixel(hMemDC2, dwLoopX, dwLoopY, DarkenColor(crPixel, 0.25));
|
|
1158
|
|
- else
|
|
1159
|
|
- ::SetPixel(hMemDC2, dwLoopX, dwLoopY, crPixel);
|
|
1160
|
|
- } // for
|
|
1161
|
|
- } // for
|
|
1162
|
|
-
|
|
1163
|
|
- ::SelectObject(hMemDC1, hOldBmp1);
|
|
1164
|
|
- ::SelectObject(hMemDC2, hOldBmp2);
|
|
1165
|
|
-
|
|
1166
|
|
- csGrayII.hbmMask = csII.hbmMask;
|
|
1167
|
|
-
|
|
1168
|
|
- csGrayII.fIcon = TRUE;
|
|
1169
|
|
- hGrayIcon = ::CreateIconIndirect(&csGrayII);
|
|
1170
|
|
- } // if
|
|
1171
|
|
-
|
|
1172
|
|
- ::DeleteObject(csGrayII.hbmColor);
|
|
1173
|
|
- //::DeleteObject(csGrayII.hbmMask);
|
|
1174
|
|
- } // if
|
|
1175
|
|
-
|
|
1176
|
|
- ::DeleteObject(csII.hbmColor);
|
|
1177
|
|
- ::DeleteObject(csII.hbmMask);
|
|
1178
|
|
- ::DeleteDC(hMemDC1);
|
|
1179
|
|
- ::DeleteDC(hMemDC2);
|
|
1180
|
|
- ::ReleaseDC(NULL, hMainDC);
|
|
1181
|
|
-
|
|
1182
|
|
- return hGrayIcon;
|
|
1183
|
|
-} // End of CreateDarkerIcon
|
|
1184
|
|
-
|
|
1185
|
|
-COLORREF CButtonST::DarkenColor(COLORREF crColor, double dFactor)
|
|
1186
|
|
-{
|
|
1187
|
|
- if (dFactor > 0.0 && dFactor <= 1.0)
|
|
1188
|
|
- {
|
|
1189
|
|
- BYTE red,green,blue,lightred,lightgreen,lightblue;
|
|
1190
|
|
- red = GetRValue(crColor);
|
|
1191
|
|
- green = GetGValue(crColor);
|
|
1192
|
|
- blue = GetBValue(crColor);
|
|
1193
|
|
- lightred = (BYTE)(red-(dFactor * red));
|
|
1194
|
|
- lightgreen = (BYTE)(green-(dFactor * green));
|
|
1195
|
|
- lightblue = (BYTE)(blue-(dFactor * blue));
|
|
1196
|
|
- crColor = RGB(lightred,lightgreen,lightblue);
|
|
1197
|
|
- } // if
|
|
1198
|
|
-
|
|
1199
|
|
- return crColor;
|
|
1200
|
|
-} // End of DarkenColor
|
|
1201
|
|
-
|
|
1202
|
|
-// This function assigns icons to the button.
|
|
1203
|
|
-// Any previous icon or bitmap will be removed.
|
|
1204
|
|
-//
|
|
1205
|
|
-// Parameters:
|
|
1206
|
|
-// [IN] nIconIn
|
|
1207
|
|
-// ID number of the icon resource to show when the mouse is over the button.
|
|
1208
|
|
-// Pass NULL to remove any icon from the button.
|
|
1209
|
|
-// [IN] nCxDesiredIn
|
|
1210
|
|
-// Specifies the width, in pixels, of the icon to load.
|
|
1211
|
|
-// [IN] nCyDesiredIn
|
|
1212
|
|
-// Specifies the height, in pixels, of the icon to load.
|
|
1213
|
|
-// [IN] nIconOut
|
|
1214
|
|
-// ID number of the icon resource to show when the mouse is outside the button.
|
|
1215
|
|
-// Can be NULL.
|
|
1216
|
|
-// If this parameter is the special value BTNST_AUTO_GRAY (cast to int) the second
|
|
1217
|
|
-// icon will be automatically created starting from nIconIn and converted to grayscale.
|
|
1218
|
|
-// If this parameter is the special value BTNST_AUTO_DARKER (cast to int) the second
|
|
1219
|
|
-// icon will be automatically created 25% darker starting from nIconIn.
|
|
1220
|
|
-// [IN] nCxDesiredOut
|
|
1221
|
|
-// Specifies the width, in pixels, of the icon to load.
|
|
1222
|
|
-// [IN] nCyDesiredOut
|
|
1223
|
|
-// Specifies the height, in pixels, of the icon to load.
|
|
1224
|
|
-//
|
|
1225
|
|
-// Return value:
|
|
1226
|
|
-// BTNST_OK
|
|
1227
|
|
-// Function executed successfully.
|
|
1228
|
|
-// BTNST_INVALIDRESOURCE
|
|
1229
|
|
-// Failed loading the specified resource.
|
|
1230
|
|
-//
|
|
1231
|
|
-DWORD CButtonST::SetIcon(int nIconIn, int nCxDesiredIn, int nCyDesiredIn, int nIconOut, int nCxDesiredOut, int nCyDesiredOut)
|
|
1232
|
|
-{
|
|
1233
|
|
- HICON hIconIn = NULL;
|
|
1234
|
|
- HICON hIconOut = NULL;
|
|
1235
|
|
- HINSTANCE hInstResource = NULL;
|
|
1236
|
|
-
|
|
1237
|
|
- // Find correct resource handle
|
|
1238
|
|
- hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconIn), RT_GROUP_ICON);
|
|
1239
|
|
-
|
|
1240
|
|
- // Set icon when the mouse is IN the button
|
|
1241
|
|
- hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconIn), IMAGE_ICON, nCxDesiredIn, nCyDesiredIn, 0);
|
|
1242
|
|
-
|
|
1243
|
|
- // Set icon when the mouse is OUT the button
|
|
1244
|
|
- switch (nIconOut)
|
|
1245
|
|
- {
|
|
1246
|
|
- case NULL:
|
|
1247
|
|
- break;
|
|
1248
|
|
- case (int)BTNST_AUTO_GRAY:
|
|
1249
|
|
- hIconOut = BTNST_AUTO_GRAY;
|
|
1250
|
|
- break;
|
|
1251
|
|
- case (int)BTNST_AUTO_DARKER:
|
|
1252
|
|
- hIconOut = BTNST_AUTO_DARKER;
|
|
1253
|
|
- break;
|
|
1254
|
|
- default:
|
|
1255
|
|
- hIconOut = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOut), IMAGE_ICON, nCxDesiredOut, nCyDesiredOut, 0);
|
|
1256
|
|
- break;
|
|
1257
|
|
- } // switch
|
|
1258
|
|
-
|
|
1259
|
|
- return SetIcon(hIconIn, hIconOut);
|
|
1260
|
|
-} // End of SetIcon
|
|
1261
|
|
-
|
|
1262
|
|
-// This function assigns icons to the button.
|
|
1263
|
|
-// Any previous icon or bitmap will be removed.
|
|
1264
|
|
-//
|
|
1265
|
|
-// Parameters:
|
|
1266
|
|
-// [IN] nIconIn
|
|
1267
|
|
-// ID number of the icon resource to show when the mouse is over the button.
|
|
1268
|
|
-// Pass NULL to remove any icon from the button.
|
|
1269
|
|
-// [IN] nIconOut
|
|
1270
|
|
-// ID number of the icon resource to show when the mouse is outside the button.
|
|
1271
|
|
-// Can be NULL.
|
|
1272
|
|
-// If this parameter is the special value BTNST_AUTO_GRAY (cast to int) the second
|
|
1273
|
|
-// icon will be automatically created starting from nIconIn and converted to grayscale.
|
|
1274
|
|
-// If this parameter is the special value BTNST_AUTO_DARKER (cast to int) the second
|
|
1275
|
|
-// icon will be automatically created 25% darker starting from nIconIn.
|
|
1276
|
|
-//
|
|
1277
|
|
-// Return value:
|
|
1278
|
|
-// BTNST_OK
|
|
1279
|
|
-// Function executed successfully.
|
|
1280
|
|
-// BTNST_INVALIDRESOURCE
|
|
1281
|
|
-// Failed loading the specified resource.
|
|
1282
|
|
-//
|
|
1283
|
|
-DWORD CButtonST::SetIcon(int nIconIn, int nIconOut)
|
|
1284
|
|
-{
|
|
1285
|
|
- return SetIcon(nIconIn, 0, 0, nIconOut, 0, 0);
|
|
1286
|
|
-} // End of SetIcon
|
|
1287
|
|
-
|
|
1288
|
|
-// This function assigns icons to the button.
|
|
1289
|
|
-// Any previous icon or bitmap will be removed.
|
|
1290
|
|
-//
|
|
1291
|
|
-// Parameters:
|
|
1292
|
|
-// [IN] hIconIn
|
|
1293
|
|
-// Handle fo the icon to show when the mouse is over the button.
|
|
1294
|
|
-// Pass NULL to remove any icon from the button.
|
|
1295
|
|
-// [IN] hIconOut
|
|
1296
|
|
-// Handle to the icon to show when the mouse is outside the button.
|
|
1297
|
|
-// Can be NULL.
|
|
1298
|
|
-// If this parameter is the special value BTNST_AUTO_GRAY the second
|
|
1299
|
|
-// icon will be automatically created starting from hIconIn and converted to grayscale.
|
|
1300
|
|
-// If this parameter is the special value BTNST_AUTO_DARKER the second
|
|
1301
|
|
-// icon will be automatically created 25% darker starting from hIconIn.
|
|
1302
|
|
-//
|
|
1303
|
|
-// Return value:
|
|
1304
|
|
-// BTNST_OK
|
|
1305
|
|
-// Function executed successfully.
|
|
1306
|
|
-// BTNST_INVALIDRESOURCE
|
|
1307
|
|
-// Failed loading the specified resource.
|
|
1308
|
|
-//
|
|
1309
|
|
-DWORD CButtonST::SetIcon(HICON hIconIn, HICON hIconOut)
|
|
1310
|
|
-{
|
|
1311
|
|
- BOOL bRetValue;
|
|
1312
|
|
- ICONINFO ii;
|
|
1313
|
|
-
|
|
1314
|
|
- // Free any loaded resource
|
|
1315
|
|
- FreeResources();
|
|
1316
|
|
-
|
|
1317
|
|
- if (hIconIn)
|
|
1318
|
|
- {
|
|
1319
|
|
- // Icon when mouse over button?
|
|
1320
|
|
- m_csIcons[0].hIcon = hIconIn;
|
|
1321
|
|
- // Get icon dimension
|
|
1322
|
|
- ::ZeroMemory(&ii, sizeof(ICONINFO));
|
|
1323
|
|
- bRetValue = ::GetIconInfo(hIconIn, &ii);
|
|
1324
|
|
- if (bRetValue == FALSE)
|
|
1325
|
|
- {
|
|
1326
|
|
- FreeResources();
|
|
1327
|
|
- return BTNST_INVALIDRESOURCE;
|
|
1328
|
|
- } // if
|
|
1329
|
|
-
|
|
1330
|
|
- m_csIcons[0].dwWidth = (DWORD)(ii.xHotspot * 2);
|
|
1331
|
|
- m_csIcons[0].dwHeight = (DWORD)(ii.yHotspot * 2);
|
|
1332
|
|
- ::DeleteObject(ii.hbmMask);
|
|
1333
|
|
- ::DeleteObject(ii.hbmColor);
|
|
1334
|
|
-
|
|
1335
|
|
- // Icon when mouse outside button?
|
|
1336
|
|
- if (hIconOut)
|
|
1337
|
|
- {
|
|
1338
|
|
- switch ((int)hIconOut)
|
|
1339
|
|
- {
|
|
1340
|
|
- case (int)BTNST_AUTO_GRAY:
|
|
1341
|
|
- hIconOut = CreateGrayscaleIcon(hIconIn);
|
|
1342
|
|
- break;
|
|
1343
|
|
- case (int)BTNST_AUTO_DARKER:
|
|
1344
|
|
- hIconOut = CreateDarkerIcon(hIconIn);
|
|
1345
|
|
- break;
|
|
1346
|
|
- } // switch
|
|
1347
|
|
-
|
|
1348
|
|
- m_csIcons[1].hIcon = hIconOut;
|
|
1349
|
|
- // Get icon dimension
|
|
1350
|
|
- ::ZeroMemory(&ii, sizeof(ICONINFO));
|
|
1351
|
|
- bRetValue = ::GetIconInfo(hIconOut, &ii);
|
|
1352
|
|
- if (bRetValue == FALSE)
|
|
1353
|
|
- {
|
|
1354
|
|
- FreeResources();
|
|
1355
|
|
- return BTNST_INVALIDRESOURCE;
|
|
1356
|
|
- } // if
|
|
1357
|
|
-
|
|
1358
|
|
- m_csIcons[1].dwWidth = (DWORD)(ii.xHotspot * 2);
|
|
1359
|
|
- m_csIcons[1].dwHeight = (DWORD)(ii.yHotspot * 2);
|
|
1360
|
|
- ::DeleteObject(ii.hbmMask);
|
|
1361
|
|
- ::DeleteObject(ii.hbmColor);
|
|
1362
|
|
- } // if
|
|
1363
|
|
- } // if
|
|
1364
|
|
-
|
|
1365
|
|
- Invalidate();
|
|
1366
|
|
-
|
|
1367
|
|
- return BTNST_OK;
|
|
1368
|
|
-} // End of SetIcon
|
|
1369
|
|
-
|
|
1370
|
|
-// This function assigns bitmaps to the button.
|
|
1371
|
|
-// Any previous icon or bitmap will be removed.
|
|
1372
|
|
-//
|
|
1373
|
|
-// Parameters:
|
|
1374
|
|
-// [IN] nBitmapIn
|
|
1375
|
|
-// ID number of the bitmap resource to show when the mouse is over the button.
|
|
1376
|
|
-// Pass NULL to remove any bitmap from the button.
|
|
1377
|
|
-// [IN] crTransColorIn
|
|
1378
|
|
-// Color (inside nBitmapIn) to be used as transparent color.
|
|
1379
|
|
-// [IN] nBitmapOut
|
|
1380
|
|
-// ID number of the bitmap resource to show when the mouse is outside the button.
|
|
1381
|
|
-// Can be NULL.
|
|
1382
|
|
-// [IN] crTransColorOut
|
|
1383
|
|
-// Color (inside nBitmapOut) to be used as transparent color.
|
|
1384
|
|
-//
|
|
1385
|
|
-// Return value:
|
|
1386
|
|
-// BTNST_OK
|
|
1387
|
|
-// Function executed successfully.
|
|
1388
|
|
-// BTNST_INVALIDRESOURCE
|
|
1389
|
|
-// Failed loading the specified resource.
|
|
1390
|
|
-// BTNST_FAILEDMASK
|
|
1391
|
|
-// Failed creating mask bitmap.
|
|
1392
|
|
-//
|
|
1393
|
|
-DWORD CButtonST::SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut, COLORREF crTransColorOut)
|
|
1394
|
|
-{
|
|
1395
|
|
- HBITMAP hBitmapIn = NULL;
|
|
1396
|
|
- HBITMAP hBitmapOut = NULL;
|
|
1397
|
|
- HINSTANCE hInstResource = NULL;
|
|
1398
|
|
-
|
|
1399
|
|
- // Find correct resource handle
|
|
1400
|
|
- hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nBitmapIn), RT_BITMAP);
|
|
1401
|
|
-
|
|
1402
|
|
- // Load bitmap In
|
|
1403
|
|
- hBitmapIn = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapIn), IMAGE_BITMAP, 0, 0, 0);
|
|
1404
|
|
-
|
|
1405
|
|
- // Load bitmap Out
|
|
1406
|
|
- switch (nBitmapOut)
|
|
1407
|
|
- {
|
|
1408
|
|
- case NULL:
|
|
1409
|
|
- break;
|
|
1410
|
|
- case (int)BTNST_AUTO_GRAY:
|
|
1411
|
|
- hBitmapOut = (HBITMAP)BTNST_AUTO_GRAY;
|
|
1412
|
|
- break;
|
|
1413
|
|
- case (int)BTNST_AUTO_DARKER:
|
|
1414
|
|
- hBitmapOut = (HBITMAP)BTNST_AUTO_DARKER;
|
|
1415
|
|
- break;
|
|
1416
|
|
- default:
|
|
1417
|
|
- hBitmapOut = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapOut), IMAGE_BITMAP, 0, 0, 0);
|
|
1418
|
|
- break;
|
|
1419
|
|
- } // if
|
|
1420
|
|
-
|
|
1421
|
|
- return SetBitmaps(hBitmapIn, crTransColorIn, hBitmapOut, crTransColorOut);
|
|
1422
|
|
-} // End of SetBitmaps
|
|
1423
|
|
-
|
|
1424
|
|
-// This function assigns bitmaps to the button.
|
|
1425
|
|
-// Any previous icon or bitmap will be removed.
|
|
1426
|
|
-//
|
|
1427
|
|
-// Parameters:
|
|
1428
|
|
-// [IN] hBitmapIn
|
|
1429
|
|
-// Handle fo the bitmap to show when the mouse is over the button.
|
|
1430
|
|
-// Pass NULL to remove any bitmap from the button.
|
|
1431
|
|
-// [IN] crTransColorIn
|
|
1432
|
|
-// Color (inside hBitmapIn) to be used as transparent color.
|
|
1433
|
|
-// [IN] hBitmapOut
|
|
1434
|
|
-// Handle to the bitmap to show when the mouse is outside the button.
|
|
1435
|
|
-// Can be NULL.
|
|
1436
|
|
-// [IN] crTransColorOut
|
|
1437
|
|
-// Color (inside hBitmapOut) to be used as transparent color.
|
|
1438
|
|
-//
|
|
1439
|
|
-// Return value:
|
|
1440
|
|
-// BTNST_OK
|
|
1441
|
|
-// Function executed successfully.
|
|
1442
|
|
-// BTNST_INVALIDRESOURCE
|
|
1443
|
|
-// Failed loading the specified resource.
|
|
1444
|
|
-// BTNST_FAILEDMASK
|
|
1445
|
|
-// Failed creating mask bitmap.
|
|
1446
|
|
-//
|
|
1447
|
|
-DWORD CButtonST::SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut, COLORREF crTransColorOut)
|
|
1448
|
|
-{
|
|
1449
|
|
- int nRetValue = 0;
|
|
1450
|
|
- BITMAP csBitmapSize;
|
|
1451
|
|
-
|
|
1452
|
|
- // Free any loaded resource
|
|
1453
|
|
- FreeResources();
|
|
1454
|
|
-
|
|
1455
|
|
- if (hBitmapIn)
|
|
1456
|
|
- {
|
|
1457
|
|
- m_csBitmaps[0].hBitmap = hBitmapIn;
|
|
1458
|
|
- m_csBitmaps[0].crTransparent = crTransColorIn;
|
|
1459
|
|
- // Get bitmap size
|
|
1460
|
|
- nRetValue = ::GetObject(hBitmapIn, sizeof(csBitmapSize), &csBitmapSize);
|
|
1461
|
|
- if (nRetValue == 0)
|
|
1462
|
|
- {
|
|
1463
|
|
- FreeResources();
|
|
1464
|
|
- return BTNST_INVALIDRESOURCE;
|
|
1465
|
|
- } // if
|
|
1466
|
|
- m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth;
|
|
1467
|
|
- m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight;
|
|
1468
|
|
-
|
|
1469
|
|
- // Create grayscale/darker bitmap BEFORE mask (of hBitmapIn)
|
|
1470
|
|
- switch ((int)hBitmapOut)
|
|
1471
|
|
- {
|
|
1472
|
|
- case (int)BTNST_AUTO_GRAY:
|
|
1473
|
|
- hBitmapOut = CreateGrayscaleBitmap(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);
|
|
1474
|
|
- m_csBitmaps[1].hBitmap = hBitmapOut;
|
|
1475
|
|
- crTransColorOut = crTransColorIn;
|
|
1476
|
|
- break;
|
|
1477
|
|
- case (int)BTNST_AUTO_DARKER:
|
|
1478
|
|
- hBitmapOut = CreateDarkerBitmap(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);
|
|
1479
|
|
- m_csBitmaps[1].hBitmap = hBitmapOut;
|
|
1480
|
|
- crTransColorOut = crTransColorIn;
|
|
1481
|
|
- break;
|
|
1482
|
|
- } // switch
|
|
1483
|
|
-
|
|
1484
|
|
- // Create mask for bitmap In
|
|
1485
|
|
- m_csBitmaps[0].hMask = CreateBitmapMask(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);
|
|
1486
|
|
- if (m_csBitmaps[0].hMask == NULL)
|
|
1487
|
|
- {
|
|
1488
|
|
- FreeResources();
|
|
1489
|
|
- return BTNST_FAILEDMASK;
|
|
1490
|
|
- } // if
|
|
1491
|
|
-
|
|
1492
|
|
- if (hBitmapOut)
|
|
1493
|
|
- {
|
|
1494
|
|
- m_csBitmaps[1].hBitmap = hBitmapOut;
|
|
1495
|
|
- m_csBitmaps[1].crTransparent = crTransColorOut;
|
|
1496
|
|
- // Get bitmap size
|
|
1497
|
|
- nRetValue = ::GetObject(hBitmapOut, sizeof(csBitmapSize), &csBitmapSize);
|
|
1498
|
|
- if (nRetValue == 0)
|
|
1499
|
|
- {
|
|
1500
|
|
- FreeResources();
|
|
1501
|
|
- return BTNST_INVALIDRESOURCE;
|
|
1502
|
|
- } // if
|
|
1503
|
|
- m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth;
|
|
1504
|
|
- m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight;
|
|
1505
|
|
-
|
|
1506
|
|
- // Create mask for bitmap Out
|
|
1507
|
|
- m_csBitmaps[1].hMask = CreateBitmapMask(hBitmapOut, m_csBitmaps[1].dwWidth, m_csBitmaps[1].dwHeight, crTransColorOut);
|
|
1508
|
|
- if (m_csBitmaps[1].hMask == NULL)
|
|
1509
|
|
- {
|
|
1510
|
|
- FreeResources();
|
|
1511
|
|
- return BTNST_FAILEDMASK;
|
|
1512
|
|
- } // if
|
|
1513
|
|
- } // if
|
|
1514
|
|
- } // if
|
|
1515
|
|
-
|
|
1516
|
|
- Invalidate();
|
|
1517
|
|
-
|
|
1518
|
|
- return BTNST_OK;
|
|
1519
|
|
-} // End of SetBitmaps
|
|
1520
|
|
-
|
|
1521
|
|
-// This functions sets the button to have a standard or flat style.
|
|
1522
|
|
-//
|
|
1523
|
|
-// Parameters:
|
|
1524
|
|
-// [IN] bFlat
|
|
1525
|
|
-// If TRUE the button will have a flat style, else
|
|
1526
|
|
-// will have a standard style.
|
|
1527
|
|
-// By default, CButtonST buttons are flat.
|
|
1528
|
|
-// [IN] bRepaint
|
|
1529
|
|
-// If TRUE the control will be repainted.
|
|
1530
|
|
-//
|
|
1531
|
|
-// Return value:
|
|
1532
|
|
-// BTNST_OK
|
|
1533
|
|
-// Function executed successfully.
|
|
1534
|
|
-//
|
|
1535
|
|
-DWORD CButtonST::SetFlat(BOOL bFlat, BOOL bRepaint)
|
|
1536
|
|
-{
|
|
1537
|
|
- m_bIsFlat = bFlat;
|
|
1538
|
|
- if (bRepaint) Invalidate();
|
|
1539
|
|
-
|
|
1540
|
|
- return BTNST_OK;
|
|
1541
|
|
-} // End of SetFlat
|
|
1542
|
|
-
|
|
1543
|
|
-// This function sets the alignment type between icon/bitmap and text.
|
|
1544
|
|
-//
|
|
1545
|
|
-// Parameters:
|
|
1546
|
|
-// [IN] byAlign
|
|
1547
|
|
-// Alignment type. Can be one of the following values:
|
|
1548
|
|
-// ST_ALIGN_HORIZ Icon/bitmap on the left, text on the right
|
|
1549
|
|
-// ST_ALIGN_VERT Icon/bitmap on the top, text on the bottom
|
|
1550
|
|
-// ST_ALIGN_HORIZ_RIGHT Icon/bitmap on the right, text on the left
|
|
1551
|
|
-// ST_ALIGN_OVERLAP Icon/bitmap on the same space as text
|
|
1552
|
|
-// By default, CButtonST buttons have ST_ALIGN_HORIZ alignment.
|
|
1553
|
|
-// [IN] bRepaint
|
|
1554
|
|
-// If TRUE the control will be repainted.
|
|
1555
|
|
-//
|
|
1556
|
|
-// Return value:
|
|
1557
|
|
-// BTNST_OK
|
|
1558
|
|
-// Function executed successfully.
|
|
1559
|
|
-// BTNST_INVALIDALIGN
|
|
1560
|
|
-// Alignment type not supported.
|
|
1561
|
|
-//
|
|
1562
|
|
-DWORD CButtonST::SetAlign(BYTE byAlign, BOOL bRepaint)
|
|
1563
|
|
-{
|
|
1564
|
|
- switch (byAlign)
|
|
1565
|
|
- {
|
|
1566
|
|
- case ST_ALIGN_HORIZ:
|
|
1567
|
|
- case ST_ALIGN_HORIZ_RIGHT:
|
|
1568
|
|
- case ST_ALIGN_VERT:
|
|
1569
|
|
- case ST_ALIGN_OVERLAP:
|
|
1570
|
|
- m_byAlign = byAlign;
|
|
1571
|
|
- if (bRepaint) Invalidate();
|
|
1572
|
|
- return BTNST_OK;
|
|
1573
|
|
- break;
|
|
1574
|
|
- } // switch
|
|
1575
|
|
-
|
|
1576
|
|
- return BTNST_INVALIDALIGN;
|
|
1577
|
|
-} // End of SetAlign
|
|
1578
|
|
-
|
|
1579
|
|
-// This function sets the pressed style.
|
|
1580
|
|
-//
|
|
1581
|
|
-// Parameters:
|
|
1582
|
|
-// [IN] byStyle
|
|
1583
|
|
-// Pressed style. Can be one of the following values:
|
|
1584
|
|
-// BTNST_PRESSED_LEFTRIGHT Pressed style from left to right (as usual)
|
|
1585
|
|
-// BTNST_PRESSED_TOPBOTTOM Pressed style from top to bottom
|
|
1586
|
|
-// By default, CButtonST buttons have BTNST_PRESSED_LEFTRIGHT style.
|
|
1587
|
|
-// [IN] bRepaint
|
|
1588
|
|
-// If TRUE the control will be repainted.
|
|
1589
|
|
-//
|
|
1590
|
|
-// Return value:
|
|
1591
|
|
-// BTNST_OK
|
|
1592
|
|
-// Function executed successfully.
|
|
1593
|
|
-// BTNST_INVALIDPRESSEDSTYLE
|
|
1594
|
|
-// Pressed style not supported.
|
|
1595
|
|
-//
|
|
1596
|
|
-DWORD CButtonST::SetPressedStyle(BYTE byStyle, BOOL bRepaint)
|
|
1597
|
|
-{
|
|
1598
|
|
- switch (byStyle)
|
|
1599
|
|
- {
|
|
1600
|
|
- case BTNST_PRESSED_LEFTRIGHT:
|
|
1601
|
|
- m_ptPressedOffset.x = 1;
|
|
1602
|
|
- m_ptPressedOffset.y = 1;
|
|
1603
|
|
- break;
|
|
1604
|
|
- case BTNST_PRESSED_TOPBOTTOM:
|
|
1605
|
|
- m_ptPressedOffset.x = 0;
|
|
1606
|
|
- m_ptPressedOffset.y = 2;
|
|
1607
|
|
- break;
|
|
1608
|
|
- default:
|
|
1609
|
|
- return BTNST_INVALIDPRESSEDSTYLE;
|
|
1610
|
|
- } // switch
|
|
1611
|
|
-
|
|
1612
|
|
- if (bRepaint) Invalidate();
|
|
1613
|
|
-
|
|
1614
|
|
- return BTNST_OK;
|
|
1615
|
|
-} // End of SetPressedStyle
|
|
1616
|
|
-
|
|
1617
|
|
-// This function sets the state of the checkbox.
|
|
1618
|
|
-// If the button is not a checkbox, this function has no meaning.
|
|
1619
|
|
-//
|
|
1620
|
|
-// Parameters:
|
|
1621
|
|
-// [IN] nCheck
|
|
1622
|
|
-// 1 to check the checkbox.
|
|
1623
|
|
-// 0 to un-check the checkbox.
|
|
1624
|
|
-// [IN] bRepaint
|
|
1625
|
|
-// If TRUE the control will be repainted.
|
|
1626
|
|
-//
|
|
1627
|
|
-// Return value:
|
|
1628
|
|
-// BTNST_OK
|
|
1629
|
|
-// Function executed successfully.
|
|
1630
|
|
-//
|
|
1631
|
|
-DWORD CButtonST::SetCheck(int nCheck, BOOL bRepaint)
|
|
1632
|
|
-{
|
|
1633
|
|
- if (m_bIsCheckBox)
|
|
1634
|
|
- {
|
|
1635
|
|
- if (nCheck == 0) m_nCheck = 0;
|
|
1636
|
|
- else m_nCheck = 1;
|
|
1637
|
|
-
|
|
1638
|
|
- if (bRepaint) Invalidate();
|
|
1639
|
|
- } // if
|
|
1640
|
|
-
|
|
1641
|
|
- return BTNST_OK;
|
|
1642
|
|
-} // End of SetCheck
|
|
1643
|
|
-
|
|
1644
|
|
-// This function returns the current state of the checkbox.
|
|
1645
|
|
-// If the button is not a checkbox, this function has no meaning.
|
|
1646
|
|
-//
|
|
1647
|
|
-// Return value:
|
|
1648
|
|
-// The current state of the checkbox.
|
|
1649
|
|
-// 1 if checked.
|
|
1650
|
|
-// 0 if not checked or the button is not a checkbox.
|
|
1651
|
|
-//
|
|
1652
|
|
-int CButtonST::GetCheck()
|
|
1653
|
|
-{
|
|
1654
|
|
- return m_nCheck;
|
|
1655
|
|
-} // End of GetCheck
|
|
1656
|
|
-
|
|
1657
|
|
-// This function sets all colors to a default value.
|
|
1658
|
|
-//
|
|
1659
|
|
-// Parameters:
|
|
1660
|
|
-// [IN] bRepaint
|
|
1661
|
|
-// If TRUE the control will be repainted.
|
|
1662
|
|
-//
|
|
1663
|
|
-// Return value:
|
|
1664
|
|
-// BTNST_OK
|
|
1665
|
|
-// Function executed successfully.
|
|
1666
|
|
-//
|
|
1667
|
|
-DWORD CButtonST::SetDefaultColors(BOOL bRepaint)
|
|
1668
|
|
-{
|
|
1669
|
|
- m_crColors[BTNST_COLOR_BK_IN] = ::GetSysColor(COLOR_BTNFACE);
|
|
1670
|
|
- m_crColors[BTNST_COLOR_FG_IN] = ::GetSysColor(COLOR_BTNTEXT);
|
|
1671
|
|
- m_crColors[BTNST_COLOR_BK_OUT] = ::GetSysColor(COLOR_BTNFACE);
|
|
1672
|
|
- m_crColors[BTNST_COLOR_FG_OUT] = ::GetSysColor(COLOR_BTNTEXT);
|
|
1673
|
|
- m_crColors[BTNST_COLOR_BK_FOCUS] = ::GetSysColor(COLOR_BTNFACE);
|
|
1674
|
|
- m_crColors[BTNST_COLOR_FG_FOCUS] = ::GetSysColor(COLOR_BTNTEXT);
|
|
1675
|
|
-
|
|
1676
|
|
- if (bRepaint) Invalidate();
|
|
1677
|
|
-
|
|
1678
|
|
- return BTNST_OK;
|
|
1679
|
|
-} // End of SetDefaultColors
|
|
1680
|
|
-
|
|
1681
|
|
-// This function sets the color to use for a particular state.
|
|
1682
|
|
-//
|
|
1683
|
|
-// Parameters:
|
|
1684
|
|
-// [IN] byColorIndex
|
|
1685
|
|
-// Index of the color to set. Can be one of the following values:
|
|
1686
|
|
-// BTNST_COLOR_BK_IN Background color when mouse is over the button
|
|
1687
|
|
-// BTNST_COLOR_FG_IN Text color when mouse is over the button
|
|
1688
|
|
-// BTNST_COLOR_BK_OUT Background color when mouse is outside the button
|
|
1689
|
|
-// BTNST_COLOR_FG_OUT Text color when mouse is outside the button
|
|
1690
|
|
-// BTNST_COLOR_BK_FOCUS Background color when the button is focused
|
|
1691
|
|
-// BTNST_COLOR_FG_FOCUS Text color when the button is focused
|
|
1692
|
|
-// [IN] crColor
|
|
1693
|
|
-// New color.
|
|
1694
|
|
-// [IN] bRepaint
|
|
1695
|
|
-// If TRUE the control will be repainted.
|
|
1696
|
|
-//
|
|
1697
|
|
-// Return value:
|
|
1698
|
|
-// BTNST_OK
|
|
1699
|
|
-// Function executed successfully.
|
|
1700
|
|
-// BTNST_INVALIDINDEX
|
|
1701
|
|
-// Invalid color index.
|
|
1702
|
|
-//
|
|
1703
|
|
-DWORD CButtonST::SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint)
|
|
1704
|
|
-{
|
|
1705
|
|
- if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;
|
|
1706
|
|
-
|
|
1707
|
|
- // Set new color
|
|
1708
|
|
- m_crColors[byColorIndex] = crColor;
|
|
1709
|
|
-
|
|
1710
|
|
- if (bRepaint) Invalidate();
|
|
1711
|
|
-
|
|
1712
|
|
- return BTNST_OK;
|
|
1713
|
|
-} // End of SetColor
|
|
1714
|
|
-
|
|
1715
|
|
-// This functions returns the color used for a particular state.
|
|
1716
|
|
-//
|
|
1717
|
|
-// Parameters:
|
|
1718
|
|
-// [IN] byColorIndex
|
|
1719
|
|
-// Index of the color to get.
|
|
1720
|
|
-// See SetColor for the list of available colors.
|
|
1721
|
|
-// [OUT] crpColor
|
|
1722
|
|
-// A pointer to a COLORREF that will receive the color.
|
|
1723
|
|
-//
|
|
1724
|
|
-// Return value:
|
|
1725
|
|
-// BTNST_OK
|
|
1726
|
|
-// Function executed successfully.
|
|
1727
|
|
-// BTNST_INVALIDINDEX
|
|
1728
|
|
-// Invalid color index.
|
|
1729
|
|
-//
|
|
1730
|
|
-DWORD CButtonST::GetColor(BYTE byColorIndex, COLORREF* crpColor)
|
|
1731
|
|
-{
|
|
1732
|
|
- if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;
|
|
1733
|
|
-
|
|
1734
|
|
- // Get color
|
|
1735
|
|
- *crpColor = m_crColors[byColorIndex];
|
|
1736
|
|
-
|
|
1737
|
|
- return BTNST_OK;
|
|
1738
|
|
-} // End of GetColor
|
|
1739
|
|
-
|
|
1740
|
|
-// This function applies an offset to the RGB components of the specified color.
|
|
1741
|
|
-// This function can be seen as an easy way to make a color darker or lighter than
|
|
1742
|
|
-// its default value.
|
|
1743
|
|
-//
|
|
1744
|
|
-// Parameters:
|
|
1745
|
|
-// [IN] byColorIndex
|
|
1746
|
|
-// Index of the color to set.
|
|
1747
|
|
-// See SetColor for the list of available colors.
|
|
1748
|
|
-// [IN] shOffsetColor
|
|
1749
|
|
-// A short value indicating the offset to apply to the color.
|
|
1750
|
|
-// This value must be between -255 and 255.
|
|
1751
|
|
-// [IN] bRepaint
|
|
1752
|
|
-// If TRUE the control will be repainted.
|
|
1753
|
|
-//
|
|
1754
|
|
-// Return value:
|
|
1755
|
|
-// BTNST_OK
|
|
1756
|
|
-// Function executed successfully.
|
|
1757
|
|
-// BTNST_INVALIDINDEX
|
|
1758
|
|
-// Invalid color index.
|
|
1759
|
|
-// BTNST_BADPARAM
|
|
1760
|
|
-// The specified offset is out of range.
|
|
1761
|
|
-//
|
|
1762
|
|
-DWORD CButtonST::OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint)
|
|
1763
|
|
-{
|
|
1764
|
|
- BYTE byRed = 0;
|
|
1765
|
|
- BYTE byGreen = 0;
|
|
1766
|
|
- BYTE byBlue = 0;
|
|
1767
|
|
- short shOffsetR = shOffset;
|
|
1768
|
|
- short shOffsetG = shOffset;
|
|
1769
|
|
- short shOffsetB = shOffset;
|
|
1770
|
|
-
|
|
1771
|
|
- if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;
|
|
1772
|
|
- if (shOffset < -255 || shOffset > 255) return BTNST_BADPARAM;
|
|
1773
|
|
-
|
|
1774
|
|
- // Get RGB components of specified color
|
|
1775
|
|
- byRed = GetRValue(m_crColors[byColorIndex]);
|
|
1776
|
|
- byGreen = GetGValue(m_crColors[byColorIndex]);
|
|
1777
|
|
- byBlue = GetBValue(m_crColors[byColorIndex]);
|
|
1778
|
|
-
|
|
1779
|
|
- // Calculate max. allowed real offset
|
|
1780
|
|
- if (shOffset > 0)
|
|
1781
|
|
- {
|
|
1782
|
|
- if (byRed + shOffset > 255) shOffsetR = 255 - byRed;
|
|
1783
|
|
- if (byGreen + shOffset > 255) shOffsetG = 255 - byGreen;
|
|
1784
|
|
- if (byBlue + shOffset > 255) shOffsetB = 255 - byBlue;
|
|
1785
|
|
-
|
|
1786
|
|
- shOffset = min(min(shOffsetR, shOffsetG), shOffsetB);
|
|
1787
|
|
- } // if
|
|
1788
|
|
- else
|
|
1789
|
|
- {
|
|
1790
|
|
- if (byRed + shOffset < 0) shOffsetR = -byRed;
|
|
1791
|
|
- if (byGreen + shOffset < 0) shOffsetG = -byGreen;
|
|
1792
|
|
- if (byBlue + shOffset < 0) shOffsetB = -byBlue;
|
|
1793
|
|
-
|
|
1794
|
|
- shOffset = max(max(shOffsetR, shOffsetG), shOffsetB);
|
|
1795
|
|
- } // else
|
|
1796
|
|
-
|
|
1797
|
|
- // Set new color
|
|
1798
|
|
- m_crColors[byColorIndex] = RGB(byRed + shOffset, byGreen + shOffset, byBlue + shOffset);
|
|
1799
|
|
-
|
|
1800
|
|
- if (bRepaint) Invalidate();
|
|
1801
|
|
-
|
|
1802
|
|
- return BTNST_OK;
|
|
1803
|
|
-} // End of OffsetColor
|
|
1804
|
|
-
|
|
1805
|
|
-// This function sets the hilight logic for the button.
|
|
1806
|
|
-// Applies only to flat buttons.
|
|
1807
|
|
-//
|
|
1808
|
|
-// Parameters:
|
|
1809
|
|
-// [IN] bAlwaysTrack
|
|
1810
|
|
-// If TRUE the button will be hilighted even if the window that owns it, is
|
|
1811
|
|
-// not the active window.
|
|
1812
|
|
-// If FALSE the button will be hilighted only if the window that owns it,
|
|
1813
|
|
-// is the active window.
|
|
1814
|
|
-//
|
|
1815
|
|
-// Return value:
|
|
1816
|
|
-// BTNST_OK
|
|
1817
|
|
-// Function executed successfully.
|
|
1818
|
|
-//
|
|
1819
|
|
-DWORD CButtonST::SetAlwaysTrack(BOOL bAlwaysTrack)
|
|
1820
|
|
-{
|
|
1821
|
|
- m_bAlwaysTrack = bAlwaysTrack;
|
|
1822
|
|
- return BTNST_OK;
|
|
1823
|
|
-} // End of SetAlwaysTrack
|
|
1824
|
|
-
|
|
1825
|
|
-// This function sets the cursor to be used when the mouse is over the button.
|
|
1826
|
|
-//
|
|
1827
|
|
-// Parameters:
|
|
1828
|
|
-// [IN] nCursorId
|
|
1829
|
|
-// ID number of the cursor resource.
|
|
1830
|
|
-// Pass NULL to remove a previously loaded cursor.
|
|
1831
|
|
-// [IN] bRepaint
|
|
1832
|
|
-// If TRUE the control will be repainted.
|
|
1833
|
|
-//
|
|
1834
|
|
-// Return value:
|
|
1835
|
|
-// BTNST_OK
|
|
1836
|
|
-// Function executed successfully.
|
|
1837
|
|
-// BTNST_INVALIDRESOURCE
|
|
1838
|
|
-// Failed loading the specified resource.
|
|
1839
|
|
-//
|
|
1840
|
|
-DWORD CButtonST::SetBtnCursor(int nCursorId, BOOL bRepaint)
|
|
1841
|
|
-{
|
|
1842
|
|
- HINSTANCE hInstResource = NULL;
|
|
1843
|
|
- // Destroy any previous cursor
|
|
1844
|
|
- if (m_hCursor)
|
|
1845
|
|
- {
|
|
1846
|
|
- ::DestroyCursor(m_hCursor);
|
|
1847
|
|
- m_hCursor = NULL;
|
|
1848
|
|
- } // if
|
|
1849
|
|
-
|
|
1850
|
|
- // Load cursor
|
|
1851
|
|
- if (nCursorId)
|
|
1852
|
|
- {
|
|
1853
|
|
- hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR);
|
|
1854
|
|
- // Load cursor resource
|
|
1855
|
|
- m_hCursor = (HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
|
|
1856
|
|
- // Repaint the button
|
|
1857
|
|
- if (bRepaint) Invalidate();
|
|
1858
|
|
- // If something wrong
|
|
1859
|
|
- if (m_hCursor == NULL) return BTNST_INVALIDRESOURCE;
|
|
1860
|
|
- } // if
|
|
1861
|
|
-
|
|
1862
|
|
- return BTNST_OK;
|
|
1863
|
|
-} // End of SetBtnCursor
|
|
1864
|
|
-
|
|
1865
|
|
-// This function sets if the button border must be drawn.
|
|
1866
|
|
-// Applies only to flat buttons.
|
|
1867
|
|
-//
|
|
1868
|
|
-// Parameters:
|
|
1869
|
|
-// [IN] bDrawBorder
|
|
1870
|
|
-// If TRUE the border will be drawn.
|
|
1871
|
|
-// [IN] bRepaint
|
|
1872
|
|
-// If TRUE the control will be repainted.
|
|
1873
|
|
-//
|
|
1874
|
|
-// Return value:
|
|
1875
|
|
-// BTNST_OK
|
|
1876
|
|
-// Function executed successfully.
|
|
1877
|
|
-//
|
|
1878
|
|
-DWORD CButtonST::DrawBorder(BOOL bDrawBorder, BOOL bRepaint)
|
|
1879
|
|
-{
|
|
1880
|
|
- m_bDrawBorder = bDrawBorder;
|
|
1881
|
|
- // Repaint the button
|
|
1882
|
|
- if (bRepaint) Invalidate();
|
|
1883
|
|
-
|
|
1884
|
|
- return BTNST_OK;
|
|
1885
|
|
-} // End of DrawBorder
|
|
1886
|
|
-
|
|
1887
|
|
-// This function sets if the focus rectangle must be drawn for flat buttons.
|
|
1888
|
|
-//
|
|
1889
|
|
-// Parameters:
|
|
1890
|
|
-// [IN] bDrawFlatFocus
|
|
1891
|
|
-// If TRUE the focus rectangle will be drawn also for flat buttons.
|
|
1892
|
|
-// [IN] bRepaint
|
|
1893
|
|
-// If TRUE the control will be repainted.
|
|
1894
|
|
-//
|
|
1895
|
|
-// Return value:
|
|
1896
|
|
-// BTNST_OK
|
|
1897
|
|
-// Function executed successfully.
|
|
1898
|
|
-//
|
|
1899
|
|
-DWORD CButtonST::DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint)
|
|
1900
|
|
-{
|
|
1901
|
|
- m_bDrawFlatFocus = bDrawFlatFocus;
|
|
1902
|
|
- // Repaint the button
|
|
1903
|
|
- if (bRepaint) Invalidate();
|
|
1904
|
|
-
|
|
1905
|
|
- return BTNST_OK;
|
|
1906
|
|
-} // End of DrawFlatFocus
|
|
1907
|
|
-
|
|
1908
|
|
-void CButtonST::InitToolTip()
|
|
1909
|
|
-{
|
|
1910
|
|
- if (m_ToolTip.m_hWnd == NULL)
|
|
1911
|
|
- {
|
|
1912
|
|
- // Create ToolTip control
|
|
1913
|
|
- m_ToolTip.Create(this, m_dwToolTipStyle);
|
|
1914
|
|
- // Create inactive
|
|
1915
|
|
- m_ToolTip.Activate(FALSE);
|
|
1916
|
|
- // Enable multiline
|
|
1917
|
|
- m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400);
|
|
1918
|
|
- //m_ToolTip.SendMessage(TTM_SETTITLE, TTI_INFO, (LPARAM)_T("Title"));
|
|
1919
|
|
- } // if
|
|
1920
|
|
-} // End of InitToolTip
|
|
1921
|
|
-
|
|
1922
|
|
-// This function sets the text to show in the button tooltip.
|
|
1923
|
|
-//
|
|
1924
|
|
-// Parameters:
|
|
1925
|
|
-// [IN] nText
|
|
1926
|
|
-// ID number of the string resource containing the text to show.
|
|
1927
|
|
-// [IN] bActivate
|
|
1928
|
|
-// If TRUE the tooltip will be created active.
|
|
1929
|
|
-//
|
|
1930
|
|
-void CButtonST::SetTooltipText(int nText, BOOL bActivate)
|
|
1931
|
|
-{
|
|
1932
|
|
- CString sText;
|
|
1933
|
|
-
|
|
1934
|
|
- // Load string resource
|
|
1935
|
|
- sText.LoadString(nText);
|
|
1936
|
|
- // If string resource is not empty
|
|
1937
|
|
- if (sText.IsEmpty() == FALSE) SetTooltipText((LPCTSTR)sText, bActivate);
|
|
1938
|
|
-} // End of SetTooltipText
|
|
1939
|
|
-
|
|
1940
|
|
-// This function sets the text to show in the button tooltip.
|
|
1941
|
|
-//
|
|
1942
|
|
-// Parameters:
|
|
1943
|
|
-// [IN] lpszText
|
|
1944
|
|
-// Pointer to a null-terminated string containing the text to show.
|
|
1945
|
|
-// [IN] bActivate
|
|
1946
|
|
-// If TRUE the tooltip will be created active.
|
|
1947
|
|
-//
|
|
1948
|
|
-void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
|
|
1949
|
|
-{
|
|
1950
|
|
- // We cannot accept NULL pointer
|
|
1951
|
|
- if (lpszText == NULL) return;
|
|
1952
|
|
-
|
|
1953
|
|
- // Initialize ToolTip
|
|
1954
|
|
- InitToolTip();
|
|
1955
|
|
-
|
|
1956
|
|
- // If there is no tooltip defined then add it
|
|
1957
|
|
- if (m_ToolTip.GetToolCount() == 0)
|
|
1958
|
|
- {
|
|
1959
|
|
- CRect rectBtn;
|
|
1960
|
|
- GetClientRect(rectBtn);
|
|
1961
|
|
- m_ToolTip.AddTool(this, lpszText, rectBtn, 1);
|
|
1962
|
|
- } // if
|
|
1963
|
|
-
|
|
1964
|
|
- // Set text for tooltip
|
|
1965
|
|
- m_ToolTip.UpdateTipText(lpszText, this, 1);
|
|
1966
|
|
- m_ToolTip.Activate(bActivate);
|
|
1967
|
|
-} // End of SetTooltipText
|
|
1968
|
|
-
|
|
1969
|
|
-// This function enables or disables the button tooltip.
|
|
1970
|
|
-//
|
|
1971
|
|
-// Parameters:
|
|
1972
|
|
-// [IN] bActivate
|
|
1973
|
|
-// If TRUE the tooltip will be activated.
|
|
1974
|
|
-//
|
|
1975
|
|
-void CButtonST::ActivateTooltip(BOOL bActivate)
|
|
1976
|
|
-{
|
|
1977
|
|
- // If there is no tooltip then do nothing
|
|
1978
|
|
- if (m_ToolTip.GetToolCount() == 0) return;
|
|
1979
|
|
-
|
|
1980
|
|
- // Activate tooltip
|
|
1981
|
|
- m_ToolTip.Activate(bActivate);
|
|
1982
|
|
-} // End of EnableTooltip
|
|
1983
|
|
-
|
|
1984
|
|
-// This function enables the tooltip to be displayed using the balloon style.
|
|
1985
|
|
-// This function must be called before any call to SetTooltipText is made.
|
|
1986
|
|
-//
|
|
1987
|
|
-// Return value:
|
|
1988
|
|
-// BTNST_OK
|
|
1989
|
|
-// Function executed successfully.
|
|
1990
|
|
-//
|
|
1991
|
|
-DWORD CButtonST::EnableBalloonTooltip()
|
|
1992
|
|
-{
|
|
1993
|
|
- m_dwToolTipStyle |= TTS_BALLOON;
|
|
1994
|
|
- return BTNST_OK;
|
|
1995
|
|
-} // End of EnableBalloonTooltip
|
|
1996
|
|
-
|
|
1997
|
|
-// This function returns if the button is the default button.
|
|
1998
|
|
-//
|
|
1999
|
|
-// Return value:
|
|
2000
|
|
-// TRUE
|
|
2001
|
|
-// The button is the default button.
|
|
2002
|
|
-// FALSE
|
|
2003
|
|
-// The button is not the default button.
|
|
2004
|
|
-//
|
|
2005
|
|
-BOOL CButtonST::GetDefault()
|
|
2006
|
|
-{
|
|
2007
|
|
- return m_bIsDefault;
|
|
2008
|
|
-} // End of GetDefault
|
|
2009
|
|
-
|
|
2010
|
|
-// This function enables the transparent mode.
|
|
2011
|
|
-// Note: this operation is not reversible.
|
|
2012
|
|
-// DrawTransparent should be called just after the button is created.
|
|
2013
|
|
-// Do not use trasparent buttons until you really need it (you have a bitmapped
|
|
2014
|
|
-// background) since each transparent button makes a copy in memory of its background.
|
|
2015
|
|
-// This may bring unnecessary memory use and execution overload.
|
|
2016
|
|
-//
|
|
2017
|
|
-// Parameters:
|
|
2018
|
|
-// [IN] bRepaint
|
|
2019
|
|
-// If TRUE the control will be repainted.
|
|
2020
|
|
-//
|
|
2021
|
|
-void CButtonST::DrawTransparent(BOOL bRepaint)
|
|
2022
|
|
-{
|
|
2023
|
|
- m_bDrawTransparent = TRUE;
|
|
2024
|
|
-
|
|
2025
|
|
- // Restore old bitmap (if any)
|
|
2026
|
|
- if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
|
|
2027
|
|
- {
|
|
2028
|
|
- m_dcBk.SelectObject(m_pbmpOldBk);
|
|
2029
|
|
- } // if
|
|
2030
|
|
-
|
|
2031
|
|
- m_bmpBk.DeleteObject();
|
|
2032
|
|
- m_dcBk.DeleteDC();
|
|
2033
|
|
-
|
|
2034
|
|
- // Repaint the button
|
|
2035
|
|
- if (bRepaint) Invalidate();
|
|
2036
|
|
-} // End of DrawTransparent
|
|
2037
|
|
-
|
|
2038
|
|
-DWORD CButtonST::SetBk(CDC* pDC)
|
|
2039
|
|
-{
|
|
2040
|
|
- if (m_bDrawTransparent && pDC)
|
|
2041
|
|
- {
|
|
2042
|
|
- // Restore old bitmap (if any)
|
|
2043
|
|
- if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
|
|
2044
|
|
- {
|
|
2045
|
|
- m_dcBk.SelectObject(m_pbmpOldBk);
|
|
2046
|
|
- } // if
|
|
2047
|
|
-
|
|
2048
|
|
- m_bmpBk.DeleteObject();
|
|
2049
|
|
- m_dcBk.DeleteDC();
|
|
2050
|
|
-
|
|
2051
|
|
- CRect rect;
|
|
2052
|
|
- CRect rect1;
|
|
2053
|
|
-
|
|
2054
|
|
- GetClientRect(rect);
|
|
2055
|
|
-
|
|
2056
|
|
- GetWindowRect(rect1);
|
|
2057
|
|
- GetParent()->ScreenToClient(rect1);
|
|
2058
|
|
-
|
|
2059
|
|
- m_dcBk.CreateCompatibleDC(pDC);
|
|
2060
|
|
- m_bmpBk.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
|
|
2061
|
|
- m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);
|
|
2062
|
|
- m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, rect1.left, rect1.top, SRCCOPY);
|
|
2063
|
|
-
|
|
2064
|
|
- return BTNST_OK;
|
|
2065
|
|
- } // if
|
|
2066
|
|
-
|
|
2067
|
|
- return BTNST_BADPARAM;
|
|
2068
|
|
-} // End of SetBk
|
|
2069
|
|
-
|
|
2070
|
|
-// This function sets the URL that will be opened when the button is clicked.
|
|
2071
|
|
-//
|
|
2072
|
|
-// Parameters:
|
|
2073
|
|
-// [IN] lpszURL
|
|
2074
|
|
-// Pointer to a null-terminated string that contains the URL.
|
|
2075
|
|
-// Pass NULL to removed any previously specified URL.
|
|
2076
|
|
-//
|
|
2077
|
|
-// Return value:
|
|
2078
|
|
-// BTNST_OK
|
|
2079
|
|
-// Function executed successfully.
|
|
2080
|
|
-//
|
|
2081
|
|
-DWORD CButtonST::SetURL(LPCTSTR lpszURL)
|
|
2082
|
|
-{
|
|
2083
|
|
- // Remove any existing URL
|
|
2084
|
|
- memset(m_szURL, 0, sizeof(m_szURL));
|
|
2085
|
|
-
|
|
2086
|
|
- if (lpszURL)
|
|
2087
|
|
- {
|
|
2088
|
|
- // Store the URL
|
|
2089
|
|
- _tcsncpy(m_szURL, lpszURL, _MAX_PATH);
|
|
2090
|
|
- } // if
|
|
2091
|
|
-
|
|
2092
|
|
- return BTNST_OK;
|
|
2093
|
|
-} // End of SetURL
|
|
2094
|
|
-
|
|
2095
|
|
-// This function associates a menu to the button.
|
|
2096
|
|
-// The menu will be displayed clicking the button.
|
|
2097
|
|
-//
|
|
2098
|
|
-// Parameters:
|
|
2099
|
|
-// [IN] nMenu
|
|
2100
|
|
-// ID number of the menu resource.
|
|
2101
|
|
-// Pass NULL to remove any menu from the button.
|
|
2102
|
|
-// [IN] hParentWnd
|
|
2103
|
|
-// Handle to the window that owns the menu.
|
|
2104
|
|
-// This window receives all messages from the menu.
|
|
2105
|
|
-// [IN] bRepaint
|
|
2106
|
|
-// If TRUE the control will be repainted.
|
|
2107
|
|
-//
|
|
2108
|
|
-// Return value:
|
|
2109
|
|
-// BTNST_OK
|
|
2110
|
|
-// Function executed successfully.
|
|
2111
|
|
-// BTNST_INVALIDRESOURCE
|
|
2112
|
|
-// Failed loading the specified resource.
|
|
2113
|
|
-//
|
|
2114
|
|
-#ifndef BTNST_USE_BCMENU
|
|
2115
|
|
-DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint)
|
|
2116
|
|
-{
|
|
2117
|
|
- HINSTANCE hInstResource = NULL;
|
|
2118
|
|
-
|
|
2119
|
|
- // Destroy any previous menu
|
|
2120
|
|
- if (m_hMenu)
|
|
2121
|
|
- {
|
|
2122
|
|
- ::DestroyMenu(m_hMenu);
|
|
2123
|
|
- m_hMenu = NULL;
|
|
2124
|
|
- m_hParentWndMenu = NULL;
|
|
2125
|
|
- m_bMenuDisplayed = FALSE;
|
|
2126
|
|
- } // if
|
|
2127
|
|
-
|
|
2128
|
|
- // Load menu
|
|
2129
|
|
- if (nMenu)
|
|
2130
|
|
- {
|
|
2131
|
|
- // Find correct resource handle
|
|
2132
|
|
- hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nMenu), RT_MENU);
|
|
2133
|
|
- // Load menu resource
|
|
2134
|
|
- m_hMenu = ::LoadMenu(hInstResource, MAKEINTRESOURCE(nMenu));
|
|
2135
|
|
- m_hParentWndMenu = hParentWnd;
|
|
2136
|
|
- // If something wrong
|
|
2137
|
|
- if (m_hMenu == NULL) return BTNST_INVALIDRESOURCE;
|
|
2138
|
|
- } // if
|
|
2139
|
|
-
|
|
2140
|
|
- // Repaint the button
|
|
2141
|
|
- if (bRepaint) Invalidate();
|
|
2142
|
|
-
|
|
2143
|
|
- return BTNST_OK;
|
|
2144
|
|
-} // End of SetMenu
|
|
2145
|
|
-#endif
|
|
2146
|
|
-
|
|
2147
|
|
-// This function associates a menu to the button.
|
|
2148
|
|
-// The menu will be displayed clicking the button.
|
|
2149
|
|
-// The menu will be handled by the BCMenu class.
|
|
2150
|
|
-//
|
|
2151
|
|
-// Parameters:
|
|
2152
|
|
-// [IN] nMenu
|
|
2153
|
|
-// ID number of the menu resource.
|
|
2154
|
|
-// Pass NULL to remove any menu from the button.
|
|
2155
|
|
-// [IN] hParentWnd
|
|
2156
|
|
-// Handle to the window that owns the menu.
|
|
2157
|
|
-// This window receives all messages from the menu.
|
|
2158
|
|
-// [IN] bWinXPStyle
|
|
2159
|
|
-// If TRUE the menu will be displayed using the new Windows XP style.
|
|
2160
|
|
-// If FALSE the menu will be displayed using the standard style.
|
|
2161
|
|
-// [IN] nToolbarID
|
|
2162
|
|
-// Resource ID of the toolbar to be associated to the menu.
|
|
2163
|
|
-// [IN] sizeToolbarIcon
|
|
2164
|
|
-// A CSize object indicating the size (in pixels) of each icon into the toolbar.
|
|
2165
|
|
-// All icons into the toolbar must have the same size.
|
|
2166
|
|
-// [IN] crToolbarBk
|
|
2167
|
|
-// A COLORREF value indicating the color to use as background for the icons into the toolbar.
|
|
2168
|
|
-// This color will be used as the "transparent" color.
|
|
2169
|
|
-// [IN] bRepaint
|
|
2170
|
|
-// If TRUE the control will be repainted.
|
|
2171
|
|
-//
|
|
2172
|
|
-// Return value:
|
|
2173
|
|
-// BTNST_OK
|
|
2174
|
|
-// Function executed successfully.
|
|
2175
|
|
-// BTNST_INVALIDRESOURCE
|
|
2176
|
|
-// Failed loading the specified resource.
|
|
2177
|
|
-//
|
|
2178
|
|
-#ifdef BTNST_USE_BCMENU
|
|
2179
|
|
-DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle, UINT nToolbarID, CSize sizeToolbarIcon, COLORREF crToolbarBk, BOOL bRepaint)
|
|
2180
|
|
-{
|
|
2181
|
|
- BOOL bRetValue = FALSE;
|
|
2182
|
|
-
|
|
2183
|
|
- // Destroy any previous menu
|
|
2184
|
|
- if (m_menuPopup.m_hMenu)
|
|
2185
|
|
- {
|
|
2186
|
|
- m_menuPopup.DestroyMenu();
|
|
2187
|
|
- m_hParentWndMenu = NULL;
|
|
2188
|
|
- m_bMenuDisplayed = FALSE;
|
|
2189
|
|
- } // if
|
|
2190
|
|
-
|
|
2191
|
|
- // Load menu
|
|
2192
|
|
- if (nMenu)
|
|
2193
|
|
- {
|
|
2194
|
|
- m_menuPopup.SetMenuDrawMode(bWinXPStyle);
|
|
2195
|
|
- // Load menu
|
|
2196
|
|
- bRetValue = m_menuPopup.LoadMenu(nMenu);
|
|
2197
|
|
- // If something wrong
|
|
2198
|
|
- if (bRetValue == FALSE) return BTNST_INVALIDRESOURCE;
|
|
2199
|
|
-
|
|
2200
|
|
- // Load toolbar
|
|
2201
|
|
- if (nToolbarID)
|
|
2202
|
|
- {
|
|
2203
|
|
- m_menuPopup.SetBitmapBackground(crToolbarBk);
|
|
2204
|
|
- m_menuPopup.SetIconSize(sizeToolbarIcon.cx, sizeToolbarIcon.cy);
|
|
2205
|
|
-
|
|
2206
|
|
- bRetValue = m_menuPopup.LoadToolbar(nToolbarID);
|
|
2207
|
|
- // If something wrong
|
|
2208
|
|
- if (bRetValue == FALSE)
|
|
2209
|
|
- {
|
|
2210
|
|
- m_menuPopup.DestroyMenu();
|
|
2211
|
|
- return BTNST_INVALIDRESOURCE;
|
|
2212
|
|
- } // if
|
|
2213
|
|
- } // if
|
|
2214
|
|
-
|
|
2215
|
|
- m_hParentWndMenu = hParentWnd;
|
|
2216
|
|
- } // if
|
|
2217
|
|
-
|
|
2218
|
|
- // Repaint the button
|
|
2219
|
|
- if (bRepaint) Invalidate();
|
|
2220
|
|
-
|
|
2221
|
|
- return BTNST_OK;
|
|
2222
|
|
-} // End of SetMenu
|
|
2223
|
|
-#endif
|
|
2224
|
|
-
|
|
2225
|
|
-// This function sets the callback message that will be sent to the
|
|
2226
|
|
-// specified window just before the menu associated to the button is displayed.
|
|
2227
|
|
-//
|
|
2228
|
|
-// Parameters:
|
|
2229
|
|
-// [IN] hWnd
|
|
2230
|
|
-// Handle of the window that will receive the callback message.
|
|
2231
|
|
-// Pass NULL to remove any previously specified callback message.
|
|
2232
|
|
-// [IN] nMessage
|
|
2233
|
|
-// Callback message to send to window.
|
|
2234
|
|
-// [IN] lParam
|
|
2235
|
|
-// A 32 bits user specified value that will be passed to the callback function.
|
|
2236
|
|
-//
|
|
2237
|
|
-// Remarks:
|
|
2238
|
|
-// the callback function must be in the form:
|
|
2239
|
|
-// LRESULT On_MenuCallback(WPARAM wParam, LPARAM lParam)
|
|
2240
|
|
-// Where:
|
|
2241
|
|
-// [IN] wParam
|
|
2242
|
|
-// If support for BCMenu is enabled: a pointer to BCMenu
|
|
2243
|
|
-// else a HMENU handle to the menu that is being to be displayed.
|
|
2244
|
|
-// [IN] lParam
|
|
2245
|
|
-// The 32 bits user specified value.
|
|
2246
|
|
-//
|
|
2247
|
|
-// Return value:
|
|
2248
|
|
-// BTNST_OK
|
|
2249
|
|
-// Function executed successfully.
|
|
2250
|
|
-//
|
|
2251
|
|
-DWORD CButtonST::SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam)
|
|
2252
|
|
-{
|
|
2253
|
|
- m_csCallbacks.hWnd = hWnd;
|
|
2254
|
|
- m_csCallbacks.nMessage = nMessage;
|
|
2255
|
|
- m_csCallbacks.lParam = lParam;
|
|
2256
|
|
-
|
|
2257
|
|
- return BTNST_OK;
|
|
2258
|
|
-} // End of SetMenuCallback
|
|
2259
|
|
-
|
|
2260
|
|
-// This function resizes the button to the same size of the image.
|
|
2261
|
|
-// To get good results both the IN and OUT images should have the same size.
|
|
2262
|
|
-//
|
|
2263
|
|
-void CButtonST::SizeToContent()
|
|
2264
|
|
-{
|
|
2265
|
|
- if (m_csIcons[0].hIcon)
|
|
2266
|
|
- {
|
|
2267
|
|
- m_ptImageOrg.x = 0;
|
|
2268
|
|
- m_ptImageOrg.y = 0;
|
|
2269
|
|
- SetWindowPos( NULL, -1, -1, m_csIcons[0].dwWidth, m_csIcons[0].dwHeight,
|
|
2270
|
|
- SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
|
|
2271
|
|
- } // if
|
|
2272
|
|
- else
|
|
2273
|
|
- if (m_csBitmaps[0].hBitmap)
|
|
2274
|
|
- {
|
|
2275
|
|
- m_ptImageOrg.x = 0;
|
|
2276
|
|
- m_ptImageOrg.y = 0;
|
|
2277
|
|
- SetWindowPos( NULL, -1, -1, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight,
|
|
2278
|
|
- SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
|
|
2279
|
|
- } // if
|
|
2280
|
|
-} // End of SizeToContent
|
|
2281
|
|
-
|
|
2282
|
|
-// This function sets the sound that must be played on particular button states.
|
|
2283
|
|
-//
|
|
2284
|
|
-// Parameters:
|
|
2285
|
|
-// [IN] lpszSound
|
|
2286
|
|
-// A string that specifies the sound to play.
|
|
2287
|
|
-// If hMod is NULL this string is interpreted as a filename, else it
|
|
2288
|
|
-// is interpreted as a resource identifier.
|
|
2289
|
|
-// Pass NULL to remove any previously specified sound.
|
|
2290
|
|
-// [IN] hMod
|
|
2291
|
|
-// Handle to the executable file that contains the resource to be loaded.
|
|
2292
|
|
-// This parameter must be NULL unless lpszSound specifies a resource identifier.
|
|
2293
|
|
-// [IN] bPlayOnClick
|
|
2294
|
|
-// TRUE if the sound must be played when the button is clicked.
|
|
2295
|
|
-// FALSE if the sound must be played when the mouse is moved over the button.
|
|
2296
|
|
-// [IN] bPlayAsync
|
|
2297
|
|
-// TRUE if the sound must be played asynchronously.
|
|
2298
|
|
-// FALSE if the sound must be played synchronously. The application takes control
|
|
2299
|
|
-// when the sound is completely played.
|
|
2300
|
|
-//
|
|
2301
|
|
-// Return value:
|
|
2302
|
|
-// BTNST_OK
|
|
2303
|
|
-// Function executed successfully.
|
|
2304
|
|
-//
|
|
2305
|
|
-#ifdef BTNST_USE_SOUND
|
|
2306
|
|
-DWORD CButtonST::SetSound(LPCTSTR lpszSound, HMODULE hMod, BOOL bPlayOnClick, BOOL bPlayAsync)
|
|
2307
|
|
-{
|
|
2308
|
|
- BYTE byIndex = bPlayOnClick ? 1 : 0;
|
|
2309
|
|
-
|
|
2310
|
|
- // Store new sound
|
|
2311
|
|
- if (lpszSound)
|
|
2312
|
|
- {
|
|
2313
|
|
- if (hMod) // From resource identifier ?
|
|
2314
|
|
- {
|
|
2315
|
|
- m_csSounds[byIndex].lpszSound = lpszSound;
|
|
2316
|
|
- } // if
|
|
2317
|
|
- else
|
|
2318
|
|
- {
|
|
2319
|
|
- _tcscpy(m_csSounds[byIndex].szSound, lpszSound);
|
|
2320
|
|
- m_csSounds[byIndex].lpszSound = m_csSounds[byIndex].szSound;
|
|
2321
|
|
- } // else
|
|
2322
|
|
-
|
|
2323
|
|
- m_csSounds[byIndex].hMod = hMod;
|
|
2324
|
|
- m_csSounds[byIndex].dwFlags = SND_NODEFAULT | SND_NOWAIT;
|
|
2325
|
|
- m_csSounds[byIndex].dwFlags |= hMod ? SND_RESOURCE : SND_FILENAME;
|
|
2326
|
|
- m_csSounds[byIndex].dwFlags |= bPlayAsync ? SND_ASYNC : SND_SYNC;
|
|
2327
|
|
- } // if
|
|
2328
|
|
- else
|
|
2329
|
|
- {
|
|
2330
|
|
- // Or remove any existing
|
|
2331
|
|
- ::ZeroMemory(&m_csSounds[byIndex], sizeof(STRUCT_SOUND));
|
|
2332
|
|
- } // else
|
|
2333
|
|
-
|
|
2334
|
|
- return BTNST_OK;
|
|
2335
|
|
-} // End of SetSound
|
|
2336
|
|
-#endif
|
|
2337
|
|
-
|
|
2338
|
|
-// This function is called every time the button background needs to be painted.
|
|
2339
|
|
-// If the button is in transparent mode this function will NOT be called.
|
|
2340
|
|
-// This is a virtual function that can be rewritten in CButtonST-derived classes
|
|
2341
|
|
-// to produce a whole range of buttons not available by default.
|
|
2342
|
|
-//
|
|
2343
|
|
-// Parameters:
|
|
2344
|
|
-// [IN] pDC
|
|
2345
|
|
-// Pointer to a CDC object that indicates the device context.
|
|
2346
|
|
-// [IN] pRect
|
|
2347
|
|
-// Pointer to a CRect object that indicates the bounds of the
|
|
2348
|
|
-// area to be painted.
|
|
2349
|
|
-//
|
|
2350
|
|
-// Return value:
|
|
2351
|
|
-// BTNST_OK
|
|
2352
|
|
-// Function executed successfully.
|
|
2353
|
|
-//
|
|
2354
|
|
-DWORD CButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)
|
|
2355
|
|
-{
|
|
2356
|
|
- COLORREF crColor;
|
|
2357
|
|
-
|
|
2358
|
|
- if (m_bIsFlat == FALSE)
|
|
2359
|
|
- {
|
|
2360
|
|
- if (m_bIsFocused || m_bIsDefault)
|
|
2361
|
|
- {
|
|
2362
|
|
- CBrush br(RGB(0,0,0));
|
|
2363
|
|
- pDC->FrameRect(pRect, &br);
|
|
2364
|
|
- pRect->DeflateRect(1, 1);
|
|
2365
|
|
- } // if
|
|
2366
|
|
- } // if
|
|
2367
|
|
-
|
|
2368
|
|
- if (m_bMouseOnButton || m_bIsPressed)
|
|
2369
|
|
- crColor = m_crColors[BTNST_COLOR_BK_IN];
|
|
2370
|
|
- else
|
|
2371
|
|
- {
|
|
2372
|
|
- if (m_bIsFocused)
|
|
2373
|
|
- crColor = m_crColors[BTNST_COLOR_BK_FOCUS];
|
|
2374
|
|
- else
|
|
2375
|
|
- crColor = m_crColors[BTNST_COLOR_BK_OUT];
|
|
2376
|
|
- } // else
|
|
2377
|
|
-
|
|
2378
|
|
- CBrush brBackground(crColor);
|
|
2379
|
|
-
|
|
2380
|
|
- pDC->FillRect(pRect, &brBackground);
|
|
2381
|
|
-
|
|
2382
|
|
- return BTNST_OK;
|
|
2383
|
|
-} // End of OnDrawBackground
|
|
2384
|
|
-
|
|
2385
|
|
-// This function is called every time the button border needs to be painted.
|
|
2386
|
|
-// This is a virtual function that can be rewritten in CButtonST-derived classes
|
|
2387
|
|
-// to produce a whole range of buttons not available by default.
|
|
2388
|
|
-//
|
|
2389
|
|
-// Parameters:
|
|
2390
|
|
-// [IN] pDC
|
|
2391
|
|
-// Pointer to a CDC object that indicates the device context.
|
|
2392
|
|
-// [IN] pRect
|
|
2393
|
|
-// Pointer to a CRect object that indicates the bounds of the
|
|
2394
|
|
-// area to be painted.
|
|
2395
|
|
-//
|
|
2396
|
|
-// Return value:
|
|
2397
|
|
-// BTNST_OK
|
|
2398
|
|
-// Function executed successfully.
|
|
2399
|
|
-//
|
|
2400
|
|
-DWORD CButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
|
|
2401
|
|
-{
|
|
2402
|
|
- // Draw pressed button
|
|
2403
|
|
- if (m_bIsPressed)
|
|
2404
|
|
- {
|
|
2405
|
|
- if (m_bIsFlat)
|
|
2406
|
|
- {
|
|
2407
|
|
- if (m_bDrawBorder)
|
|
2408
|
|
- pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
|
|
2409
|
|
- }
|
|
2410
|
|
- else
|
|
2411
|
|
- {
|
|
2412
|
|
- CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
|
|
2413
|
|
- pDC->FrameRect(pRect, &brBtnShadow);
|
|
2414
|
|
- }
|
|
2415
|
|
- }
|
|
2416
|
|
- else // ...else draw non pressed button
|
|
2417
|
|
- {
|
|
2418
|
|
- CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
|
|
2419
|
|
- CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); // Light gray
|
|
2420
|
|
- CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Dark gray
|
|
2421
|
|
- CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black
|
|
2422
|
|
-
|
|
2423
|
|
- if (m_bIsFlat)
|
|
2424
|
|
- {
|
|
2425
|
|
- if (m_bMouseOnButton && m_bDrawBorder)
|
|
2426
|
|
- pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
|
|
2427
|
|
- }
|
|
2428
|
|
- else
|
|
2429
|
|
- {
|
|
2430
|
|
- // Draw top-left borders
|
|
2431
|
|
- // White line
|
|
2432
|
|
- CPen* pOldPen = pDC->SelectObject(&penBtnHiLight);
|
|
2433
|
|
- pDC->MoveTo(pRect->left, pRect->bottom-1);
|
|
2434
|
|
- pDC->LineTo(pRect->left, pRect->top);
|
|
2435
|
|
- pDC->LineTo(pRect->right, pRect->top);
|
|
2436
|
|
- // Light gray line
|
|
2437
|
|
- pDC->SelectObject(pen3DLight);
|
|
2438
|
|
- pDC->MoveTo(pRect->left+1, pRect->bottom-1);
|
|
2439
|
|
- pDC->LineTo(pRect->left+1, pRect->top+1);
|
|
2440
|
|
- pDC->LineTo(pRect->right, pRect->top+1);
|
|
2441
|
|
- // Draw bottom-right borders
|
|
2442
|
|
- // Black line
|
|
2443
|
|
- pDC->SelectObject(pen3DDKShadow);
|
|
2444
|
|
- pDC->MoveTo(pRect->left, pRect->bottom-1);
|
|
2445
|
|
- pDC->LineTo(pRect->right-1, pRect->bottom-1);
|
|
2446
|
|
- pDC->LineTo(pRect->right-1, pRect->top-1);
|
|
2447
|
|
- // Dark gray line
|
|
2448
|
|
- pDC->SelectObject(penBtnShadow);
|
|
2449
|
|
- pDC->MoveTo(pRect->left+1, pRect->bottom-2);
|
|
2450
|
|
- pDC->LineTo(pRect->right-2, pRect->bottom-2);
|
|
2451
|
|
- pDC->LineTo(pRect->right-2, pRect->top);
|
|
2452
|
|
- //
|
|
2453
|
|
- pDC->SelectObject(pOldPen);
|
|
2454
|
|
- } // else
|
|
2455
|
|
- } // else
|
|
2456
|
|
-
|
|
2457
|
|
- return BTNST_OK;
|
|
2458
|
|
-} // End of OnDrawBorder
|
|
2459
|
|
-
|
|
2460
|
|
-#undef BS_TYPEMASK |