#include "pch.h"
#include "framework.h"
#include "SystemWnd.h"
#include "SystemWndDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CSystemWndDlg::CSystemWndDlg(CWnd* pParent )
: CDialogEx(IDD_SYSTEMWND_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSystemWndDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSystemWndDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_SELECT, &CSystemWndDlg::OnBnClickedButtonSelect)
ON_BN_CLICKED(IDC_BUTTON_MORESELECT, &CSystemWndDlg::OnBnClickedButtonMoreselect)
END_MESSAGE_MAP()
BOOL CSystemWndDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CSystemWndDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
HCURSOR CSystemWndDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CSystemWndDlg::OnBnClickedButtonSelect()
{
CFileDialog dlg(TRUE,L"txt",NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,L"文本文件(*.txt)|*.txt|音乐文件(*.mp3)|*.mp3|所有文件(*.*)|*.*||");
if (IDCANCEL == dlg.DoModal())
return;
CString strFilePath = dlg.GetFileTitle();
SetDlgItemText(IDC_EDIT_PATH,strFilePath);
}
void CSystemWndDlg::OnBnClickedButtonMoreselect()
{
CFileDialog dlg(TRUE, L"txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT| OFN_ALLOWMULTISELECT, L"文本文件(*.txt)|*.txt|音乐文件(*.mp3)|*.mp3|所有文件(*.*)|*.*||");
if (IDCANCEL == dlg.DoModal())
return;
POSITION pos = dlg.GetStartPosition();
while (pos)
{
CString str=dlg.GetNextPathName(pos);
MessageBox(str);
}
}
选择文件夹
void CSystemWndDlg::OnBnClickedBtnSelect()
{
CFolderPickerDialog dlg;
if (IDCANCEL == dlg.DoModal())
return;
CString str = dlg.GetPathName();
SetDlgItemText(IDC_EDIT1,str);
}