-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSizingDialog.cpp
More file actions
792 lines (650 loc) · 21.1 KB
/
CSizingDialog.cpp
File metadata and controls
792 lines (650 loc) · 21.1 KB
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
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
// CSizingDialog.cpp : implementation file
// (c)1998 Hans Bühler, codex design
// Designed to be used with MS VC++ 5.0
#include "stdafx.h"
#include "CSizingDialog.h"
#ifndef OBM_SIZE
#define OBM_SIZE 32766
// taken from WinresRc.h
// if not used for any reason
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Some static variables
/////////////////////////////////////////////////////////////////////////////
static LPCTSTR pfEntry_Left = _T("Left"),
pfEntry_Right = _T("Right"),
pfEntry_Top = _T("Top"),
pfEntry_Bottom = _T("Bottom"),
pfEntry_State = _T("State"),
pfEntry_IsDone = _T("(check)");
#define BAD_ID ((UINT)~0)
static struct cdxCSizingPropSheet::StandardControls psheetCtrls[] =
{
{ ID_WIZNEXT, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ ID_WIZFINISH, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ ID_WIZBACK, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ IDOK, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ IDCANCEL, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ ID_WIZNEXT, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ ID_APPLY_NOW, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ IDHELP, CSizingDialog::mdRepos,CSizingDialog::mdRepos },
{ AFX_IDC_TAB_CONTROL, CSizingDialog::mdResize,CSizingDialog::mdResize },
{ ID_WIZFINISH+1,CSizingDialog::mdResize,CSizingDialog::mdRepos}, /* the bevel line; hope that it will keep this id */
{ BAD_ID }
};
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog::ControlInfo::Header
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Functions for my windowos
/////////////////////////////////////////////////////////////////////////////
/*
* OnInitDialog()
* Gets initial sizes of the window and makes sizing icon
*/
BOOL CSizingDialog::ControlInfo::Header::OnInitDialog(UINT addSzByPcnt)
{
ASSERT(IsValid() && (m_iClientWid == -1));
CRect r;
WINDOWPLACEMENT wpl;
m_pWnd->GetClientRect(&r);
m_iClientWid = r.right - r.left;
m_iClientHi = r.bottom - r.top;
m_pWnd->GetWindowPlacement(&wpl);
m_iMinWid = wpl.rcNormalPosition.right - wpl.rcNormalPosition.left;
m_iMinHi = wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top;
// set up sizing icon
if(m_bSizeIcon)
{
if(!m_bmSizeIcon.LoadOEMBitmap(OBM_SIZE))
{
TRACE0(_T("*** ERROR[CSizingDialog::ControlInfo::Header::OnInitDialog()]: LoadOEMBitmap() failed.\n"));
m_bSizeIcon = false;
}
else
{
CRect szr(r.Width()-24,r.Height()-24,r.Width(),r.Height());
if(!m_wndSizeIcon.Create(NULL,WS_CHILD|SS_BITMAP,szr,m_pWnd) ||
!m_wndSizeIcon.ModifyStyleEx(0,WS_EX_TRANSPARENT) )
{
TRACE0(_T("*** ERROR[CSizingDialog::ControlInfo::Header::OnInitDialog()]: Can't create static icon control\n"));
m_bSizeIcon = false;
}
else
{
m_wndSizeIcon.SetBitmap(m_bmSizeIcon);
// now the icon has been resized to the real size of the icon
if(!m_wndSizeIcon.GetWindowPlacement(&wpl))
{
TRACE0(_T("*** ERROR[CSizingDialog::ControlInfo::Header::OnInitDialog()]: Can't get windowplacement for sizeicon.\n"));
m_bSizeIcon = false;
}
else
{
wpl.flags = 0;
wpl.rcNormalPosition.left = r.Width() - (wpl.rcNormalPosition.right - wpl.rcNormalPosition.left);
wpl.rcNormalPosition.right = r.Width();
wpl.rcNormalPosition.top = r.Height() - (wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top);
wpl.rcNormalPosition.bottom= r.Height();
if(!m_wndSizeIcon.SetWindowPlacement(&wpl))
{
TRACE0(_T("*** ERROR[CSizingDialog::ControlInfo::Header::OnInitDialog()]: Can't set windowplacement for sizeicon.\n"));
m_bSizeIcon = false;
}
else
{
AddSzControl(m_wndSizeIcon,mdRepos,mdRepos);
m_wndSizeIcon.ShowWindow(SW_SHOW); // finally - show it
}
}
}
}
}
if(addSzByPcnt)
StretchWindow(addSzByPcnt);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
/*
* OnSize() handler
* Call before base classes' handler
*/
void CSizingDialog::ControlInfo::Header::OnSize(UINT nType, int cx, int cy)
{
if((nType != SIZE_MINIMIZED) && (m_iClientWid != -1))
{
ASSERT((m_pWnd != NULL) && ::IsWindow(m_pWnd->m_hWnd));
ChangeSize(cx,cy);
}
}
/*
* tell system what minimum size we have
* call past original function
*/
void CSizingDialog::ControlInfo::Header::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
ASSERT(m_pWnd != NULL);
if(::IsWindow(m_pWnd->m_hWnd) && (m_iClientWid != -1))
{
lpMMI->ptMinTrackSize.x = m_iMinWid;
lpMMI->ptMinTrackSize.y = m_iMinHi;
if(!(m_Freedom & fdVert))
lpMMI->ptMaxTrackSize.y = m_iMinHi;
if(!(m_Freedom & fdHoriz))
lpMMI->ptMaxTrackSize.x = m_iMinWid;
}
}
/////////////////////////////////////////////////////////////////////////////
/*
* this _really_ sizes/positions the controls
* call RedrawWindow() afterwards !
*/
bool CSizingDialog::ControlInfo::Header::ChangeSize(int newWid, int newHi)
{
if(!IsValid() || (m_iClientWid == -1))
return false;
int deltaX = newWid - m_iClientWid,
deltaY = newHi - m_iClientHi;
bool ok = true;
if(deltaX < 0)
{
ok = false;
deltaX = 0;
}
if(deltaY < 0)
{
deltaY = 0;
ok = false;
}
for(ControlInfo *ci = m_pFirst; ci; ci = ci->GetNext())
ci->AdaptControlSize(deltaX,deltaY);
m_pWnd->RedrawWindow();
return ok;
}
/*
* force recalculation
*/
bool CSizingDialog::ControlInfo::Header::ReorganizeControls(void)
{
ASSERT(IsValid());
CRect r;
m_pWnd->GetClientRect(&r);
return ChangeSize(r.Width(), r.Height());
}
/*
* resize dialog in all available directions
*/
void CSizingDialog::ControlInfo::Header::StretchWindow(UINT addSzByPcnt)
{
ASSERT(IsValid());
int delta;
WINDOWPLACEMENT wpl;
if(!m_pWnd->GetWindowPlacement(&wpl))
{
#ifdef _DEBUG
CString s;m_pWnd->GetWindowText(s);
if(s.IsEmpty())
s.Format(_T("<Address_0x%lx"),(UINT)this);
TRACE1(_T("*** ERROR[CSizingDialog::ControlInfo::Header::StretchWindow()]: GetWindowPlacement() failed for dialog with caption \"%s\" !\n"),(LPCSTR)s);
#endif
return;
}
if(addSzByPcnt && (m_Freedom & fdHoriz))
{
delta = ((wpl.rcNormalPosition.right - wpl.rcNormalPosition.left) * addSzByPcnt) / (100/2);
if((wpl.rcNormalPosition.left -= delta) < 0)
wpl.rcNormalPosition.left = 0;
wpl.rcNormalPosition.right += delta;
}
if(addSzByPcnt && (m_Freedom & fdVert))
{
delta = ((wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top) * addSzByPcnt) / (100/2);
if((wpl.rcNormalPosition.top -= delta) < 0)
wpl.rcNormalPosition.top = 0;
wpl.rcNormalPosition.bottom += delta;
}
wpl.flags = 0;
m_pWnd->SetWindowPos(&wndBottom, wpl.rcNormalPosition.left,
wpl.rcNormalPosition.top,
wpl.rcNormalPosition.right - wpl.rcNormalPosition.left,
wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOREDRAW|SWP_NOZORDER);
}
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog::ControlInfo::Header utility functions: Sizing
/////////////////////////////////////////////////////////////////////////////
/*
* add a control that might be resized or repositioned
* (simple)
*/
CSizingDialog::ControlInfo *CSizingDialog::ControlInfo::Header::AddSzControl(CWnd & ctrl, Mode modeX, Mode modeY)
{
BYTE dX1pcnt = exIgnore,
dX2pcnt = exIgnore,
dY1pcnt = exIgnore,
dY2pcnt = exIgnore;
switch(modeX)
{
default : ASSERT(false);
case mdNone : break;
case mdRepos : dX1pcnt = dX2pcnt = exMaximum;
break;
case mdResize : dX2pcnt = exMaximum;
break;
case mdRelative: dX1pcnt = dX2pcnt = exMaximum / 2;
break;
}
switch(modeY)
{
default : ASSERT(false);
case mdNone : break;
case mdRepos : dY1pcnt = dY2pcnt = exMaximum;
break;
case mdResize : dY2pcnt = exMaximum;
break;
case mdRelative: dY1pcnt = dY2pcnt = exMaximum / 2;
break;
}
return AddSzControlEx(ctrl,dX1pcnt,dX2pcnt,dY1pcnt,dY2pcnt);
}
/*
* add a control that might be resized or repositioned
* (ex)
*/
CSizingDialog::ControlInfo *CSizingDialog::ControlInfo::Header::AddSzControlEx(CWnd & ctrl, BYTE dX1pcnt, BYTE dX2pcnt, BYTE dY1pcnt, BYTE dY2pcnt)
{
if(!IsValid() || !::IsWindow(ctrl.m_hWnd) || (m_iClientWid == -1))
{
ASSERT(m_iClientWid != -1); // call CSizingDialog::InitDialog() first !
ASSERT(::IsWindow(ctrl.m_hWnd)); // that's not a valid control !
return NULL;
}
if((dX1pcnt == exIgnore) && (dX2pcnt == exIgnore) &&
(dY1pcnt == exIgnore) && (dY2pcnt == exIgnore) )
{
#ifdef _DEBUG
CString s;ctrl.GetWindowText(s);
if(s.IsEmpty())
s.Format(_T("No caption; <Address_0x%lx"),(UINT)&ctrl);
TRACE1(_T("*** WARNING[CSizingDialog::ControlInfo::Header::AddSzControl()]: For control \"%s\", all modifcators are set to NONE (control will not be added).\n"),(LPCTSTR)s);
#endif
return NULL;
}
//
// check whether we have useful values;
// NOTE exMaximum == 100
//
ASSERT((dX1pcnt <= exMaximum) && (dX2pcnt <= exMaximum) && (dY1pcnt <= exMaximum) && (dY2pcnt <= exMaximum));
ControlInfo *ci;
if(!( ci = new ControlInfo(*this,ctrl,dX1pcnt,dX2pcnt,dY1pcnt,dY2pcnt) ))
{
ASSERT(false);
AfxThrowMemoryException();
}
CRect r;m_pWnd->GetClientRect(&r);
ci->AdaptControlSize(r.Width() - m_iClientWid,r.Height() - m_iClientHi);
return ci;
}
/////////////////////////////////////////////////////////////////////////////
// Additional utilities
/////////////////////////////////////////////////////////////////////////////
/*
* store window position to registry
*/
bool CSizingDialog::ControlInfo::Header::StoreWindowPosition(const CString & profileSec)
{
ASSERT(IsValid() && !profileSec.IsEmpty()); // can't use an empty profile section string; see CWinApp::GetProfileInt() for further information
if(m_iClientWid != -1)
{
WINDOWPLACEMENT wpl;
if(!m_pWnd->GetWindowPlacement(&wpl))
return false;
return AfxGetApp()->WriteProfileInt(profileSec, pfEntry_IsDone, ~const_IsDone) && // invalidate first
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_Left, wpl.rcNormalPosition.left) &&
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_Right, wpl.rcNormalPosition.right) &&
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_Top, wpl.rcNormalPosition.top) &&
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_Bottom, wpl.rcNormalPosition.bottom) &&
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_State, wpl.showCmd) &&
AfxGetApp()->WriteProfileInt(profileSec, pfEntry_IsDone, const_IsDone); // validate position
}
return false;
}
/*
* Load window position from registry
*/
bool CSizingDialog::ControlInfo::Header::RestoreWindowPosition(const CString & profileSec, bool withState)
{
ASSERT(IsValid() && !profileSec.IsEmpty()); // can't use an empty profile section string; see CWinApp::GetProfileInt() for further information
WINDOWPLACEMENT wpl;
bool ok;
if(!m_pWnd->GetWindowPlacement(&wpl))
{
#ifdef _DEBUG
CString s;m_pWnd->GetWindowText(s);
if(s.IsEmpty())
s.Format(_T("<Address_0x%lx"),(UINT)this);
TRACE1(_T("*** ERROR[CSizingDialog::ControlInfo::Header::RestoreWindowPosition()]: GetWindowPlacement() failed for dialog with caption \"%s\" !\n"),(LPCSTR)s);
#endif
return false;
}
//
// first, we check whether the position had been saved successful any time before
//
if( ok = (AfxGetApp()->GetProfileInt(profileSec,pfEntry_IsDone,0) == const_IsDone) )
{
// load previus session
wpl.rcNormalPosition.left = AfxGetApp()->GetProfileInt(profileSec, pfEntry_Left, wpl.rcNormalPosition.left);
wpl.rcNormalPosition.right = AfxGetApp()->GetProfileInt(profileSec, pfEntry_Right, wpl.rcNormalPosition.right);
wpl.rcNormalPosition.top = AfxGetApp()->GetProfileInt(profileSec, pfEntry_Top, wpl.rcNormalPosition.top);
wpl.rcNormalPosition.bottom = AfxGetApp()->GetProfileInt(profileSec, pfEntry_Bottom, wpl.rcNormalPosition.bottom);
wpl.showCmd = AfxGetApp()->GetProfileInt(profileSec, pfEntry_State, wpl.showCmd);
if(!withState)
wpl.showCmd = 0;
ok = m_pWnd->SetWindowPlacement(&wpl) != FALSE;
}
return ok;
}
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog::ControlInfo
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// construction
/////////////////////////////////////////////////////////////////////////////
/*
* class basics
*/
CSizingDialog::ControlInfo::ControlInfo(Header & hd, CWnd & wnd, BYTE dX1pcnt, BYTE dX2pcnt, BYTE dY1pcnt, BYTE dY2pcnt)
: m_rHeader(hd), m_Link(wnd), m_dX1pcnt(dX1pcnt), m_dX2pcnt(dX2pcnt), m_dY1pcnt(dY1pcnt), m_dY2pcnt(dY2pcnt)
{
WINDOWPLACEMENT wpl;
wnd.GetWindowPlacement(&wpl);
m_X1 = wpl.rcNormalPosition.left;
m_Y1 = wpl.rcNormalPosition.top;
m_X2 = wpl.rcNormalPosition.right;
m_Y2 = wpl.rcNormalPosition.bottom;
if(m_pNext = hd)
m_pNext->m_pPrev = this;
m_pPrev = NULL;
hd = this;
}
CSizingDialog::ControlInfo::~ControlInfo()
{
m_Link.Empty(); // delete all equal controls
if(!m_pPrev)
{
ASSERT( ((ControlInfo *)m_rHeader) == this); // should be mine :)
if(m_rHeader = m_pNext)
m_pNext->m_pPrev = NULL;
}
else
{
if(m_pPrev->m_pNext = m_pNext)
m_pNext->m_pPrev = m_pPrev;
}
}
/////////////////////////////////////////////////////////////////////////////
void CSizingDialog::ControlInfo::AddEqualCtrl(CWnd & ctrl)
{
if(!( new EqualCtrl(m_Link,ctrl) ))
{
ASSERT(false);
AfxThrowMemoryException();
}
}
/////////////////////////////////////////////////////////////////////////////
// do something :)
/////////////////////////////////////////////////////////////////////////////
/*
* action
*/
void CSizingDialog::ControlInfo::AdaptControlSize(register int deltaX, register int deltaY)
{
ASSERT((deltaX >= 0) && (deltaY >= 0));
register int x1,y1,x2,y2,i;
// NOTE: Resizing is even needed if both values are zero
// (to resize the controls to their default position)
x1 = m_X1;
y1 = m_Y1;
x2 = m_X2;
y2 = m_Y2;
if(deltaX)
{
if(i = m_dX1pcnt) // NOTE exIgnore == 0
x1 += (deltaX * i) / 100;
if(i = m_dX2pcnt) // NOTE exIgnore == 0
x2 += (deltaX * i) / 100;
}
if(deltaY)
{
if(i = m_dY1pcnt) // NOTE exIgnore == 0
y1 += (deltaY * i) / 100;
if(i = m_dY2pcnt) // NOTE exIgnore == 0
y2 += (deltaY * i) / 100;
}
for(register EqualCtrl *ec = &m_Link; ec; ec = ec->GetNext())
{
if(::IsWindow(ec->GetCtrl().m_hWnd))
{
#ifdef _DEBUG
ASSERT( ec->GetCtrl().SetWindowPos(&wndTop,x1,y1,x2-x1,y2-y1,SWP_NOREDRAW|SWP_NOZORDER) );
#else
ec->GetCtrl().SetWindowPos(&wndTop,x1,y1,x2-x1,y2-y1,SWP_NOREDRAW|SWP_NOZORDER);
#endif
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog dialog
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// construction
/////////////////////////////////////////////////////////////////////////////
void CSizingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSizingDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSizingDialog, CDialog)
//{{AFX_MSG_MAP(CSizingDialog)
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog message handlers
/////////////////////////////////////////////////////////////////////////////
/*
* set up dialog; this function MUST be called before you add any controls
* NOTE: The real OnInitDialog() virtual function calls this one by using
* DEF_STRETCH as a addSzByPcntValue.
* This value automatically grows the size of the dialog (therefore it
* won't appear in minimum height what I assume to be worse looking).
* Call it with a value of 0 to make it as small as you designed it
* in the resource editor.
*/
BOOL CSizingDialog::OnInitDialog(UINT addSzByPcnt)
{
CDialog::OnInitDialog();
return m_Controls.OnInitDialog(addSzByPcnt);
}
/*
* perform window sizing and adaption of controls
*/
void CSizingDialog::OnSize(UINT nType, int cx, int cy)
{
m_Controls.OnSize(nType,cx,cy);
CDialog::OnSize(nType, cx, cy);
}
/*
* tell system what minimum size we have
*/
void CSizingDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
m_Controls.OnGetMinMaxInfo(lpMMI);
}
/////////////////////////////////////////////////////////////////////////////
// Additional utilities
/////////////////////////////////////////////////////////////////////////////
/*
* pump all messages for this window
* call it during lengthy operations to ensure
* sizing takes place
*/
void CSizingDialog::PumpMessages(void)
{
// Must call Create() before using the dialog
ASSERT(::IsWindow(m_hWnd));
MSG msg;
// Handle dialog messages for all windows
while(::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE))
{
if(!CDialog::IsDialogMessage(&msg)) // not used by our dialog
{
::TranslateMessage(&msg); // pass to application
::DispatchMessage(&msg);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// cdxCSizingPropSheet
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(cdxCSizingPropSheet, CPropertySheet)
/////////////////////////////////////////////////////////////////////////////
// creation etc.
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(cdxCSizingPropSheet, CPropertySheet)
//{{AFX_MSG_MAP(cdxCSizingPropSheet)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_GETMINMAXINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// cdxCSizingPropSheet message handlers
/*
* setup controls
*/
BOOL cdxCSizingPropSheet::OnInitDialog(UINT addSzByPcnt)
{
BOOL bResult = CPropertySheet::OnInitDialog();
m_Controls.OnInitDialog(addSzByPcnt);
//
// now we like to add all pages
//
int i;
CWnd *w = CPropertySheet::GetActivePage(),
*helpBut = NULL;
if(!w || !::IsWindow(w->m_hWnd))
{
ASSERT(false);
// ugly...
// it will work but will even look quite ugly.
// reason: No page !
}
else
{
CSizingDialog::ControlInfo *ci;
ci = m_Controls.AddSzControl(*w,CSizingDialog::mdResize,CSizingDialog::mdResize);
if(ci)
{
CWnd *ow;
for(i=0; i<CPropertySheet::GetPageCount(); ++i)
if(ow = CPropertySheet::GetPage(i))
ci->AddEqualCtrl(*ow); // thus they'll be sized the same way :)
}
}
//
// add buttons, tab and bevel line
//
for(i=0; psheetCtrls[i].id != BAD_ID; ++i)
{
if(w = CPropertySheet::GetDlgItem(psheetCtrls[i].id))
{
if(psheetCtrls[i].id == IDHELP)
{
ASSERT(helpBut == NULL); // only one ?
helpBut = w;
}
m_Controls.AddSzControl(*w,psheetCtrls[i].modeX,psheetCtrls[i].modeY);
}
else
{
TRACE1(_T("*** WARNING[cdxCSizingPropSheet::OnInitDialog()]: Can't find CWnd for ID#%ld !\n"),psheetCtrls[i].id);
}
}
if(helpBut && (w = m_Controls.GetSizeIconCtrl()))
w->SetWindowPos(helpBut,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
return bResult;
}
/*
* add sizing style
*/
int cdxCSizingPropSheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
return -1;
ModifyStyle(0,WS_THICKFRAME|WS_SYSMENU);
return 0;
}
/*
* change size
*/
void cdxCSizingPropSheet::OnSize(UINT nType, int cx, int cy)
{
CPropertySheet::OnSize(nType, cx, cy);
m_Controls.OnSize(nType,cx,cy);
}
void cdxCSizingPropSheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
CPropertySheet::OnGetMinMaxInfo(lpMMI);
m_Controls.OnGetMinMaxInfo(lpMMI);
}
/*
* our overload
*/
void cdxCSizingPropSheet::AddPage( cdxCSizingPropPage & rPage )
{
CPropertySheet::AddPage(&rPage);
rPage.Init(*this);
}
/////////////////////////////////////////////////////////////////////////////
// cdxCSizingPropPage
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(cdxCSizingPropPage,CPropertyPage);
/////////////////////////////////////////////////////////////////////////////
// CSizingDialog message handlers
/////////////////////////////////////////////////////////////////////////////
void cdxCSizingPropPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(cdxCSizingPropPage)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(cdxCSizingPropPage, CPropertyPage)
//{{AFX_MSG_MAP(cdxCSizingPropPage)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// cdxCSizingPropPage basics
/////////////////////////////////////////////////////////////////////////////
BOOL cdxCSizingPropPage::OnInitDialog()
{
BOOL bOk = CPropertyPage::OnInitDialog();
m_Controls.OnInitDialog(0);
return bOk;
}
void cdxCSizingPropPage::OnSize(UINT nType, int cx, int cy)
{
m_Controls.OnSize(nType,cx,cy);
CPropertyPage::OnSize(nType, cx, cy);
}