#include "pch.h"
#include "GenericBkMFC.h"
#include "DlgFileDialogST.h"

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

CDlgFileDialogST::CDlgFileDialogST(CWnd* pParent, CResourceServerST*	m_pIcons)
	: CDialog(CDlgFileDialogST::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgFileDialogST)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	m_pIconsDLL = m_pIcons;
}

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

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

BEGIN_MESSAGE_MAP(CDlgFileDialogST, CDialog)
	//{{AFX_MSG_MAP(CDlgFileDialogST)
	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 CDlgFileDialogST::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Buttons
	m_btnOpen.SetShade(CShadeButtonST::SHS_HBUMP, 8, 20, 5, RGB(55, 55, 255));
	m_btnOpen.SetIcon(m_pIconsDLL->LoadIcon(DLL_IDI_GENERAL_FOLDER05, 48, 48));
	//
	m_btnSave.SetShade(CShadeButtonST::SHS_HBUMP, 8, 20, 5, RGB(55, 55, 255));
	m_btnSave.SetIcon(m_pIconsDLL->LoadIcon(DLL_IDI_GENERAL_FOLDER04, 48, 48));
	//
	m_btnBrowse.SetShade(CShadeButtonST::SHS_HBUMP, 8, 20, 5, RGB(55, 55, 255));
	m_btnBrowse.SetIcon(m_pIconsDLL->LoadIcon(DLL_IDI_GENERAL_FOLDER08, 48, 48));

	return TRUE;
} // End of OnInitDialog

void CDlgFileDialogST::OnOK()
{
} // End of OnOK

void CDlgFileDialogST::OnCancel()
{
} // End of OnCancel

void CDlgFileDialogST::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 CDlgFileDialogST::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 CDlgFileDialogST::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
