?? ddxfolder.cpp
字號:
/*
Module : DDXFOLDER.CPP
Purpose: implementation for a MFC DDX_ routine to get a directory/folder
Using the file open/save as common dialogs or the newer Shell API
SHBrowseForFolder
Created: PJN / 26-03-1997
History: PJN / 16-07-1997 Added support for setting the initial directory when using SHBrowseForFolder
PJN / 26-11-1997 Update to allow the folder selection dialogs to be used withou the DDX stuff
PJN / 16-09-1998 1. Updated all the documentation to be HTML based as with my other shareware / freeware.
2. Unicode enabled all the code and provision of Unicode build configurations.
3. VC 5 mak files provided now as standard
4. Option to have non read only edit control.
5. Provision of a DDV function
6. General tidy up of the sample app including removing all the AppWizard
generated comments.
7. All code now compiles cleanly at warning level 4
8. Replaced all TRACE0 calls with TRACE
9. Changed name of main function from DDX_GetFolder to DDX_FolderControl
10. Module name has been changed from ddxgetfolder to ddxfolder.
11. Sample app now allows read only state of widget to be toggled
13. Addition of a DDX_FolderValue function
14. Change the ID's of the strings in the resource table which the code uses
PJN / 17-09-1998 1. Minor update to some comments and the documentation
Copyright (c) 1997 - 1998 by PJ Naughter.
All rights reserved.
*/
///////////////////////////////// Includes //////////////////////////////////
#include "stdafx.h"
#include "..\\DogMgt.h"
#include "ddxfolder.h"
#include "choosedirdlg.h"
//#include "DICOM.h"
//#include "MainFrm.h"
///////////////////////////////// defines /////////////////////////////////////
#define GETFOLDER_EDIT_ID 100
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////// Implementation //////////////////////////////
BEGIN_MESSAGE_MAP(CModifyButton, CButton)
//{{AFX_MSG_MAP(CModifyButton)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CModifyButton::CModifyButton()
{
m_pBuddy = NULL;
m_bFirstCall = TRUE;
}
void CModifyButton::SetBuddy(CGetFolderControl* pBuddy)
{
m_pBuddy = pBuddy;
}
BOOL CModifyButton::PreTranslateMessage(MSG* pMsg)
{
//create the tooltip
if (m_bFirstCall)
{
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);
// m_ToolTip.AddTool(this, IDS_DDXFOLDER_TT_MODIFY);
m_bFirstCall = FALSE;
}
//give the tooltip a chance to handle the message
m_ToolTip.RelayEvent(pMsg);
return CButton::PreTranslateMessage(pMsg);
}
void CModifyButton::OnClicked()
{
if (m_pBuddy)
m_pBuddy->Edit();
else
TRACE(_T("CModifyButton: No auto buddy defined\n"));
}
BEGIN_MESSAGE_MAP(CGetFolderControl, CEdit)
//{{AFX_MSG_MAP(CGetFolderControl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CGetFolderControl::CGetFolderControl()
{
}
BOOL CGetFolderControl::SubclassEdit(HWND hEdit)
{
//test our inputs
ASSERT(this);
if (!IsWindow(hEdit))
{
ASSERT(FALSE);
TRACE(_T("CGetFolderControl::SubclassEdit -- window handle is invalid!\n"));
return FALSE;
}
//subclass the control
if (SubclassWindow(hEdit))
return AddEditButton();
else
{
TRACE(_T("CGetFolderControl::SubclassEdit -- Could not subclass edit control!\n"));
ASSERT(FALSE);
return FALSE;
}
}
BOOL CGetFolderControl::AddEditButton()
{
return true;
}
void CGetFolderControl::Edit()
{
CChooseDirDlg dlg;
m_sPath.Format("%s", "c:\\");
if (!dlg.GetDirectory(m_sPath, this, (m_dwFlags & GFLDR_OLD_STYLE_DIALOG), m_sDialogTitle)){
m_sPath.Empty();
}
}
CString CGetFolderControl::GetFolder() const
{
return m_sPath;
}
void CGetFolderControl::SetFolder(const CString& sFolder)
{
CString sText(sFolder);
//Remove any trailing slashes if there is any
if (!sText.IsEmpty())
{
int nLength = sText.GetLength();
if (sText[nLength-1] == _T('\\'))
sText = sText.Left(nLength - 1);
}
SetWindowText(sText);
}
void DDX_FolderControl(CDataExchange* pDX, int nIDC, CGetFolderControl& rCGetFolderControl, DWORD dwFlags, const CString& sDialogTitle)
{
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
if (!pDX->m_bSaveAndValidate && rCGetFolderControl.m_hWnd == NULL) // not subclassed yet
{
if (!rCGetFolderControl.SubclassEdit(hWndCtrl))
{
ASSERT(FALSE); // possibly trying to subclass twice ?
AfxThrowNotSupportedException();
}
}
rCGetFolderControl.SetFlags(dwFlags);
rCGetFolderControl.SetDialogTitle(sDialogTitle);
}
void DDX_FolderValue(CDataExchange* pDX, CGetFolderControl& rCGetFolderControl, CString& sFolder)
{
if (pDX->m_bSaveAndValidate)
sFolder = rCGetFolderControl.GetFolder();
else
rCGetFolderControl.SetFolder(sFolder);
}
void DDV_FolderControl(CDataExchange* pDX, CGetFolderControl& rCGetFolderControl, DWORD dwFlags)
{
if (dwFlags & GFLDR_FOLDER_MUST_EXIST)
{
BOOL bFolderExists = FALSE;
CString sFolder = rCGetFolderControl.GetFolder();
//Check to see if the folder exists
DWORD dwAttributes = GetFileAttributes(sFolder);
if (dwAttributes != 0xFFFFFFFF)
bFolderExists = ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
if (!pDX->m_bSaveAndValidate && !bFolderExists)
{
TRACE0("Warning: initial dialog data contains a non - existant folder.\n");
return; // don't stop now
}
if (pDX->m_bSaveAndValidate && !bFolderExists)
{
//AfxMessageBox(IDS_DDXFOLDER_REQUIRE_VALID_FOLDER);
pDX->PrepareEditCtrl(rCGetFolderControl.GetDlgCtrlID());
pDX->Fail();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -