1 void CWriteWnd::OpenFileDialog() 2 { 3 OPENFILENAME ofn; 4 TCHAR szOpenFileNames[80*MAX_PATH] = _T(""); 5 TCHAR szPath[MAX_PATH]; 6 TCHAR szFileName[80*MAX_PATH]; 7 8 TCHAR* p; 9 int nLen = 0; 10 ZeroMemory(&ofn, sizeof(ofn)); 11 12 ofn.lStructSize = sizeof(ofn); 13 ofn.hwndOwner = *this; 14 ofn.lpstrFile = szOpenFileNames; 15 ofn.nMaxFile = sizeof(szOpenFileNames); 16 ofn.lpstrFilter = _T("自设文件类型(*.*) *.* 所有文件(*.*) *.* ") ; 17 ofn.nFilterIndex = 1; 18 ofn.lpstrFileTitle = NULL; 19 ofn.nMaxFileTitle = 0; 20 ofn.lpstrInitialDir = NULL; 21 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |OFN_ALLOWMULTISELECT; 22 23 24 25 if( GetOpenFileName( &ofn ) ) 26 { 27 //把第一个文件名前的复制到szPath,即: 28 //如果只选了一个文件,就复制到最后一个'/' 29 //如果选了多个文件,就复制到第一个NULL字符 30 lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset ); 31 32 //当只选了一个文件时,下面这个NULL字符是必需的. 33 //这里不区别对待选了一个和多个文件的情况 34 35 szPath[ ofn.nFileOffset ] = '