📄 excep3.cpp
字号:
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
//
// excep3.cpp. Test program for exception handling.
// compile this program with the following command line
//
// cl -GX excep3.cpp user32.lib comdlg32.lib
//
// The -GX enables exception handling. The user32.lib
// provides the MessageBox function. comdlg32 is used
// for the open/save file common dialog box.
//
FILE *TestFileFunc (char *szFile);
class COpenFile
{
public:
COpenFile();
~COpenFile();
OPENFILENAME m_ofn;
int m_errno;
int GetFileName (char *szName, int nSize);
};
main ()
{
char fn[_MAX_PATH] = {"DooWop.Diddly"};
FILE *fp;
while (1)
{
try
{
fp = TestFileFunc (fn);
break;
}
catch (COpenFile *of)
{
int nResult = of->GetFileName (fn, _MAX_PATH);
delete of;
if (nResult == IDCANCEL)
return (-1);
}
}
fclose (fp);
cout << "Open file " << fn << endl;
}
FILE *TestFileFunc(char *szFile)
{
FILE *fp = fopen (szFile, "rb");
if (fp == NULL)
{
int err = errno;
COpenFile *of = new COpenFile;
of->m_errno = err;
throw (of);
}
return (fp);
}
COpenFile::COpenFile()
{
memset (&m_ofn, '\0', sizeof (OPENFILENAME));
m_ofn.lStructSize = sizeof (OPENFILENAME);
}
COpenFile::~COpenFile()
{
}
int COpenFile::GetFileName (char *szName, int nSize)
{
m_ofn.lpstrFile = szName;
m_ofn.nMaxFile = nSize;
m_ofn.lpstrTitle = "Open a File";
m_ofn.lpstrFilter = "All files (*.*)\0*.*\0";
BOOL bResult = GetOpenFileName (&m_ofn);
return (bResult ? IDOK : IDCANCEL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -