-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXFolderDialog.cpp
922 lines (774 loc) · 27.9 KB
/
XFolderDialog.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
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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
// XFileOpenListView.cpp Version 1.0
//
// Diese Datei ist Bestandteil von EasyCash&Tax, der freien EÜR-Fibu
//
// Copyleft (GPLv3) 2020 Thomas Mielke
//
// Dies ist freie Software; Sie dürfen sie unter den Bedingungen der
// GNU General Public License, wie von der Free Software Foundation
// veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß
// Version 3 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
//
// Ein Verkauf dieser Quelldatei ist jedoch ausgeschlossen (siehe vorher-
// gehende Release-Info von Hans Dietrich).
//
// Diese Software wird in der Hoffnung weiterverbreitet, dass sie nützlich
// sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte
// Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK.
// Mehr Details finden Sie in der GNU Lesser General Public License.
//
// Sie sollten eine Kopie der GNU General Public License Version 3 zusammen mit
// dieser Software erhalten haben; falls nicht, schreiben Sie an die Free
// Software Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110, USA.
// vorige Release-Informationen (credits):
// XFolderDialog.cpp Version 1.3
//
// Author: Hans Dietrich
//
// Description:
// XFolderDialog implements CXFolderDialog, a folder browsing dialog that
// uses the new Windows 2000-style dialog. Please see article at
// www.codeproject.com.
//
// History
// Version 1.3 - 2008 February 22
// - Fixed problems related to compiling under recent versions of VS.
// - Fixed bug when new folder is created and OK pressed, reported
// by McLyndon and Super Garrison.
// - Fixed bug when new path entered in mru combo, reported by Brad Bruce,
// with fix suggested by Manfred Drasch.
// - Fixed bug when used in dll, reported by k-mommos.
// - Fixed bug where you click My Computer then select folder, with fix
// suggested by Wade Ledbetter.
// - Added ability to set/save list view mode, requested by Aetschmaen.
//
// Version 1.2 - 2005 March 22
// - Fixed initial sizing problem with placebar
//
// Version 1.1 - 2005 March 17
// - Improved performance by using file filter
//
// Version 1.0 - 2005 March 15
// - Initial public release; based on Version 1.2 of XFileDialog,
// with fixes provided by Ned Harding and Rail Jon Rogut.
//
// Public APIs:
// NAME DESCRIPTION
// ---------------- -----------------------------------------------------
// EnableRegistry() Enables/disables use of registry to store view mode
// GetPath() Returns folder path
// GetOsVersion() Returns OS version used to control dialog appearance
// GetViewMode() Gets last-used view mode from folder select dialog
// SetOsVersion() Set OS version used to control dialog appearance
// SetTitle() Set title of dialog ("Select Folder" is default)
// SetViewMode() Sets view mode for folder select dialog list control
//
// License:
// This software is released into the public domain. You are free to use
// it in any way you like, except that you may not sell this source code.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this
// software may cause.
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <afxpriv.h>
#include "XFolderDialog.h"
#include "XFolderDialogRes.h"
#include <io.h>
#include "dlgs.h"
#include "WinVer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma warning(disable : 4996) // disable bogus deprecation warning
//=============================================================================
// display _WIN32_WINNT in output window - this determines OPENFILENAME size
//=============================================================================
#define makestring2(x) #x
#define makestring(x) makestring2(x)
#ifdef _WIN32_WINNT
#pragma message(__FILE__ "(" makestring(__LINE__) ") : _WIN32_WINNT = " makestring(_WIN32_WINNT) "\n")
#else
#pragma message(__FILE__ "(" makestring(__LINE__) ") : _WIN32_WINNT is not defined\n")
#endif
//=============================================================================
// set resource handle (in case used in DLL)
//=============================================================================
#ifdef _USRDLL
#define AFXMANAGESTATE AfxGetStaticModuleState
#else
#define AFXMANAGESTATE AfxGetAppModuleState
#endif
#ifndef OPENFILENAME_SIZE_VERSION_400A
#define OPENFILENAME_SIZE_VERSION_400A CDSIZEOF_STRUCT(OPENFILENAMEA,lpTemplateName)
#define OPENFILENAME_SIZE_VERSION_400W CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName)
#ifdef UNICODE
#define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400W
#else
#define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400A
#endif // !UNICODE
#endif //
#ifndef __noop
#if _MSC_VER < 1300
#define __noop ((void)0)
#endif
#endif
#undef TRACE
#define TRACE __noop
//=============================================================================
// if you want to see the TRACE output, uncomment this line:
//#include "XTrace.h"
//=============================================================================
//=============================================================================
// CXFolderDialog
//=============================================================================
IMPLEMENT_DYNAMIC(CXFolderDialog, CFileDialog)
//=============================================================================
// registry key
//=============================================================================
static LPCTSTR PROFILE_SETTINGS = _T("XFolderDialog");
static LPCTSTR PROFILE_VIEWMODE = _T("ViewMode");
//=============================================================================
// static string for file filter
//=============================================================================
static LPCTSTR szFilter = _T("Files (*.XFolderDialog-8C0C924B-7A86-4e8d-8D6E-A1C50D74E8DF)|")
_T("*.XFolderDialog-8C0C924B-7A86-4e8d-8D6E-A1C50D74E8DF||");
//=============================================================================
BEGIN_MESSAGE_MAP(CXFolderDialog, CFileDialog)
//=============================================================================
//{{AFX_MSG_MAP(CXFolderDialog)
ON_WM_SIZE()
ON_CBN_SELENDOK(IDC_MRU_COMBO, OnSelendokMruCombo)
ON_CBN_KILLFOCUS(IDC_MRU_COMBO, OnCbnKillfocusMruCombo)
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//=============================================================================
CXFolderDialog::CXFolderDialog(LPCTSTR lpszInitialFolder /*= NULL*/,
DWORD dwFlags /*= 0*/,
CWnd* pParentWnd /*= NULL*/)
: CFileDialog(TRUE, NULL, NULL, dwFlags | OFN_HIDEREADONLY, szFilter, pParentWnd)
//=============================================================================
{
m_strInitialFolder = lpszInitialFolder;
m_strPath = _T("");
m_dwFlags = dwFlags;
m_eOsVersion = XFILEDIALOG_AUTO_DETECT_OS_VERSION;
m_strTitle = _T("");
m_nIdFileNameStatic = 1090;
m_nIdFileNameCombo = 1148; // or 1152
m_nIdFilesOfTypeStatic = 1089;
m_nIdFilesOfTypeCombo = 1136;
m_nIdPlaceBar = 1184;
m_nViewMode = XLVM_XP_UNDEFINED;
m_bUseRegistry = FALSE;
m_bPersist = FALSE;
#pragma warning (disable:4482)
SetOsVersion(CXFolderDialog::XFILEDIALOG_OS_VERSION::XFILEDIALOG_AUTO_DETECT_OS_VERSION);
SetViewMode(XLVM_XP_UNDEFINED);
// we use string version of SetTemplate(), to avoid resource id collisions
SetTemplate(0, _T("IDD_XFOLDERDIALOG"));
}
//=============================================================================
CXFolderDialog::~CXFolderDialog()
//=============================================================================
{
TRACE(_T("in CXFolderDialog::~CXFolderDialog\n"));
if (m_bUseRegistry && m_bPersist)
{
TRACE(_T("writing view mode to registry: 0x%X\n"),
m_wndListView.m_lastViewMode);
AfxGetApp()->WriteProfileInt(PROFILE_SETTINGS, PROFILE_VIEWMODE,
m_wndListView.m_lastViewMode);
}
}
//=============================================================================
void CXFolderDialog::DoDataExchange(CDataExchange* pDX)
//=============================================================================
{
CFileDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXFolderDialog)
DDX_Control(pDX, IDC_MRU_COMBO, m_cmbRecentFolders);
//}}AFX_DATA_MAP
}
//=============================================================================
// DoModal override copied mostly from MFC, with modification to use
// m_ofnEx instead of m_ofn.
int CXFolderDialog::DoModal()
//=============================================================================
{
TRACE(_T("in CXFolderDialog::DoModal\n"));
ASSERT_VALID(this);
ASSERT(m_ofn.Flags & OFN_ENABLEHOOK);
ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
AFX_MANAGE_STATE(AFXMANAGESTATE())
m_bFirstTime = TRUE;
m_wndListView.Init(this);
// zero out the file buffer for consistent parsing later
TCHAR * pBuf = new TCHAR [m_ofn.nMaxFile + 100];
memset(pBuf, 0, (m_ofn.nMaxFile + 100) * sizeof(TCHAR));
if (m_ofn.lpstrFile)
{
// copy file buffer
_tcsncpy(pBuf, m_ofn.lpstrFile, m_ofn.nMaxFile);
// zero out file buffer in OPENFILENAME struct
memset(m_ofn.lpstrFile, 0, m_ofn.nMaxFile*sizeof(TCHAR));
// restore copied file buffer
_tcsncpy(m_ofn.lpstrFile, pBuf, m_ofn.nMaxFile);
}
if (pBuf)
delete [] pBuf;
pBuf = NULL;
// WINBUG: This is a special case for the file open/save dialog,
// which sometimes pumps while it is coming up but before it has
// disabled the main window.
HWND hWndFocus = ::GetFocus();
BOOL bEnableParent = FALSE;
m_ofn.hwndOwner = PreModal();
AfxUnhookWindowCreate();
if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner))
{
bEnableParent = TRUE;
::EnableWindow(m_ofn.hwndOwner, FALSE);
}
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
ASSERT(pThreadState->m_pAlternateWndInit == NULL);
if (m_ofn.Flags & OFN_EXPLORER)
pThreadState->m_pAlternateWndInit = this;
else
AfxHookWindowCreate(this);
memset(&m_ofnEx, 0, sizeof(m_ofnEx));
memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn));
if (m_ofnEx.hInstance == 0)
m_ofnEx.hInstance = AfxGetInstanceHandle();
m_ofnEx.Flags |= OFN_ENABLESIZING;
#if (_WIN32_WINNT >= 0x0500)
TRACE(_T("_WIN32_WINNT=0x%X\n"), _WIN32_WINNT);
#pragma message(__FILE__ "(" makestring(__LINE__) \
") : OPENFILENAME is large size (3 extra items are included)")
if (IsWin2000())
m_ofnEx.lStructSize = sizeof(OPENFILENAME); // OS >= 2000, force to large size
else
m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400; // use small size
#else // _WIN32_WINNT < 0x0500, or isn't defined
#pragma message(__FILE__ "(" makestring(__LINE__) \
") : OPENFILENAME is small size (3 extra items are NOT included)")
if (IsWin2000())
m_ofnEx.lStructSize = sizeof(OPENFILENAMEEX); // OS >= 2000, force to large size
else
m_ofnEx.lStructSize = OPENFILENAME_SIZE_VERSION_400; // use small size
#endif
m_ofnEx.lpstrInitialDir = m_strInitialFolder;
int nResult = 0;
if (m_bOpenFileDialog)
nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx);
else
nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx);
memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
m_ofn.lStructSize = sizeof(m_ofn);
if (nResult)
{
ASSERT(pThreadState->m_pAlternateWndInit == NULL);
}
pThreadState->m_pAlternateWndInit = NULL;
// WINBUG: Second part of special case for file open/save dialog.
if (bEnableParent)
::EnableWindow(m_ofnEx.hwndOwner, TRUE);
if (::IsWindow(hWndFocus))
::SetFocus(hWndFocus);
PostModal();
return nResult ? nResult : IDCANCEL;
}
//=============================================================================
BOOL CXFolderDialog::OnInitDialog()
//=============================================================================
{
TRACE(_T("in CXFolderDialog::OnInitDialog\n"));
CFileDialog::OnInitDialog();
// load folder history - check if valid folder
m_cmbRecentFolders.SetMaxHistoryItems(50);
m_cmbRecentFolders.SetDropSize(20);
m_cmbRecentFolders.SetCheckAccess(TRUE);
m_cmbRecentFolders.LoadHistory(_T("FolderHistory"), _T("Folder"));
CString str;
if (m_cmbRecentFolders.GetCount() > 0)
{
m_cmbRecentFolders.GetLBText(0, str);
m_cmbRecentFolders.SetWindowText(str);
}
CWnd *pWndParent = GetParent();
ASSERT(pWndParent && IsWindow(pWndParent->m_hWnd));
// save left margin for combo boxes
CWnd *pWndFileNameCombo = pWndParent->GetDlgItem(m_nIdFileNameCombo);
if (!pWndFileNameCombo)
{
// the File Name control ID is either 1148 or 1152, depending on whether
// it is used as an edit box (1152) or a combo box (1148). If the OS
// version is < 5, it is 1152; if >= 5, it is 1148. It will also be
// 1152 if the registry key
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\NoFileMru
// is set to 1. For convenience, we will always refer to this control
// as a combobox.
m_nIdFileNameCombo = 1152;
pWndFileNameCombo = pWndParent->GetDlgItem(m_nIdFileNameCombo);
}
CRect rect;
CWnd *pWndFileNameStatic = pWndParent->GetDlgItem(m_nIdFileNameStatic);
ASSERT(pWndFileNameStatic);
if (pWndFileNameStatic)
{
pWndFileNameStatic->GetWindowRect(&rect);
pWndParent->ScreenToClient(&rect);
m_nStaticLeftMargin = rect.left;
}
else
{
m_nStaticLeftMargin = 60;
}
// set title if specified
if (m_strTitle.IsEmpty())
pWndParent->SetWindowText(_T("Select Folder"));
else
pWndParent->SetWindowText(m_strTitle);
static BOOL bFirstTime = TRUE;
if (bFirstTime)
{
bFirstTime = FALSE;
CToolBarCtrl *ptb = (CToolBarCtrl *) pWndParent->GetDlgItem(m_nIdPlaceBar);
if (ptb && IsWindow(ptb->m_hWnd))
ptb->ShowWindow(SW_HIDE);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//=============================================================================
void CXFolderDialog::SetViewMode(int cmd)
//=============================================================================
{
TRACE(_T("in CXFolderDialog::SetViewMode: 0x%X\n"), cmd);
m_nViewMode = cmd;
if (m_nViewMode == -1)
{
m_bUseRegistry = FALSE;
m_bPersist = FALSE;
}
else //if (m_nViewMode == 0)
{
m_bUseRegistry = TRUE;
m_bPersist = TRUE;
}
}
//=============================================================================
// OnSize - position and size controls on default and new dialogs
void CXFolderDialog::OnSize(UINT nType, int cx, int cy)
//=============================================================================
{
TRACE(_T("in CXFolderDialog::OnSize: cx=%d cy=%d\n"), cx, cy);
CFileDialog::OnSize(nType, cx, cy);
// original dialog box
CWnd *pWndParent = GetParent();
if ((pWndParent == NULL) || (!::IsWindow(pWndParent->m_hWnd)))
return;
CRect rectNoWhere(10000, 10000, 10001, 10001);
// File name combobox
CWnd *pWndFileNameCombo = pWndParent->GetDlgItem(m_nIdFileNameCombo);
if (pWndFileNameCombo && ::IsWindow(pWndFileNameCombo->m_hWnd))
{
pWndFileNameCombo->MoveWindow(&rectNoWhere);
pWndFileNameCombo->EnableWindow(FALSE);
}
// File name static
CWnd *pWnd = pWndParent->GetDlgItem(m_nIdFileNameStatic);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->MoveWindow(&rectNoWhere);
pWnd->EnableWindow(FALSE);
}
// Files of type combobox
pWnd = pWndParent->GetDlgItem(m_nIdFilesOfTypeCombo);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->MoveWindow(&rectNoWhere);
pWnd->EnableWindow(FALSE);
}
// Files of type static
pWnd = pWndParent->GetDlgItem(m_nIdFilesOfTypeStatic);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->MoveWindow(&rectNoWhere);
pWnd->EnableWindow(FALSE);
}
CRect rectOK;
CWnd *pWndOK = pWndParent->GetDlgItem(1);
if (pWndOK && ::IsWindow(pWndOK->m_hWnd))
{
pWndOK->GetWindowRect(&rectOK);
pWndParent->ScreenToClient(&rectOK);
pWndOK->ShowWindow(SW_HIDE);
}
CWnd *pWndOkButton = GetDlgItem(IDOK);
if (pWndOkButton && ::IsWindow(pWndOkButton->m_hWnd))
{
pWndOkButton->MoveWindow(&rectOK);
}
// Folder name static
CRect rectRecentFoldersStatic;
int h = 0;
int w = 0;
pWnd = GetDlgItem(IDC_MRU_CAPTION);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->GetWindowRect(&rectRecentFoldersStatic);
pWndParent->ScreenToClient(&rectRecentFoldersStatic);
h = rectRecentFoldersStatic.Height();
w = rectRecentFoldersStatic.Width();
rectRecentFoldersStatic.left = m_nStaticLeftMargin;
rectRecentFoldersStatic.right = rectRecentFoldersStatic.left + w;
rectRecentFoldersStatic.top = rectOK.top + 2;
rectRecentFoldersStatic.bottom = rectRecentFoldersStatic.top + h;
pWnd->MoveWindow(&rectRecentFoldersStatic);
}
// Folder name combobox
CRect rectRecentFoldersCombo;
pWnd = GetDlgItem(IDC_MRU_COMBO);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->GetWindowRect(&rectRecentFoldersCombo);
pWndParent->ScreenToClient(&rectRecentFoldersCombo);
w = rectRecentFoldersCombo.Width();
h = rectRecentFoldersCombo.Height();
rectRecentFoldersCombo.left = rectRecentFoldersStatic.right + 2;
rectRecentFoldersCombo.right = rectOK.left - 6;
rectRecentFoldersCombo.top = rectOK.top;
rectRecentFoldersCombo.bottom = rectRecentFoldersCombo.top + h;
pWnd->MoveWindow(&rectRecentFoldersCombo);
}
CRect rectCancelWindow, rectCancelClient;
pWnd = pWndParent->GetDlgItem(2);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
pWnd->GetWindowRect(&rectCancelClient);
rectCancelWindow = rectCancelClient;
pWndParent->ScreenToClient(&rectCancelClient);
}
// Place bar
pWnd = pWndParent->GetDlgItem(m_nIdPlaceBar);
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
CRect rectPlaceBar;
pWnd->GetWindowRect(&rectPlaceBar);
pWndParent->ScreenToClient(&rectPlaceBar);
rectPlaceBar.bottom = rectCancelClient.bottom;
pWnd->MoveWindow(&rectPlaceBar);
}
// Dialog
CRect rectDialog;
pWndParent->GetWindowRect(&rectDialog);
rectDialog.bottom = rectCancelWindow.bottom + rectCancelWindow.Height()/2 + 3;
rectDialog.right = rectCancelWindow.right + 10;
pWndParent->MoveWindow(&rectDialog);
///////////////////////////////////////////////////////////////////////////
// following code is necessary to prevent having the
// recent folders combobox highlighted
static BOOL bFirstTime = TRUE;
if (bFirstTime)
{
bFirstTime = FALSE;
m_cmbRecentFolders.SetFocus();
SetTimer(1, 20, NULL); // ensure all placebar buttons are visible
}
else
{
m_cmbRecentFolders.SetEditSel(-1, 0);
pWndFileNameCombo->SetFocus();
}
}
//=============================================================================
CString CXFolderDialog::GetPath(UINT nMessage)
//=============================================================================
{
CString strPath = _T("");
CWnd *pWnd = GetParent();
if (pWnd && IsWindow(pWnd->m_hWnd))
{
TCHAR szDir[MAX_PATH*3];
szDir[0] = _T('\0');
pWnd->SendMessage(nMessage, sizeof(szDir)/sizeof(TCHAR)-2,
(LPARAM)(LPCTSTR)szDir);
szDir[sizeof(szDir)/sizeof(TCHAR)-1] = _T('\0');
strPath = szDir;
}
return strPath;
}
/*
BOOL CXFolderDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
TRACE(_T("in CXFolderDialog::OnNotify\n"));
memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
m_ofn.lStructSize = sizeof(m_ofn);
NMHDR * pNmhdr = (NMHDR *) lParam;
TRACE1("%d\r\n", pNmhdr->code);
if (pNmhdr->code == CDN_SELCHANGE)
{
TRACE(_T("XFolderDialog::OnNotify() CDN_SELCHANGE ===============\n"));
CWnd *pWnd = GetParent();
if (pWnd)
{
TCHAR szDir[MAX_PATH*2] = { 0 };
pWnd->SendMessage(CDM_GETFILEPATH, sizeof(szDir)/sizeof(TCHAR)-2,
(LPARAM)(LPCTSTR)szDir);
TRACE1("CDN_SELCHANGE %d\r\n", pNmhdr->code);
m_strPath = szDir;
m_cmbRecentFolders.SetWindowText(m_strPath);
TRACE(_T("m_strPath=%s\n"), m_strPath);
}
}
else if (pNmhdr->code == CDN_FOLDERCHANGE)
{
TRACE(_T("XFolderDialog::OnNotify() CDN_FOLDERCHANGE ===============\n"));
TRACE1("CDN_FOLDERCHANGE %d\r\n", pNmhdr->code);
CWnd *pWnd = GetParent();
if (pWnd)
{
TCHAR szDir[MAX_PATH*2] = { 0 };
pWnd->SendMessage(CDM_GETFOLDERPATH, sizeof(szDir)/sizeof(TCHAR)-2,
(LPARAM)(LPCTSTR)szDir);
m_strPath = szDir;
m_cmbRecentFolders.SetWindowText(szDir);
}
}
return CFileDialog::OnNotify(wParam, lParam, pResult);
}
void CXFolderDialog::OnOK()
{
OutputDebugString(_T("CXFolderDialog::OnOK\n"));
CWnd *pWnd = GetParent();
if (pWnd)
{
TCHAR szDir[MAX_PATH*2] = { 0 };
pWnd->SendMessage(CDM_GETFILEPATH, sizeof(szDir)/sizeof(TCHAR)-2,
(LPARAM)(LPCTSTR)szDir);
m_strPath = szDir;
m_cmbRecentFolders.SetWindowText(m_strPath);
}
else
{
m_cmbRecentFolders.GetWindowText(m_strPath);
}
if (_taccess(m_strPath, 00) == -1)
{
CString strMessage = _T("");
strMessage.Format(_T("The folder '%s' isn't accessible."), m_strPath);
AfxMessageBox(strMessage);
return;
}
m_cmbRecentFolders.SaveHistory(TRUE);
((CDialog*)GetParent())->EndDialog(IDOK);
}
*/
//=============================================================================
// OnNotify - when the open dialog sends a notification, copy m_ofnEx to m_ofn
// in case handler function is expecting updated information in the
// OPENFILENAME struct.
//
BOOL CXFolderDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
//=============================================================================
{
TRACE(_T("in CXFolderDialog::OnNotify\n"));
memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn));
m_ofn.lStructSize = sizeof(m_ofn);
NMHDR * pNmhdr = (NMHDR *) lParam;
TRACE1("--> %d\r\n", pNmhdr->code);
if (pNmhdr->code == CDN_SELCHANGE)
{
TRACE1("CDN_SELCHANGE %d\r\n", pNmhdr->code);
TRACE(_T("XFolderDialog::OnNotify() CDN_SELCHANGE ===============\n"));
m_strPath = GetPath(CDM_GETFILEPATH);
if (!m_strPath.IsEmpty())
m_cmbRecentFolders.SetWindowText(m_strPath);
TRACE(_T("m_strPath=%s\n"), m_strPath);
}
else if (pNmhdr->code == CDN_FOLDERCHANGE)
{
TRACE1("CDN_FOLDERCHANGE %d\r\n", pNmhdr->code);
TRACE(_T("XFolderDialog::OnNotify() CDN_FOLDERCHANGE ===============\n"));
m_strPath = GetPath(CDM_GETFOLDERPATH);
if (!m_strPath.IsEmpty())
m_cmbRecentFolders.SetWindowText(m_strPath);
TRACE(_T("m_strPath=%s\n"), m_strPath);
TRACE(_T("m_bPersist=%d -----\n"), m_bPersist);
if (m_bPersist)
{
if (m_wndListView.m_hWnd && IsWindow(m_wndListView.m_hWnd))
m_wndListView.UnsubclassWindow(); // unsubclass myself
m_wndListView.m_hWnd = 0;
VERIFY(m_wndListView.SubclassDlgItem(lst2, GetParent()));
if (m_bFirstTime)
{
TRACE(_T("first-time init: %d\n"), m_bUseRegistry);
// if first-time init:
// Set view mode based on value saved in profile settings.
if (m_bUseRegistry && (m_nViewMode == 0))
{
m_nViewMode = AfxGetApp()->GetProfileInt(PROFILE_SETTINGS, PROFILE_VIEWMODE, 0);
TRACE(_T("reading view mode from registry: 0x%X\n"), m_nViewMode);
}
m_bFirstTime = FALSE;
}
TRACE(_T("setting view mode to 0x%X\n"), m_nViewMode);
m_wndListView.SetViewMode(m_nViewMode);
}
}
return CFileDialog::OnNotify(wParam, lParam, pResult);
}
//=============================================================================
void CXFolderDialog::OnOK()
//=============================================================================
{
TRACE(_T("CXFolderDialog::OnOK: m_strPath=%s\n"), m_strPath);
m_strPath = GetPath(CDM_GETFILEPATH);
if (!m_strPath.IsEmpty())
m_cmbRecentFolders.SetWindowText(m_strPath);
else
m_cmbRecentFolders.GetWindowText(m_strPath);
TRACE(_T("m_strPath=%s\n"), m_strPath);
if (m_strPath.IsEmpty())
{
AfxMessageBox(_T("Please select a folder."));
return;
}
else if (_taccess(m_strPath, 00) == -1)
{
CString strMessage = _T("");
strMessage.Format(_T("The folder '%s' isn't accessible."), m_strPath);
AfxMessageBox(strMessage);
return;
}
m_cmbRecentFolders.SaveHistory(TRUE);
((CDialog*)GetParent())->EndDialog(IDOK);
}
//=============================================================================
void CXFolderDialog::OnSelendokMruCombo()
//=============================================================================
{
TRACE(_T("in CXFolderDialog::OnSelendokMruCombo\n"));
if (!::IsWindow(m_cmbRecentFolders.m_hWnd))
return;
CString strFolder = _T("");
int index = m_cmbRecentFolders.GetCurSel();
if (index >= 0)
{
m_cmbRecentFolders.GetLBText(index, strFolder);
if (!strFolder.IsEmpty() && (_taccess(strFolder, 00) == 0))
{
CWnd *pWnd = GetParent();
if ((pWnd != NULL) && ::IsWindow(pWnd->m_hWnd))
{
// change to new folder, leave file name control unchanged
TCHAR szText[_MAX_PATH*2];
szText[0] = _T('\0');
pWnd->GetDlgItem(m_nIdFileNameCombo)->SendMessage(WM_GETTEXT,
sizeof(szText)/sizeof(TCHAR)-2, (LPARAM)szText);
pWnd->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)(LPCTSTR)strFolder);
pWnd->SendMessage(WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED),
(LPARAM)GetDlgItem(IDOK)->GetSafeHwnd());
pWnd->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)szText);
}
}
}
}
//=============================================================================
void CXFolderDialog::OnCbnKillfocusMruCombo()
//=============================================================================
{
CString strFolder = _T("");
m_cmbRecentFolders.GetWindowText(strFolder);
if (!strFolder.IsEmpty() && (_taccess(strFolder, 00) == 0))
{
CWnd *pWnd = GetParent();
if (pWnd && ::IsWindow(pWnd->m_hWnd))
{
// change to new folder, leave file name control unchanged
TCHAR szText[MAX_PATH*2];
szText[0] = _T('\0');
pWnd->GetDlgItem(m_nIdFileNameCombo)->SendMessage(WM_GETTEXT,
sizeof(szText)/sizeof(TCHAR)-2, (LPARAM)szText);
pWnd->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)(LPCTSTR)strFolder);
pWnd->SendMessage(WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED),
(LPARAM)GetDlgItem(IDOK)->GetSafeHwnd());
pWnd->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)szText);
m_strPath = strFolder;
}
}
}
//=============================================================================
BOOL CXFolderDialog::IsWin2000()
//=============================================================================
{
if (GetOsVersion() == XFILEDIALOG_OS_VERSION_4)
return FALSE;
else if (GetOsVersion() == XFILEDIALOG_OS_VERSION_5)
return TRUE;
// auto detect
if (Is2000OrGreater())
return TRUE;
return FALSE;
}
//=============================================================================
// OnTimer - adjust dialog size so placebar fits
void CXFolderDialog::OnTimer(UINT nIDEvent)
//=============================================================================
{
KillTimer(nIDEvent);
if (nIDEvent == 1)
{
CWnd *pWndParent = GetParent();
if (pWndParent && IsWindow(pWndParent->m_hWnd))
{
CRect rectPlaceBar;
CWnd *pWnd = pWndParent->GetDlgItem(m_nIdPlaceBar);
if (pWnd && IsWindow(pWnd->m_hWnd))
{
pWnd->GetWindowRect(&rectPlaceBar);
CToolBarCtrl *ptb = (CToolBarCtrl *) pWndParent->GetDlgItem(m_nIdPlaceBar);
if (ptb && IsWindow(ptb->m_hWnd))
{
int nCount = ptb->GetButtonCount();
DWORD dwSize = ptb->GetButtonSize();
UINT nButtonHeight = HIWORD(dwSize);
int nMinHeight = nCount * nButtonHeight + 2;
CRect rectDialog;
pWndParent->GetWindowRect(&rectDialog);
if ((rectPlaceBar.Height() < nMinHeight) &&
(nMinHeight < GetSystemMetrics(SM_CYSCREEN))) // might not work on multiple monitors
{
// adjust dialog so all buttons are visible
rectDialog.bottom += nMinHeight - rectPlaceBar.Height();
pWndParent->MoveWindow(&rectDialog);
}
ptb->ShowWindow(SW_SHOW);
}
}
}
SetFocus(); // set focus back to dialog
}
CFileDialog::OnTimer(nIDEvent);
}
//=============================================================================
void CXFolderDialog::OnDestroy()
//=============================================================================
{
TRACE(_T("in CXFolderDialog::OnDestroy\n"));
m_nViewMode = m_wndListView.m_lastViewMode;
CFileDialog::OnDestroy();
}