GuiFDir.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:3k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. /****************************************************************************
  2.  * *  
  3.  * GuiToolKit   *
  4.  *  (MFC extension) *  
  5.  * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
  6.  *--------------------------------------------------------------------------*    
  7.  * *
  8.  * This program is free software;so you are free to use it any of your *
  9.  * applications (Freeware, Shareware, Commercial),but leave this header *
  10.  * intact. *
  11.  * *
  12.  * These files are provided "as is" without warranty of any kind. *
  13.  * *
  14.  *        GuiToolKit is forever FREE CODE !!!!! *
  15.  * *
  16.  *--------------------------------------------------------------------------*
  17.  * Created by: Francisco Campos G. *
  18.  * Bug Fixes and improvements : (Add your name) *
  19.  * -Francisco Campos *
  20.  * *
  21.  ****************************************************************************/
  22. #include "stdafx.h"
  23. #include "GuiFDir.h"
  24. #include <Dlgs.h>     
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CFDir
  32. #define ID_BUTTONOK  200
  33. #define IDEDIT  201
  34. IMPLEMENT_DYNAMIC(CGuiFDir, CFileDialog)
  35. CGuiFDir::CGuiFDir(CWnd* parent)
  36. :CFileDialog(TRUE, NULL,_T("*..*"), 
  37.              OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST,
  38.              NULL, parent)
  39. {
  40.     m_ofn.lpstrTitle = _T("Select Folder");
  41. m_ofn.lpstrFilter =_T("Directory");
  42. }
  43. BEGIN_MESSAGE_MAP(CFWnd, CWnd)
  44.         //ON_BN_CLICKED(ID_BUTTONOK, OnOpen)
  45. ON_BN_CLICKED(IDOK, OnOpen)
  46. END_MESSAGE_MAP()
  47. BEGIN_MESSAGE_MAP(CGuiFDir,CFileDialog)
  48. //{{AFX_MSG_MAP(CFDir)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. void CFWnd::OnOpen()
  52. {
  53. CString m_GetPath;
  54. GetDlgItem(IDEDIT)->GetWindowText(m_GetPath);
  55. DWORD attr = GetFileAttributes((LPCTSTR)m_GetPath);
  56.     if (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
  57.      {
  58. ::EndDialog(m_hWnd, IDOK);
  59.      }
  60.  
  61. }
  62. void CGuiFDir::OnInitDone()
  63. {
  64. CRect rc;
  65. CRect rcCancel;
  66. CRect rclst;
  67. CString m_Caption;
  68. VERIFY(cw=GetParent());
  69. VERIFY(cfwn.SubclassWindow(cw->m_hWnd));
  70. cw->GetDlgItem(stc3)->SetWindowText(_T("Folder:"));
  71. cw->GetDlgItem(stc2)->SetWindowText(_T("Selection type:"));
  72.     cw->GetDlgItem(edt1)->GetWindowRect(rc);
  73. cw->ScreenToClient(rc);
  74. m_cedit.Create(WS_TABSTOP | WS_VISIBLE | WS_CHILD,rc,cw,IDEDIT);
  75. m_cedit.SetWindowPos(this,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
  76. m_cedit.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);
  77. m_cedit.SetWindowText(m_ofn.lpstrInitialDir);
  78. m_cedit.SetFont(cw->GetDlgItem(edt1)->GetFont());
  79. HideControl(edt1);
  80. CFileDialog::OnInitDone();
  81. }
  82. void CGuiFDir::OnFolderChange()
  83. {
  84. m_GetPath=GetFolderPath();
  85. m_cedit.SetWindowText(m_GetPath);
  86. CFileDialog::OnFolderChange();
  87. }