需要新版本的头文件。 typedef struct tagOFN { DWORD lStructSize; HWND hwndOwner; HINSTANCE hInstance; LPCTSTR lpstrFilter; LPTSTR lpstrCustomFilter; DWORD nMaxCustFilter; DWORD nFilterIndex; LPTSTR lpstrFile; DWORD nMaxFile; LPTSTR lpstrFileTitle; DWORD nMaxFileTitle; LPCTSTR lpstrInitialDir; LPCTSTR lpstrTitle; DWORD Flags; WORD nFileOffset; WORD nFileExtension; LPCTSTR lpstrDefExt; LPARAM lCustData; LPOFNHOOKPROC lpfnHook; LPCTSTR lpTemplateName; #if (_WIN32_WINNT >= 0x0500) void * pvReserved; DWORD dwReserved; DWORD FlagsEx; #endif // (_WIN32_WINNT >= 0x0500) } OPENFILENAME, *LPOPENFILENAME; Windows通过判断lStructSize和Flags来决定使用的对话框的版本。lStructSize: Windows 95/98 and Windows NT 4.0: In an application intended for Windows 95/98 or Windows NT 4.0 and that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000 and later: Use sizeof (OPENFILENAME) for this parameter. 如果Flags中包含OFN_ENABLEHOOK位,则使用旧的对话框
OPENFILENAME ofn; memset(&ofn, sizeof(ofn), 0); ofn.lStructSize = sizeof(ofn); .... // some other initialization GetOpenFileName(&ofn); CString strFileName(ofn.lpstrFile); //现在的strFileName就与CFileDialog::GetFileName的返回值一个类型了。
typedef struct tagOFN {
DWORD lStructSize;
HWND hwndOwner;
HINSTANCE hInstance;
LPCTSTR lpstrFilter;
LPTSTR lpstrCustomFilter;
DWORD nMaxCustFilter;
DWORD nFilterIndex;
LPTSTR lpstrFile;
DWORD nMaxFile;
LPTSTR lpstrFileTitle;
DWORD nMaxFileTitle;
LPCTSTR lpstrInitialDir;
LPCTSTR lpstrTitle;
DWORD Flags;
WORD nFileOffset;
WORD nFileExtension;
LPCTSTR lpstrDefExt;
LPARAM lCustData;
LPOFNHOOKPROC lpfnHook;
LPCTSTR lpTemplateName;
#if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)
} OPENFILENAME, *LPOPENFILENAME;
Windows通过判断lStructSize和Flags来决定使用的对话框的版本。lStructSize:
Windows 95/98 and Windows NT 4.0: In an application intended for Windows 95/98 or Windows NT 4.0 and that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000 and later: Use sizeof (OPENFILENAME) for this parameter. 如果Flags中包含OFN_ENABLEHOOK位,则使用旧的对话框
memset(&ofn, sizeof(ofn), 0);
ofn.lStructSize = sizeof(ofn);
.... // some other initialization
GetOpenFileName(&ofn);
CString strFileName(ofn.lpstrFile);
//现在的strFileName就与CFileDialog::GetFileName的返回值一个类型了。
char szFileName[MAX_PATH] = { 0 };
char szFileTitle[MAX_PATH] = { 0 };
OPENFILENAME ofn;
memset(&ofn, sizeof(ofn), 0);
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = szFileName;
ofn.lpstrFileTitle = szFileTitle;
.... // some other initialization
GetOpenFileName(&ofn);
CString strFileName(szFileTitle);
//现在的strFileName就与CFileDialog::GetFileName的返回值一个类型了。