Windows系统自带选择文件的对话重写和居中处理
class CMyFileDialog: public CFileDialogImpl<CMyFileDialog> { public: CMyFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, HWND hWndParent = NULL) : CFileDialogImpl<CMyFileDialog>(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent){ } // Maps BEGIN_MSG_MAP(CMyFileDialog) CHAIN_MSG_MAP(CFileDialogImpl<CMyFileDialog>) END_MSG_MAP() //重载此函数;实现居中 void OnInitDone ( LPOFNOTIFY lpon ) { GetFileDialogWindow().CenterWindow(lpon->lpOFN->hwndOwner); } };
重写FileDialog,重载OnInitDone,实现居中,引用代码如下:
void xxx::SelectUpgradeFile() { char szFilters[] = _T("升级文件 (*.ram)\0*.ram\0全部文件(*.*)\0*.*\0\0"); CMyFileDialog fileDlg(TRUE,NULL, NULL,OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,szFilters );//szFilters char strBuffer[MAX_PATH] = {0}; fileDlg.m_ofn.lpstrFile = strBuffer; fileDlg.m_ofn.nMaxFile = MAX_PATH; if (fileDlg.DoModal() != IDOK) { ImmsMessageBox(m_PaintManager.GetPaintWindow(),_T("升级设备失败!"),_T("提示"),MB_OK); return ; } m_strEquipmentUpgradeFileName = fileDlg.m_ofn.lpstrFile; if (m_strEquipmentUpgradeFileName.Right(4).CompareNoCase(".ram")!=0) { ImmsMessageBox(m_PaintManager.GetPaintWindow(),_T("选择的文件不是编解码器升级文件!"),_T("提示"),MB_OK|MB_ICONERROR); return ; } CEditUI *pFileName = static_cast<CEditUI *>(m_PaintManager.FindControl(ctrl_device_data_manager_decoder_equi_upgrade_select_file)); if(!pFileName) return; pFileName->SetText(m_strEquipmentUpgradeFileName); }