📄 openmultifiledlg.cpp
字号:
// MyFileDialog.cpp : implementation file
//
#include "stdafx.h"
#include "MyFolder.h"
#include "OpenMultiFileDlg.h"
#include <afxodlgs.h> // MFC OLE dialog classes
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAXMULTIPATH 260//保存文件名的缓冲区的最大长度
/////////////////////////////////////////////////////////////////////////////
// COpenMultiFileDlg
IMPLEMENT_DYNAMIC(COpenMultiFileDlg, CFileDialog)
COpenMultiFileDlg::COpenMultiFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)//派生类构造函数必须调用基类构造函数。
{
m_pszFileName=new TCHAR[MAXMULTIPATH];
m_pszFileName[0]='\0';
}
COpenMultiFileDlg::~COpenMultiFileDlg()
{
if(m_pszFileName!=NULL)
delete []m_pszFileName;//释放m_pszFileName
}
int COpenMultiFileDlg::DoModal()//m_ofn是win32openfiledialog的一个实例。
{
ASSERT_VALID(this);
ASSERT(m_ofn.Flags&OFN_ALLOWMULTISELECT);//支持打开多个文件
m_ofn.lpstrFile=m_pszFileName;
m_ofn.nMaxFile=MAXMULTIPATH;//路径及文件名最大字符数,(260)
return CFileDialog::DoModal();
}
BEGIN_MESSAGE_MAP(COpenMultiFileDlg, CFileDialog)
//{{AFX_MSG_MAP(COpenMultiFileDlg)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////
// This is where the real action is going on
// Remember #include <dlgs.h>
BOOL COpenMultiFileDlg::OnInitDialog() // Override
{
const UINT iExtraSize = 150;//增加Dialog窗口长度
// Number of controls in the File Dialog
const UINT nControls = 7;
// Get a pointer to the original dialog box.
CWnd *wndDlg = GetParent();//得到CFileDialog指针
RECT Rect;
wndDlg->GetWindowRect(&Rect);
// Change the size
wndDlg->SetWindowPos(NULL, 0, 0,
Rect.right - Rect.left, //原来对话框宽度
Rect.bottom - Rect.top + iExtraSize, //原来对话框长度+iExtraSize
SWP_NOMOVE);
// Control ID's - defined in <dlgs.h>
UINT Controls[nControls] = {stc3, stc2, // The two label controls
edt1, cmb1, // The eidt control and the drop-down box
IDOK, IDCANCEL,
lst1}; // Explorer vinduet
// Go through each of the controls in the dialog box, and move them to a new position
for (int i=0 ; i<nControls ; i++)
{
CWnd *wndCtrl = wndDlg->GetDlgItem(Controls[i]);
wndCtrl->GetWindowRect(&Rect);
wndDlg->ScreenToClient(&Rect); // Remember it is child controls
// Move all the controls according to the new size of the dialog.
if (Controls[i] != lst1)
wndCtrl->SetWindowPos(NULL,
Rect.left, Rect.top + iExtraSize,
0, 0, SWP_NOSIZE);
else // This is the explorer like window. It should be sized - not moved.
wndCtrl->SetWindowPos(NULL, 0, 0,
Rect.right - Rect.left,
Rect.bottom - Rect.top + iExtraSize,
SWP_NOMOVE);
}
// Remember to call the baseclass.
return CFileDialog::OnInitDialog();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -