void CChildFrame::OnFileOpen() { // szFilters is a text string that includes two file name filters: // "*.my" for "MyType Files" and "*.*' for "All Files." char CChildFrame::szFilters[]= "MyType Files (*.my)|*.my|All Files (*.*)|*.*||"; // Create an Open dialog; the default file name extension is ".my". CFileDialog fileDlg (TRUE, "my", "*.my", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this); fileDlg .m_ofn.Flags=OFN_EXPLORER; // Display the file dialog. When user clicks OK, fileDlg.DoModal() // returns IDOK. if( fileDlg.DoModal ()==IDOK ) { CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here. ... //Change the window's title to the opened file's title. CString fileName = fileDlg.GetFileTitle ();
SetWindowText(fileName); }}
CFileDialog类或 GetOpenFileName()函数
按你的图应该是:void CMyFileOpenDlg::OnButtonNew() { // TODO: Add your control notification handler code here char fileName[MAX_PATH]=""; CExpFileOpen dlgFile(TRUE); //if use new style! OSVERSIONINFO VersionInformation; GetVersionEx(&VersionInformation); if(VersionInformation.dwMajorVersion >= 5) dlgFile.m_ofn.lStructSize=88;// new =88 else dlgFile.m_ofn.lStructSize=76;// old =76 //do not use it ! dlgFile.m_ofn.Flags |= OFN_ENABLETEMPLATEHANDLE; dlgFile.m_ofn.Flags |= OFN_ENABLETEMPLATE;// add our temp ! dlgFile.m_ofn.lpstrTitle = "Explorer Style Open File"; dlgFile.m_ofn.lpstrFile = fileName; dlgFile.m_ofn.Flags |= OFN_EXPLORER; //'Clip siblings' 'Child' 'None' '3Dlook' 'Control' 'Visible' dlgFile.m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EX_OPEN); //=1547! dlgFile.m_ofn.hInstance=AfxGetInstanceHandle(); dlgFile.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0"; dlgFile.m_ofn.lpstrDefExt = "txt"; // show dlgFile.DoModal(); #ifdef _DEBUG afxDump << fileName << " \n"; #endif }注意: dlgFile.m_ofn.lStructSize=88;// new =88 就是你要的格式
{
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
char CChildFrame::szFilters[]=
"MyType Files (*.my)|*.my|All Files (*.*)|*.*||"; // Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "my", "*.my",
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
fileDlg .m_ofn.Flags=OFN_EXPLORER;
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here.
...
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle ();
SetWindowText(fileName);
}}
GetOpenFileName()函数
{
// TODO: Add your control notification handler code here
char fileName[MAX_PATH]="";
CExpFileOpen dlgFile(TRUE);
//if use new style!
OSVERSIONINFO VersionInformation;
GetVersionEx(&VersionInformation);
if(VersionInformation.dwMajorVersion >= 5)
dlgFile.m_ofn.lStructSize=88;// new =88
else
dlgFile.m_ofn.lStructSize=76;// old =76
//do not use it ! dlgFile.m_ofn.Flags |= OFN_ENABLETEMPLATEHANDLE;
dlgFile.m_ofn.Flags |= OFN_ENABLETEMPLATE;// add our temp !
dlgFile.m_ofn.lpstrTitle = "Explorer Style Open File";
dlgFile.m_ofn.lpstrFile = fileName;
dlgFile.m_ofn.Flags |= OFN_EXPLORER;
//'Clip siblings' 'Child' 'None' '3Dlook' 'Control' 'Visible'
dlgFile.m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EX_OPEN); //=1547!
dlgFile.m_ofn.hInstance=AfxGetInstanceHandle();
dlgFile.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0";
dlgFile.m_ofn.lpstrDefExt = "txt";
// show
dlgFile.DoModal();
#ifdef _DEBUG
afxDump << fileName << " \n";
#endif
}注意:
dlgFile.m_ofn.lStructSize=88;// new =88
就是你要的格式
哪个类里面的,是未公开API吗
// dlgFile.m_ofn.Flags |= OFN_ENABLETEMPLATE;// add our temp !
// dlgFile.m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EX_OPEN); //=1547!
// dlgFile.m_ofn.hInstance=AfxGetInstanceHandle();