获取GetOpenFileName多选文件名
来源:互联网 发布:金山 雷军 知乎 编辑:程序博客网 时间:2024/05/16 20:31
- OPENFILENAME ofn;
- TCHAR szOpenFileNames[80*MAX_PATH];
- TCHAR szPath[MAX_PATH];
- TCHAR szFileName[80*MAX_PATH];
-
- TCHAR* p;
- int nLen = 0;
- ZeroMemory( &ofn, sizeof(ofn) );
-
- ofn.Flags = OFN_EXPLORER | OFN_ALLOWMULTISELECT;
- ofn.lStructSize = sizeof(ofn);
- ofn.lpstrFile = szOpenFileNames;
- ofn.nMaxFile = sizeof(szOpenFileNames);
- ofn.lpstrFile[0] = '/0';
- ofn.lpstrFilter = TEXT("All Files(*.*)/0*.*/0");
-
- if( GetOpenFileName( &ofn ) )
-
- {
-
-
-
-
- lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );
-
-
-
-
- szPath[ ofn.nFileOffset ] = '/0';
- nLen = lstrlen(szPath);
-
- if( szPath[nLen-1] != '//' ) //如果选了多个文件,则必须加上'//'
-
- {
- lstrcat(szPath, TEXT("//"));
- }
-
-
- p = szOpenFileNames + ofn.nFileOffset;
- ZeroMemory(szFileName, sizeof(szFileName));
-
- while( *p )
- {
- lstrcat(szFileName, szPath);
- lstrcat(szFileName, p);
- lstrcat(szFileName, TEXT("/n"));
- p += lstrlen(p) +1;
- }
- MessageBox(NULL, szFileName, TEXT("MultiSelect"), MB_OK);
- }