CAA中选择文件或文件夹

#include "Shlobj.h"

注:以下参考C++对应的操作方式,在CAA中可用

//选择文件夹

{
    TCHAR szBuffer[MAX_PATH] = {0};
    BROWSEINFO bi;
    ZeroMemory(&bi,sizeof(BROWSEINFO));   
    bi.hwndOwner = NULL;   
    bi.pszDisplayName = szBuffer;   
    bi.lpszTitle = _T("选择生成的Excel文件所在文件夹:");   
    bi.ulFlags = BIF_RETURNONLYFSDIRS;//BIF_BROWSEINCLUDEFILES;   
    LPITEMIDLIST idl = SHBrowseForFolder(&bi);   
    if (NULL == idl)
    {   
        return;   
    }   
    SHGetPathFromIDList(idl,szBuffer); 

    int iLength = WideCharToMultiByte(CP_ACP, 0, szBuffer, -1, NULL, 0, NULL, NULL);  
    //将tchar值赋给_char
    char tablePath[500] = {};
    WideCharToMultiByte(CP_ACP, 0, szBuffer, -1, tablePath, iLength, NULL, NULL);

    CATUnicodeString tablePathStr = tablePath;

}

//选择文件

{
    TCHAR szBuffer[MAX_PATH] = {0};   
    BROWSEINFO bi;   
    ZeroMemory(&bi,sizeof(BROWSEINFO));   
    bi.hwndOwner = NULL;   
    bi.pszDisplayName = szBuffer;   
    bi.lpszTitle = _T("从下面选择文件或文件夹:");   
    bi.ulFlags = BIF_BROWSEINCLUDEFILES;   
    LPITEMIDLIST idl = SHBrowseForFolder(&bi);   
      
    SHGetPathFromIDList(idl,szBuffer);   
        
        int iLength = WideCharToMultiByte(CP_ACP, 0, szBuffer, -1, NULL, 0, NULL, NULL);  
        //将tchar值赋给_char
        char tablePath[500] = {};
        WideCharToMultiByte(CP_ACP, 0, szBuffer, -1, tablePath, iLength, NULL, NULL);

        CATUnicodeString tablePathStr = tablePath;

}

猜你喜欢

转载自blog.csdn.net/c_I_always/article/details/82585405