• 获取GetOpenFileName多选文件名


     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 ] = '';
    36         nLen = lstrlen(szPath);
    37 
    38         if( szPath[nLen-1] != '\' )   //如果选了多个文件,则必须加上'\'
    39         {
    40             lstrcat(szPath, TEXT("\"));
    41         }
    42 
    43 
    44         p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
    45 
    46 
    47         while( *p )
    48         { 
    49             ZeroMemory(szFileName, sizeof(szFileName));
    50             lstrcat(szFileName, szPath);  //给文件名加上路径  
    51             lstrcat(szFileName, p);    //加上文件名    
    52             lstrcat(szFileName, TEXT("/n")); //换行 
    53             p += lstrlen(p) +1;     //移至下一个文件
    54         }
    55     }
    56     MessageBox(NULL, szFileName, TEXT("MultiSelect"), MB_OK); 
    57 }    
  • 相关阅读:
    you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(255), sort integer not null
    mysql导出数据到excel的两种方式
    java8 foreach不能使用break、countinue
    学习rabbitmq
    shell脚本基础
    编程基础;程序的执行方式;编程基本概念
    定制vim的工作特性
    使用多个“窗口”
    多文件模式
    可视化模式
  • 原文地址:https://www.cnblogs.com/chechen/p/3863802.html
Copyright © 2020-2023  润新知