Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / MFC

CFileDialogST v1.0

Rate me:
Please Sign up or sign in to vote.
4.89/5 (17 votes)
25 Jun 20013 min read 185.4K   4.9K   59  
A CFileDialog implementation using APIs.
#include "stdafx.h"
#include "CFileDialogST_demo.h"
#include "CFileDialogST_demoDlg.h"

#include "FileDialogST.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define IDS_MAILADDR	_T("mailto:davide_calabro@yahoo.com")
#define IDS_WEBADDR		_T("http://members.tripod.com/~SoftechSoftware/index.html")

CCFileDialogST_demoDlg::CCFileDialogST_demoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCFileDialogST_demoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCFileDialogST_demoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCFileDialogST_demoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCFileDialogST_demoDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	DDX_Control(pDX, IDOK, m_btnClose);
	DDX_Control(pDX, IDC_OPEN, m_btnOpen);
	DDX_Control(pDX, IDC_SAVE, m_btnSave);
	DDX_Control(pDX, IDC_BROWSE, m_btnBrowse);

	DDX_Control(pDX, IDC_EMAILLINK, m_EMailLink);
	DDX_Control(pDX, IDC_HOMEPAGELINK, m_HomePageLink);
}

BEGIN_MESSAGE_MAP(CCFileDialogST_demoDlg, CDialog)
	//{{AFX_MSG_MAP(CCFileDialogST_demoDlg)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CCFileDialogST_demoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);
	SetIcon(m_hIcon, FALSE);
	
	// Buttons
	m_btnClose.SetShade(CShadeButtonST::SHS_HBUMP,8,20,5,RGB(55,55,255));
	m_btnClose.SetIcon(IDI_CLOSE);
	//
	m_btnOpen.SetShade(CShadeButtonST::SHS_HBUMP,8,20,5,RGB(55,55,255));
	m_btnOpen.SetIcon(IDI_OPEN);
	//
	m_btnSave.SetShade(CShadeButtonST::SHS_HBUMP,8,20,5,RGB(55,55,255));
	m_btnSave.SetIcon(IDI_SAVE);
	//
	m_btnBrowse.SetShade(CShadeButtonST::SHS_HBUMP,8,20,5,RGB(55,55,255));
	m_btnBrowse.SetIcon(IDI_BROWSE);

	// Set HyperLink for E-Mail
	m_EMailLink.SetURL(IDS_MAILADDR);
	m_EMailLink.SetUnderline(CHyperLink::ulAlways);

	// Set HyperLink for Home Page
	m_HomePageLink.SetURL(IDS_WEBADDR);
	m_HomePageLink.SetUnderline(CHyperLink::ulAlways);

	return TRUE;
} // End of OnInitDialog

void CCFileDialogST_demoDlg::OnOpen() 
{
	CFileDialogST	dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, _T("All files\0*.*\0"), this);
	CString			sPathName;
	int				nRetValue;

	nRetValue = dlg.DoModal();
	if (nRetValue == IDOK)
	{
		POSITION	Pos;

		Pos = dlg.GetStartPosition();
		while (Pos != NULL)
		{
			sPathName = dlg.GetNextPathName(Pos);
			MessageBox(sPathName, _T("GetNextPathName"), MB_ICONINFORMATION);
		} // while
		/*
		sPathName = dlg.GetPathName();
		MessageBox(sPathName, _T("GetPathName"), MB_ICONINFORMATION);
		sPathName = dlg.GetFileName();
		MessageBox(sPathName, _T("GetFileName"), MB_ICONINFORMATION);
		sPathName = dlg.GetFileTitle();
		MessageBox(sPathName, _T("GetFileTitle"), MB_ICONINFORMATION);
		sPathName = dlg.GetFileExt();
		MessageBox(sPathName, _T("GetFileExt"), MB_ICONINFORMATION);
		sPathName = dlg.GetFileDir();
		MessageBox(sPathName, _T("GetFileDir"), MB_ICONINFORMATION);
		sPathName = dlg.GetFileDrive();
		MessageBox(sPathName, _T("GetFileDrive"), MB_ICONINFORMATION);
		*/
	} // if
} // End of OnOpen

void CCFileDialogST_demoDlg::OnSave() 
{
	CFileDialogST	dlg(FALSE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, _T("All files\0*.*\0"), this);
	CString			sPathName;
	int				nRetValue;

	nRetValue = dlg.DoModal();
	if (nRetValue == IDOK)
	{
		sPathName = dlg.GetPathName();
		MessageBox(sPathName, _T("GetPathName"), MB_ICONINFORMATION);
	} // if
} // End of OnSave

void CCFileDialogST_demoDlg::OnBrowse() 
{
	CFileDialogST	dlg;
	int				nRetValue;
	CString			sFolder;

	nRetValue = dlg.SelectFolder(_T("Please select a destination folder"), _T("c:\\"), 0x40|BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS, this);
	if (nRetValue == IDOK)
	{
		sFolder = dlg.GetSelectedFolder();
		MessageBox(sFolder, _T("GetSelectedFolder"), MB_ICONINFORMATION);
	} // if
} // End of OnBrowse

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions