-
Notifications
You must be signed in to change notification settings - Fork 0
/
HMXDialog.cpp
325 lines (254 loc) · 7.29 KB
/
HMXDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// HMXDialog.cpp : implementation file
//
/********************************************************************
created: 2001/10/25
file: HMXDialog
author: Massimo Colurcio
homepage: http://www.softhor.com/developmentarea
email: [email protected]
thanks to: an unknown programmer for bitmap drawing
purpose: want a dialog with background bitmap or color?
*********************************************************************/
#include "stdafx.h"
#include "HMXDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHMXDialog dialog
CHMXDialog::CHMXDialog()
{
CommonConstruct();
}
CHMXDialog::CHMXDialog(UINT uResource, CWnd* pParent /*=NULL*/)
: cdxCDynamicDialog(uResource, pParent)
{
CommonConstruct();
}
CHMXDialog::CHMXDialog(LPCTSTR pszResource, CWnd* pParent /*=NULL*/)
: cdxCDynamicDialog(pszResource, pParent)
{
CommonConstruct();
}
void CHMXDialog::CommonConstruct()
{
m_nType = BITMAP_TILE;
m_nBkGnd = BKGND_NONE;
}
void CHMXDialog::DoDataExchange(CDataExchange* pDX)
{
cdxCDynamicDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHMXDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
/********************************************************************
created: 2001/10/25
in: uResource, nType
out: none
return: true if success
purpose: set bitmap from resource
*********************************************************************/
bool CHMXDialog::SetBitmap(UINT uResource, int nType /*BITMAP_TILE*/)
{
bool bRet;
m_nType = nType;
m_nBkGnd = BKGND_IMAGE;
bRet = m_bmpBkGnd.LoadResource(uResource)?true:false;
Invalidate();
return bRet;
}
/********************************************************************
created: 2001/10/25
in: sFileName, nType
out: none
return: true if success
purpose: set bitmap from BMP file
*********************************************************************/
bool CHMXDialog::SetBitmap(const CString& sFileName, int nType /*BITMAP_TILE*/)
{
bool bRet;
m_nType = nType;
m_nBkGnd = BKGND_IMAGE;
bRet = m_bmpBkGnd.Load(sFileName)?true:false;
Invalidate();
return bRet;
}
/********************************************************************
created: 2001/10/25
in: clr
out: none
return: always true
purpose: set background color
*********************************************************************/
bool CHMXDialog::SetBkClr(COLORREF clr)
{
m_clrBkGnd = clr;
m_brsBkGnd.DeleteObject();
m_brsBkGnd.CreateSolidBrush(m_clrBkGnd);
m_nBkGnd = BKGND_COLOR;
Invalidate();
return true;
}
/********************************************************************
created: 2001/10/25
in: none
out: background color
return: none
purpose: get background color
*********************************************************************/
bool CHMXDialog::GetBkClr(COLORREF& clr)
{
clr = m_clrBkGnd;
return true;
}
BEGIN_MESSAGE_MAP(CHMXDialog, cdxCDynamicDialog)
//{{AFX_MSG_MAP(CHMXDialog)
ON_WM_ERASEBKGND()
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHMXDialog message handlers
/********************************************************************
created: 2001/10/25
in: pDC, see CWnd::OnEraseBkgnd
out: none
return: none
purpose: erase background painting with
color or background bitmap
*********************************************************************/
BOOL CHMXDialog::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
GetClientRect(rc);
int x = 0, y = 0;
BOOL bRet;
switch( m_nBkGnd ) {
case BKGND_NONE:
//
// no background
//
bRet = CDialog::OnEraseBkgnd(pDC);
break;
case BKGND_COLOR:
//
// color background
//
pDC->FillRect( &rc, &m_brsBkGnd);
bRet = TRUE;
break;
case BKGND_IMAGE:
//
// image background
//
if(m_bmpBkGnd.GetPixelPtr() != 0) {
switch(m_nType) {
case BITMAP_CENTER:
//
// center the bitmap
//
CDialog::OnEraseBkgnd(pDC);
x = (rc.Width() - m_bmpBkGnd.GetWidth()) / 2;
y = (rc.Height() - m_bmpBkGnd.GetHeight()) / 2;
m_bmpBkGnd.DrawDIB(pDC, x, y);
break;
case BITMAP_STRETCH:
//
// stretch bitmap so it will best fit to the dialog
//
m_bmpBkGnd.DrawDIB(pDC, 0, 0, rc.Width(), rc.Height());
break;
case BITMAP_TILE:
//
// tile the bitmap
//
while(y < rc.Height()) {
while(x < rc.Width()) {
m_bmpBkGnd.DrawDIB(pDC, x, y);
x += m_bmpBkGnd.GetWidth();
}
x = 0;
y += m_bmpBkGnd.GetHeight();
}
break;
default:
bRet = CDialog::OnEraseBkgnd(pDC);
break;
}
} else
// no bitmap set, behave like a normal dialog
bRet = cdxCDynamicDialog::OnEraseBkgnd(pDC);
break;
default:
bRet = cdxCDynamicDialog::OnEraseBkgnd(pDC);
break;
}
return bRet;
}
/********************************************************************
created: 2001/10/25
in: none
out: none
return: TRUE if success
purpose: handling palette changing
*********************************************************************/
BOOL CHMXDialog::OnQueryNewPalette()
{
CPalette * pPal = m_bmpBkGnd.GetPalette();
if( pPal != 0 && GetSafeHwnd() != 0 ) {
CClientDC dc(this);
CPalette * pOldPalette = dc.SelectPalette(pPal, FALSE);
UINT nChanged = dc.RealizePalette();
dc.SelectPalette(pOldPalette, TRUE);
if (nChanged == 0)
return FALSE;
Invalidate();
return TRUE;
}
return cdxCDynamicDialog::OnQueryNewPalette();
}
/********************************************************************
created: 2001/10/25
in: see CWnd::OnPaletteChanged
out: see CWnd::OnPaletteChanged
return: none
purpose: handling palette changing
*********************************************************************/
void CHMXDialog::OnPaletteChanged(CWnd* pFocusWnd)
{
CPalette * pPal = m_bmpBkGnd.GetPalette();
if( pPal != 0 && GetSafeHwnd() != 0 && pFocusWnd != this && ! IsChild(pFocusWnd) ) {
CClientDC dc(this);
CPalette * pOldPalette = dc.SelectPalette(pPal, TRUE);
UINT nChanged = dc.RealizePalette();
dc.SelectPalette(pOldPalette, TRUE);
if( nChanged )
Invalidate();
} else
cdxCDynamicDialog::OnPaletteChanged(pFocusWnd);
}
/********************************************************************
created: 2001/10/25
in: see CWnd::OnMouseMove
out: see CWnd::OnMouseMove
return: none
purpose: use this method to allow window movements dragging
the window clicking the entire client area
*********************************************************************/
void CHMXDialog::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//
// Special Thanks to "Jens Rahm" <[email protected]>
//
if( nFlags == MK_LBUTTON ) {
::ReleaseCapture();
SendMessage( WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
cdxCDynamicDialog::OnMouseMove(nFlags, point);
}