PageShellDialogBrowseFor.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:10k
源码类别:

界面编程

开发平台:

Visual C++

  1. // PageShellDialogBrowseFor.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "profuis_controls.h"
  5. #include "PageShellDialogBrowseFor.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #if ( ! defined __EXT_MFC_NO_SHELL_DIALOG_BFF )
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPageShellDialogBrowseFor dialog
  14. CPageShellDialogBrowseFor::CPageShellDialogBrowseFor(CWnd* pParent /*=NULL*/)
  15. : CPageBase(CPageShellDialogBrowseFor::IDD, pParent)
  16. , m_bInitComplete( false )
  17. {
  18. //{{AFX_DATA_INIT(CPageShellDialogBrowseFor)
  19. //}}AFX_DATA_INIT
  20. SetAutoSubclassChildControls();
  21. }
  22. void CPageShellDialogBrowseFor::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CPageBase::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CPageShellDialogBrowseFor)
  26. DDX_Control(pDX, IDC_CHECK_JUMP_TO_CURRENT_DIRECTORY_INITIALLY, m_checkJumpToCurrentDirectoryInitially);
  27. DDX_Control(pDX, IDC_CHECK_ALLOW_CURRENT_DIRECTORY_CHANGING, m_checkAllowCurrentDirectoryChanging);
  28. DDX_Control(pDX, IDC_CHECK_COMPARE_WITH_WINDOWS, m_checkCompareWithWindowsDialogs);
  29. DDX_Control(pDX, IDC_CHECK_ENABLE_SHELL_CONTEXT_MENUS_BFF, m_checkEnableShellContextMenusBFF);
  30. DDX_Control(pDX, IDC_CHECK_SHOW_HIDDEN_ITEMS_BFF, m_checkShowHiddenItemsBFF);
  31. DDX_Control(pDX, IDC_EDIT_CUSTOM_CAPTION_FOR_NEW_FOLDER_BUTTON, m_editCustomCaptionForNewFolderButton);
  32. DDX_Control(pDX, IDC_EDIT_CUSTOM_CAPTION_FOR_EDIT_LABEL, m_editCustomCaptionForEditLabel);
  33. DDX_Control(pDX, IDC_EDIT_CUSTOM_CAPTION_FOR_CANCEL_BUTTON1, m_editCustomCaptionForCancelButton1);
  34. DDX_Control(pDX, IDC_STATIC_ROOT_FOR_BROWSE_FOR_DIALOG, m_labelEditRootInBrowseForDialog);
  35. DDX_Control(pDX, IDC_EDIT_CUSTOM_CAPTION_FOR_OK_BUTTON, m_editCustomCaptionForOkButton);
  36. DDX_Control(pDX, IDC_EDIT_CUSTOM_CAPTION_FOR_BROWSE_FOR_DIALOG, m_editCustomCaptionForBrowseForDialog);
  37. DDX_Control(pDX, IDC_CHECK_SHOW_NEW_FOLDER_BUTTON, m_checkShowNewFolderButton);
  38. DDX_Control(pDX, IDC_CHECK_SHOW_EDIT, m_checkShowEdit);
  39. DDX_Control(pDX, IDC_EDIT_TITLE_TEXT, m_editTitleText);
  40. DDX_Control(pDX, IDC_EDIT_BFF_INITIAL_FOLDER, m_editInitialFolderForBrowseDialog);
  41. DDX_Control(pDX, IDC_CHECK_SR_SL, m_checkSaveRestoreShellLocation);
  42. DDX_Control(pDX, IDC_CHECK_SR_WP, m_checkSaveRestoreWindowPosition);
  43. //}}AFX_DATA_MAP
  44. DDX_Control(pDX, IDC_EDIT_BFF_RESULT, m_editResultOfBrowseDialog);
  45. }
  46. BEGIN_MESSAGE_MAP(CPageShellDialogBrowseFor, CPageBase)
  47. //{{AFX_MSG_MAP(CPageShellDialogBrowseFor)
  48. ON_BN_CLICKED(IDC_BUTTON_SHOW_WINDOWS_DIALOG, OnButtonShowWindowsDialog)
  49. ON_BN_CLICKED(IDC_BUTTON_SHOW_PROF_UIS_DIALOG, OnButtonShowProfUisDialog)
  50. ON_BN_CLICKED(IDC_BUTTON_SET_CUSTOM_ROOT, OnButtonSetCustomRoot)
  51. ON_BN_CLICKED(IDC_BUTTON_RESET_CUSTOM_ROOT, OnButtonResetCustomRoot)
  52. ON_BN_CLICKED(IDC_CHECK_COMPARE_WITH_WINDOWS, OnCheckCompareWithWindowsDialogs)
  53. ON_MESSAGE( BFFM_VALIDATEFAILED, BrowseCallbackProc )
  54. ON_BN_CLICKED(IDC_CHECK_SR_SL, OnCheckSrSl)
  55. ON_BN_CLICKED(IDC_CHECK_JUMP_TO_CURRENT_DIRECTORY_INITIALLY, OnCheckJumpToCurrentDirectoryInitially)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CPageShellDialogBrowseFor message handlers
  60. BOOL CPageShellDialogBrowseFor::OnInitDialog() 
  61. {
  62. CPageBase::OnInitDialog();
  63. m_editTitleText.SetCueBanner( _T("Empty text here means no title.") );
  64. static LPCTSTR g_strEmptyCommentCueBanner = _T("Empty text here means use default caption.");
  65. m_editCustomCaptionForOkButton.SetCueBanner( g_strEmptyCommentCueBanner );
  66. m_editCustomCaptionForBrowseForDialog.SetCueBanner( g_strEmptyCommentCueBanner );
  67. m_labelEditRootInBrowseForDialog.SetCueBanner( _T("Default shell root is used.") ); 
  68. m_editCustomCaptionForCancelButton1.SetCueBanner( g_strEmptyCommentCueBanner );
  69. m_editCustomCaptionForNewFolderButton.SetCueBanner( g_strEmptyCommentCueBanner );
  70. m_editCustomCaptionForEditLabel.SetCueBanner( g_strEmptyCommentCueBanner );
  71. m_checkEnableShellContextMenusBFF.SetCheck( 1 );
  72. m_checkShowHiddenItemsBFF.SetCheck( 0 );
  73. m_checkSaveRestoreShellLocation.SetCheck( 1 );
  74. m_checkSaveRestoreWindowPosition.SetCheck( 1 );
  75. m_checkJumpToCurrentDirectoryInitially.SetCheck( 0 );
  76. m_checkAllowCurrentDirectoryChanging.SetCheck( 1 );
  77. OnCheckSrSl();
  78. m_bInitComplete = true;
  79. return TRUE;
  80. }
  81. void CPageShellDialogBrowseFor::OnButtonShowWindowsDialog() 
  82. {
  83. BROWSEINFO _bi;
  84. ::memset( &_bi, 0, sizeof(BROWSEINFO) );
  85. TCHAR SelectFolder[MAX_PATH];
  86. _bi.hwndOwner = m_hWndFocus;
  87. if( m_pidlCustomRoot != NULL )
  88. _bi.pidlRoot = m_pidlCustomRoot;
  89. CString _strTextTitle;
  90. m_editTitleText.GetWindowText( _strTextTitle );
  91. if( ! _strTextTitle.IsEmpty() )
  92. _bi.lpszTitle = _strTextTitle;
  93. if( m_checkShowEdit.GetCheck() == 1 )
  94. _bi.ulFlags = BIF_EDITBOX/*|BIF_VALIDATE*/;
  95. _bi.pszDisplayName = SelectFolder;
  96. CExtPIDL pidl;
  97. pidl.Attach( (ITEMIDLIST*)(LPITEMIDLIST)::SHBrowseForFolder( &_bi ) );
  98. if( ! pidl.IsEmpty() )
  99. {
  100. CExtSafeString str = pidl.GetPath();
  101. if( str.IsEmpty() )
  102. str = SelectFolder;
  103. m_editResultOfBrowseDialog.SetWindowText( str );
  104. pidl.Empty();
  105. }
  106. else
  107. m_editResultOfBrowseDialog.SetWindowText( __CANCEL_BUTTON_PRESSED_EVENT_RESULT_DESCRIPTION );
  108. }
  109. void CPageShellDialogBrowseFor::OnButtonShowProfUisDialog() 
  110. {
  111. CString strCustomDialogCaption;
  112. m_editCustomCaptionForBrowseForDialog.GetWindowText( strCustomDialogCaption );
  113. CString strCustomOkButtonCaption;
  114. m_editCustomCaptionForOkButton.GetWindowText( strCustomOkButtonCaption );
  115. CString strTextTitle;
  116. m_editTitleText.GetWindowText( strTextTitle );
  117. CString strCustomCancelButtonCaption;
  118. m_editCustomCaptionForCancelButton1.GetWindowText( strCustomCancelButtonCaption );
  119. CString strCustomNewFolderButtonCaption;
  120. m_editCustomCaptionForNewFolderButton.GetWindowText( strCustomNewFolderButtonCaption );
  121. CString strCustomEditLabelCaption;
  122. m_editCustomCaptionForEditLabel.GetWindowText( strCustomEditLabelCaption );
  123. CExtShellDialogBrowseFor dlgShellBrowseFor( this );
  124. if( ! strCustomDialogCaption.IsEmpty() )
  125. dlgShellBrowseFor.m_strCustomDialogCaption = LPCTSTR(strCustomDialogCaption);
  126. if( ! strCustomOkButtonCaption.IsEmpty() )
  127. dlgShellBrowseFor.m_strCustomOkButtonCaption = LPCTSTR(strCustomOkButtonCaption);
  128. if( ! strCustomCancelButtonCaption.IsEmpty() )
  129. dlgShellBrowseFor.m_strCustomCancelButtonCaption = LPCTSTR(strCustomCancelButtonCaption);
  130. if( ! strCustomNewFolderButtonCaption.IsEmpty() )
  131. dlgShellBrowseFor.m_strCustomNewFolderButtonCaption = LPCTSTR(strCustomNewFolderButtonCaption);
  132. if( ! strCustomEditLabelCaption.IsEmpty() )
  133. dlgShellBrowseFor.m_strCustomEditLabelCaption = LPCTSTR(strCustomEditLabelCaption);
  134. if( ! strTextTitle.IsEmpty() )
  135. dlgShellBrowseFor.m_strLabelAtTop = LPCTSTR(strTextTitle);
  136. if( m_checkShowHiddenItemsBFF.GetCheck() != 0 )
  137. dlgShellBrowseFor.m_wndShellTree.m_dwAttributeFilterAny |= SFGAO_HIDDEN;
  138. else
  139. dlgShellBrowseFor.m_wndShellTree.m_dwAttributeFilterAllAbsent |= SFGAO_HIDDEN;
  140. dlgShellBrowseFor.m_wndShellTree.ShowShellContextMenusSet( ( m_checkEnableShellContextMenusBFF.GetCheck() != 0 ) ? true : false );
  141. dlgShellBrowseFor.m_bShowMakeNewFolderButton = ( m_checkShowNewFolderButton.GetCheck() == 1 ) ? true : false;
  142. dlgShellBrowseFor.m_bShowFolderEdit = ( m_checkShowEdit.GetCheck() == 1 ) ? true : false;
  143. if( m_pidlCustomRoot != NULL )
  144. dlgShellBrowseFor.m_pidlRoot = m_pidlCustomRoot;
  145. CString strInitialFolder;
  146. m_editInitialFolderForBrowseDialog.GetWindowText( strInitialFolder );
  147. strInitialFolder.TrimLeft( _T(" rnt") );
  148. strInitialFolder.TrimRight( _T(" rnt") );
  149. if( ! strInitialFolder.IsEmpty() )
  150. dlgShellBrowseFor.m_pidlResult.FromFolder( LPCTSTR(strInitialFolder), NULL );
  151. dlgShellBrowseFor.m_bCurrentDirectorySetInitially = ( m_checkJumpToCurrentDirectoryInitially.GetCheck() != 0 ) ? true : false;
  152. dlgShellBrowseFor.m_bCurrentDirectorySetOnWalk = ( m_checkAllowCurrentDirectoryChanging.GetCheck() != 0 ) ? true : false;
  153. dlgShellBrowseFor.m_bSaveRestoreShellLocation = ( m_checkSaveRestoreShellLocation.GetCheck() != 0 ) ? true : false;
  154. dlgShellBrowseFor.m_bSaveRestoreWindowPosition = ( m_checkSaveRestoreWindowPosition.GetCheck() != 0 ) ? true : false;
  155. if( dlgShellBrowseFor.DoModal() != IDOK )
  156. m_editResultOfBrowseDialog.SetWindowText( __CANCEL_BUTTON_PRESSED_EVENT_RESULT_DESCRIPTION );
  157. else if( ! dlgShellBrowseFor.m_pidlResult.IsEmpty() )
  158. {
  159. CExtSafeString str = dlgShellBrowseFor.m_pidlResult.GetPath();
  160. if( str.IsEmpty() )
  161. str = dlgShellBrowseFor.m_strDisplayNameResult;
  162. m_editResultOfBrowseDialog.SetWindowText( str );
  163. }
  164. else
  165. m_editResultOfBrowseDialog.SetWindowText( __CANCEL_BUTTON_PRESSED_EVENT_RESULT_DESCRIPTION );
  166. }
  167. LRESULT CPageShellDialogBrowseFor::BrowseCallbackProc( WPARAM wParam, LPARAM lParam )
  168. {
  169. wParam;
  170. lParam;
  171. return 0;
  172. }
  173. void CPageShellDialogBrowseFor::OnButtonSetCustomRoot() 
  174. {
  175. BROWSEINFO _bi;
  176. ::memset( &_bi, 0, sizeof(BROWSEINFO) );
  177. _bi.hwndOwner = m_hWndFocus;
  178. _bi.lpszTitle = _T("Select custom root");
  179. m_pidlCustomRoot.Empty();
  180. m_pidlCustomRoot.Attach( (ITEMIDLIST*)(LPITEMIDLIST)::SHBrowseForFolder( &_bi ) );
  181. m_strRootCurrent = _T("");
  182. if( ! m_pidlCustomRoot.IsRoot() )
  183. {
  184. m_strRootCurrent = LPCTSTR(m_pidlCustomRoot.GetPath());
  185. if( m_strRootCurrent.IsEmpty() )
  186. m_strRootCurrent = LPCTSTR(m_pidlCustomRoot.GetDisplayNameOf());
  187. }
  188. m_labelEditRootInBrowseForDialog.SetWindowText( LPCTSTR(m_strRootCurrent) ); 
  189. }
  190. void CPageShellDialogBrowseFor::OnButtonResetCustomRoot() 
  191. {
  192. m_pidlCustomRoot.Empty();
  193. m_strRootCurrent = _T("");
  194. m_labelEditRootInBrowseForDialog.SetWindowText( LPCTSTR(m_strRootCurrent) ); 
  195. }
  196. void CPageShellDialogBrowseFor::OnCheckCompareWithWindowsDialogs() 
  197. {
  198. UINT nShowCmd = ( m_checkCompareWithWindowsDialogs.GetCheck() != 0 ) ? SW_SHOW : SW_HIDE;
  199. GetDlgItem( IDC_BUTTON_SHOW_WINDOWS_DIALOG ) -> ShowWindow( nShowCmd );
  200. }
  201. void CPageShellDialogBrowseFor::OnCheckSrSl() 
  202. {
  203. BOOL bEnable = ( m_checkSaveRestoreShellLocation.GetCheck() != 0 ) ? FALSE : TRUE;
  204. m_checkJumpToCurrentDirectoryInitially.EnableWindow( bEnable );
  205. m_editInitialFolderForBrowseDialog.EnableWindow( bEnable );
  206. }
  207. void CPageShellDialogBrowseFor::OnCheckJumpToCurrentDirectoryInitially() 
  208. {
  209. BOOL bEnable = ( m_checkJumpToCurrentDirectoryInitially.GetCheck() != 0 ) ? FALSE : TRUE;
  210. m_checkSaveRestoreShellLocation.EnableWindow( bEnable );
  211. m_editInitialFolderForBrowseDialog.EnableWindow( bEnable );
  212. }
  213. #endif // ( ! defined __EXT_MFC_NO_SHELL_DIALOG_BFF )