📄 filedialogex.cpp
字号:
// FileDialogEx.cpp : implementation file
//
#include "stdafx.h"
#include "Ex050203.h"
#include "FileDialogEx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileDialogEx
IMPLEMENT_DYNAMIC(CFileDialogEx, CFileDialog)
CFileDialogEx::CFileDialogEx(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
}
BEGIN_MESSAGE_MAP(CFileDialogEx, CFileDialog)
//{{AFX_MSG_MAP(CFileDialogEx)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CFileDialogEx::OnInitDialog()
{
m_edit.SubclassDlgItem(IDC_FILEINFO, this);//子类化编辑框
return CFileDialog::OnInitDialog();
}
int CFileDialogEx::DoModal()
{
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEDIALOG);
m_ofn.Flags |= OFN_ENABLETEMPLATE;//增加自定义的子对话框
return CFileDialog::DoModal();
}
void CFileDialogEx::OnFileNameChange()
{
ShowFileInfo();
}
void CFileDialogEx::OnFolderChange()
{//选择新文件夹
ShowFileInfo();
}
void CFileDialogEx::OnTypeChange()
{//选择新文件类型
ShowFileInfo();
}
void CFileDialogEx::ShowFileInfo()
{//显示文件信息
CString strFileName = GetPathName();
if(strFileName.IsEmpty())
return ;
//取得文件大小
CFileStatus rStatus ;
CFile::GetStatus(strFileName,rStatus);
CString strInfo ;
strInfo.Format("当前选中文件是%s\r\n文件大小是%d",strFileName,rStatus.m_size);
m_edit.SetWindowText(strInfo);
}
void CFileDialogEx::OnSize(UINT nType, int cx, int cy)
{//对话框移动时,更改编辑框的大小
CWnd* pDlg = GetParent();
if(NULL != GetSafeHwnd())
{
//取得取消按钮右边缘的坐标
CWnd* pCancel = pDlg->GetDlgItem(IDCANCEL);
ASSERT(pCancel);
CRect rcCancel;
pCancel->GetWindowRect(&rcCancel);
//取得编辑框的坐标
CRect rEdit;
m_edit.GetWindowRect(&rEdit);
rEdit.right = rcCancel.right ;
//移动编辑框坐标
ScreenToClient(&rEdit);
m_edit.MoveWindow(&rEdit);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -