-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextProgressCtrl.cpp
699 lines (600 loc) · 19.2 KB
/
TextProgressCtrl.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// TextProgressCtrl.cpp : implementation file
//
// Written by Chris Maunder ([email protected])
// Copyright 1998-2005.
//
// TextProgressCtrl is a drop-in replacement for the standard
// CProgressCtrl that displays text in a progress control.
//
// Homepage: http://www.codeproject.com/miscctrl/text_progressctrl.asp
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed by any means PROVIDING it is not sold for
// profit without the author's written consent, and providing that this
// notice and the author's name is included. If the source code in
// this file is used in any commercial application then an email to
// me would be nice.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage to your
// computer or anything else vaguely within its vicinity.
//
// Expect bugs.
//
// Please use and enjoy. Please let me know of any bugs/mods/improvements
// that you have found/implemented and I will fix/incorporate them into this
// file.
////////////////////////////////////////////////////////////////////////////////
// Revision History - by PJ Arends ([email protected])
// July 1, 2001 - added functionality to set font to parent windows font
// July 15, 2001 - added SetTextColor() and GetTextColor() functions
// August 2, 2001 - Added functionality where the control now responds to
// PBM_* progress bar messages. Now the control can be
// controlled by sending messages to its HWND.
// - added PBM_SETTEXTCOLOR and PBM_SETSHOWTEXT messages
// - added the ability to call GetPos() via OnGetPos()
// January 3, 2005 - By Kriz: Added two basic methods some other changes to
// allow the user to switch between the three alignment
// styles LEFT, CENTER and RIGHT - even on the fly if that's
// needed. Methods: AlignText and AlignTextInvalidate
// - By C Maunder: updated the code so it compiles in VC7
// March 6, 2006 - By A. Bommarito: changed to allow text in vertical
// progress bars; added method to change text background
// color; added capability to independently control display
// of text and percentage complete; added marquee mode;
// changed to exclusively use messaging interface
// February 22, 2007 - By A. Bommarito: changed to fix problem where progress bar
// border didn't display on XP and above when a manifest file
// specified use of Version 6 of the Common Controls; fixed
// problem with AppendFormat method being used without an
// _T() around the format string - caused compile error when
// using Unicode (message from dev75040); added complete turn
// off of Marquee style (message from Robert Pickford)
//
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TextProgressCtrl.h"
#include "CMemDC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef _MEMDC_H_
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: [email protected]
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// History - 10/3/97 Fixed scrolling bug.
// Added print support.
//
// This class implements a memory Device Context
class CMemDC : public CDC
{
public:
// constructor sets up the memory DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);
m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // Make a copy of the relevent parts of the current DC for printing
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}
// Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};
#endif
////////////////////////////////////////////////////////////////////////////////
// CTextProgressCtrl
#define IDT_MARQUEE 1 // timer used to update marquee style progress bar
#define EDGE_SPACE 2 // number of pixels to space text away from edge of progress bar
CTextProgressCtrl::CTextProgressCtrl()
{
// default range
m_nMin = 0;
m_nMax = 100;
// default step size
m_nStepSize = 10;
// initial starting position
m_nPos = 0;
// default colors
m_crBarClr = CLR_DEFAULT;
m_crBarBkClr = CLR_DEFAULT;
m_crTextClr = CLR_DEFAULT;
m_crTextBkClr = CLR_DEFAULT;
// default to show percent complete, all text centered
m_bShowPercent = TRUE;
m_dwTextStyle = DT_CENTER;
// default marquee bar size of 20% of full progress bar
m_nMarqueeSize = 20;
}
CTextProgressCtrl::~CTextProgressCtrl()
{
// delete vertical font if needed
if (m_VerticalFont.m_hObject)
m_VerticalFont.DeleteObject();
}
BEGIN_MESSAGE_MAP(CTextProgressCtrl, CProgressCtrl)
//{{AFX_MSG_MAP(CTextProgressCtrl)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
ON_MESSAGE(PBM_SETRANGE, OnSetRange)
ON_MESSAGE(PBM_SETPOS, OnSetPos)
ON_MESSAGE(PBM_DELTAPOS, OnOffsetPos)
ON_MESSAGE(PBM_SETSTEP, OnSetStep)
ON_MESSAGE(PBM_STEPIT, OnStepIt)
ON_MESSAGE(PBM_SETRANGE32, OnSetRange32)
ON_MESSAGE(PBM_GETRANGE, OnGetRange)
ON_MESSAGE(PBM_GETPOS, OnGetPos)
ON_MESSAGE(PBM_SETBARCOLOR, OnSetBarColor)
ON_MESSAGE(PBM_SETBKCOLOR, OnSetBarBkColor)
ON_MESSAGE(PBM_GETBARCOLOR, OnGetBarColor)
ON_MESSAGE(PBM_GETBKCOLOR, OnGetBarBkColor)
ON_MESSAGE(PBM_SETTEXTCOLOR, OnSetTextColor)
ON_MESSAGE(PBM_GETTEXTCOLOR, OnGetTextColor)
ON_MESSAGE(PBM_SETTEXTBKCOLOR, OnSetTextBkColor)
ON_MESSAGE(PBM_GETTEXTBKCOLOR, OnGetTextBkColor)
ON_MESSAGE(PBM_SETSHOWPERCENT, OnSetShowPercent)
ON_MESSAGE(PBM_ALIGNTEXT, OnAlignText)
ON_MESSAGE(PBM_SETMARQUEE, OnSetMarquee)
ON_MESSAGE(PBM_SETMARQUEEOPTIONS, OnSetMarqueeOptions)
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////////
// CTextProgressCtrl message handlers
BOOL CTextProgressCtrl::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}
void CTextProgressCtrl::OnPaint()
{
if (m_nMin >= m_nMax)
return;
CPaintDC PaintDC(this); // device context for painting
CMemDC dc(&PaintDC); // memory device context
// get colors to use
COLORREF crBarColor = (COLORREF)OnGetBarColor(0, 0);
COLORREF crBarBkColor = (COLORREF)OnGetBarBkColor(0, 0);
COLORREF crTextColor = (COLORREF)OnGetTextColor(0, 0);
COLORREF crTextBkColor = (COLORREF)OnGetTextBkColor(0, 0);;
// select progress bar font if there is one, else select parent font
if (GetFont())
dc.SelectObject(GetFont());
else
dc.SelectObject(GetParent()->GetFont());
// get bar dimensions and draw bar outline
BOOL bLeft = true, bMiddle = true, bRight = true;
CRect LeftRect, MiddleRect, RightRect, ClientRect;
GetClientRect(&ClientRect);
DrawEdge(dc, ClientRect, EDGE_SUNKEN, BF_ADJUST | BF_RECT | BF_FLAT);
LeftRect = MiddleRect = RightRect = ClientRect;
// compute the fractional position
double dFraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));
// get the control style
DWORD dwStyle = GetStyle();
// create a vertical font if needed
if ((dwStyle & PBS_VERTICAL) && (!m_VerticalFont.m_hObject))
CreateVerticalFont();
if (dwStyle & PBS_MARQUEE)
{
if (dwStyle & PBS_VERTICAL)
{
MiddleRect.top = MiddleRect.bottom - (int)((MiddleRect.Height()) * dFraction);
MiddleRect.bottom = MiddleRect.top + (((LeftRect.Height() * m_nMarqueeSize) + 50) / 100);
if (MiddleRect.bottom >= LeftRect.bottom)
{
bLeft = false;
MiddleRect.bottom = LeftRect.bottom;
}
else
LeftRect.top = MiddleRect.bottom;
if (MiddleRect.top <= RightRect.top)
{
bRight = false;
MiddleRect.top = RightRect.top;
}
else
RightRect.bottom = MiddleRect.top;
}
else
{
MiddleRect.right = MiddleRect.left + (int)((MiddleRect.Width()) * dFraction);
MiddleRect.left = MiddleRect.right - (((LeftRect.Width() * m_nMarqueeSize) + 50) / 100);
if (MiddleRect.left <= LeftRect.left)
{
bLeft = false;
MiddleRect.left = LeftRect.left;
}
else
LeftRect.right = MiddleRect.left;
if (MiddleRect.right >= RightRect.right)
{
bRight = false;
MiddleRect.right = RightRect.right;
}
else
RightRect.left = MiddleRect.right;
}
}
else
{
bLeft = false;
if (dwStyle & PBS_VERTICAL)
{
MiddleRect.top = MiddleRect.bottom - (int)((MiddleRect.Height()) * dFraction);
RightRect.bottom = MiddleRect.top;
}
else
{
MiddleRect.right = MiddleRect.left + (int)((MiddleRect.Width()) * dFraction);
RightRect.left = MiddleRect.right;
}
}
if (bLeft)
dc.FillSolidRect(LeftRect, crBarBkColor);
if (bMiddle)
dc.FillSolidRect(MiddleRect, crBarColor);
if (bRight)
dc.FillSolidRect(RightRect, crBarBkColor);
// draw text if needed
CString str;
GetWindowText(str);
if (m_bShowPercent)
{
//str.AppendFormat(_T("%d%%"), (int)((dFraction * 100.0) + 0.5));
CString str1;
str1.Format(_T(" %d%%"), (int)((dFraction * 100.0) + 0.5));
str += str1;
}
if (str.GetLength())
{
CFont *pOldFont = NULL;
CPoint ptStart;
CSize szText;
if (dwStyle & PBS_VERTICAL)
{
pOldFont = (CFont*)dc.SelectObject(&m_VerticalFont);
szText = dc.GetOutputTextExtent(str);
switch (m_dwTextStyle)
{
case DT_LEFT:
ptStart.y = ClientRect.bottom - 1 - EDGE_SPACE;
break;
case DT_RIGHT:
ptStart.y = ClientRect.top + szText.cx + EDGE_SPACE;
break;
case DT_CENTER:
default:
ptStart.y = ClientRect.top + szText.cx + (ClientRect.Height() - szText.cx) / 2;
break;
}
ptStart.x = ClientRect.left + ((ClientRect.Width() - szText.cy) / 2);
}
else
{
szText = dc.GetOutputTextExtent(str);
switch (m_dwTextStyle)
{
case DT_LEFT:
ptStart.x = ClientRect.left + EDGE_SPACE;
break;
case DT_RIGHT:
ptStart.x = ClientRect.right - szText.cx - 1 - EDGE_SPACE;
break;
case DT_CENTER:
default:
ptStart.x = ClientRect.left + ((ClientRect.Width() - szText.cx) / 2);
break;
}
ptStart.y = ClientRect.top + ((ClientRect.Height() - szText.cy) / 2);
}
dc.SetBkMode(TRANSPARENT);
CRgn rgn;
if (bLeft)
{
rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom);
dc.SelectClipRgn(&rgn);
dc.SetTextColor(crTextColor);
dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL);
rgn.DeleteObject();
}
if (bMiddle)
{
rgn.CreateRectRgn(MiddleRect.left, MiddleRect.top, MiddleRect.right, MiddleRect.bottom);
dc.SelectClipRgn(&rgn);
dc.SetTextColor(crTextBkColor);
dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL);
rgn.DeleteObject();
}
if (bRight)
{
rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom);
dc.SelectClipRgn(&rgn);
dc.SetTextColor(crTextColor);
dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL);
rgn.DeleteObject();
}
if (pOldFont)
dc.SelectObject(pOldFont);
}
}
void CTextProgressCtrl::OnTimer(UINT_PTR nIDEvent)
{
static int nDirection = +1;
if (nIDEvent == IDT_MARQUEE)
{
int nPosition = GetPos();
int nMax = (int)((((double)(100 + m_nMarqueeSize) * (double)m_nMax) + 0.5) / 100.0);
if ((nDirection == 1) && (nPosition >= nMax))
nDirection = -1;
else if ((nDirection == -1) && (nPosition <= m_nMin))
nDirection = +1;
SetPos(nPosition + nDirection);
}
}
LRESULT CTextProgressCtrl::OnSetRange(WPARAM, LPARAM lparamRange)
{
// set new 16-bit range, returning old one
return (OnSetRange32(LOWORD(lparamRange), HIWORD(lparamRange)));
}
LRESULT CTextProgressCtrl::OnSetPos(WPARAM nNewPos, LPARAM)
{
// save old position for return
int nOldPos = m_nPos;
// set new position
m_nPos = (int)nNewPos;
// limit position to inside of range
DWORD dwStyle = GetStyle();
if (m_nPos < m_nMin)
m_nPos = m_nMin;
if (dwStyle & PBS_MARQUEE)
{
int nMax = (int)((((double)(100 + m_nMarqueeSize) * (double)m_nMax) + 0.5) / 100.0);
if (m_nPos > nMax)
m_nPos = nMax;
}
else if (m_nPos > m_nMax)
m_nPos = m_nMax;
// call a common routine to redraw window
CommonPaint();
// return old position
return ((LRESULT)nOldPos);
}
LRESULT CTextProgressCtrl::OnOffsetPos(WPARAM nIncrement, LPARAM)
{
// set new position, returning old one
return (OnSetPos((WPARAM)(m_nPos + (int)nIncrement), 0));
}
LRESULT CTextProgressCtrl::OnSetStep(WPARAM nStepInc, LPARAM)
{
// save old step size for return
int nOldStep = m_nStepSize;
// set new step size
m_nStepSize = (int)nStepInc;
// return old step size
return ((LRESULT)nOldStep);
}
LRESULT CTextProgressCtrl::OnStepIt(WPARAM, LPARAM)
{
// compute new position, wrapping if needed
int nPos = m_nPos + m_nStepSize;
if (nPos < m_nMin)
nPos = m_nMax - abs(m_nMin - nPos);
else if (nPos > m_nMax)
nPos = m_nMin + abs(nPos - m_nMax);
// set new position, returning old one
return ((LRESULT)OnSetPos((WPARAM)nPos, 0));
}
LRESULT CTextProgressCtrl::OnSetRange32(WPARAM nLowLim, LPARAM nHighLim)
{
// save old range for return
int nOldMin = m_nMin;
int nOldMax = m_nMax;
// set new range
m_nMin = (int)nLowLim;
m_nMax = (int)nHighLim;
// return old range (16 bit only)
return (MAKELRESULT(LOWORD(nOldMin), LOWORD(nOldMax)));
}
LRESULT CTextProgressCtrl::OnGetRange(WPARAM bWhichLimit, LPARAM pPBRange)
{
// get arguments into proper types
BOOL bType = (BOOL)bWhichLimit;
PPBRANGE pRange = (PPBRANGE)pPBRange;
// return both range limits if a pointer was provided
if (pRange)
{
pRange->iLow = m_nMin;
pRange->iHigh = m_nMax;
}
// return selected range limit
return ((LRESULT)(bType ? m_nMin : m_nMax));
}
LRESULT CTextProgressCtrl::OnGetPos(WPARAM, LPARAM)
{
// return current position
return ((LRESULT)m_nPos);
}
LRESULT CTextProgressCtrl::OnSetBarColor(WPARAM, LPARAM crBar)
{
// call a common routine to redraw window
CommonPaint();
// set new bar color, returning old one
COLORREF crOldBarClr = m_crBarClr;
m_crBarClr = (COLORREF)crBar;
return ((LRESULT)crOldBarClr);
}
LRESULT CTextProgressCtrl::OnSetBarBkColor(WPARAM, LPARAM crBarBk)
{
// call a common routine to redraw window
CommonPaint();
// set new bar background color, returning old one
COLORREF crOldBarBkClr = m_crBarBkClr;
m_crBarBkClr = (COLORREF)crBarBk;
return ((LRESULT)crOldBarBkClr);
}
LRESULT CTextProgressCtrl::OnGetBarColor(WPARAM, LPARAM)
{
// return current bar color
return ((LRESULT)((m_crBarClr == CLR_DEFAULT)? ::GetSysColor(COLOR_HIGHLIGHT) : m_crBarClr));
}
LRESULT CTextProgressCtrl::OnGetBarBkColor(WPARAM, LPARAM)
{
// return current bar background color
return ((LRESULT)((m_crBarBkClr == CLR_DEFAULT)? ::GetSysColor(COLOR_BTNFACE) : m_crBarBkClr));
}
LRESULT CTextProgressCtrl::OnSetTextColor(WPARAM, LPARAM crText)
{
// call a common routine to redraw window
CommonPaint();
// set new text color, returning old one
COLORREF crOldTextClr = m_crTextClr;
m_crTextClr = (COLORREF)crText;
return ((LRESULT)crOldTextClr);
}
LRESULT CTextProgressCtrl::OnGetTextColor(WPARAM, LPARAM)
{
// return current text color
return ((LRESULT)((m_crTextClr == CLR_DEFAULT ? ::GetSysColor(COLOR_WINDOWTEXT) : m_crTextClr)));
}
LRESULT CTextProgressCtrl::OnSetTextBkColor(WPARAM, LPARAM crTextBkClr)
{
// call a common routine to redraw window
CommonPaint();
// set new text background color, returning old one
COLORREF crOldTextBkClr = m_crTextBkClr;
m_crTextBkClr = (COLORREF)crTextBkClr;
return ((LRESULT)crOldTextBkClr);
}
LRESULT CTextProgressCtrl::OnGetTextBkColor(WPARAM, LPARAM)
{
// return current text background color
return ((LRESULT)((m_crTextBkClr == CLR_DEFAULT ? ::GetSysColor(COLOR_WINDOW) : m_crTextBkClr)));
}
LRESULT CTextProgressCtrl::OnSetShowPercent(WPARAM bShow, LPARAM)
{
// call a common routine to redraw window
CommonPaint();
// set new percent completed display state, returning old one
BOOL bOldShow = m_bShowPercent;
m_bShowPercent = (BOOL)bShow;
return ((LRESULT)bOldShow);
}
LRESULT CTextProgressCtrl::OnAlignText(WPARAM dwAlignment, LPARAM)
{
// get argument into proper type
DWORD dwAlign = (DWORD)dwAlignment;
// check input
ASSERT((dwAlign == DT_LEFT) || (dwAlign == DT_RIGHT) || (dwAlign == DT_CENTER));
// call a common routine to redraw window
CommonPaint();
// set new text alignment mode, returning old one
DWORD dwOldTextStyle = m_dwTextStyle;
m_dwTextStyle = dwAlign;
return ((LRESULT)dwOldTextStyle);
}
LRESULT CTextProgressCtrl::OnSetMarquee(WPARAM bShow, LPARAM uMsecBetweenUpdate)
{
// call a common routine to redraw window
CommonPaint();
// can't have percent complete for this style
m_bShowPercent = false;
// turn marquee mode on or off
if ((BOOL)bShow)
{
ModifyStyle(0, PBS_MARQUEE);
SetTimer(IDT_MARQUEE, (UINT)uMsecBetweenUpdate, NULL);
}
else
{
KillTimer(IDT_MARQUEE);
ModifyStyle(PBS_MARQUEE, 0);
}
// return current marquee mode
return ((LRESULT)bShow);
}
LRESULT CTextProgressCtrl::OnSetMarqueeOptions(WPARAM nBarSize, LPARAM)
{
// get argument into proper type
int nBar = (int)nBarSize;
// call a common routine to redraw window
CommonPaint();
// set new marquee bar size
m_nMarqueeSize = nBar;
// return bar size (have to return something from a message)
return ((LRESULT)nBar);
}
////////////////////////////////////////////////////////////////////////////////
// CTextProgressCtrl helper functions
void CTextProgressCtrl::CreateVerticalFont()
{
// delete old font if it exists
if (m_VerticalFont.m_hObject)
m_VerticalFont.DeleteObject();
// create a new vertical font based on the current font
LOGFONT lf;
GetFont()->GetLogFont(&lf);
lf.lfEscapement = lf.lfOrientation = 900;
m_VerticalFont.CreateFontIndirect(&lf);
}
void CTextProgressCtrl::CommonPaint()
{
//
// common place to mess with redraw options
//
// note that Invalidate() by itself won't cause
// a repaint when this control is used in a modeless
// dialog box
//
// also note that the marquee timer won't work in a modeless
// dialog - to use marquee mode in a modeless dialog the code
// that is running will have to pump Windows messages
//
RedrawWindow();
}