BCB 带有可新建文件夹的选择目录对话框,SHBrowseForFolder | 您所在的位置:网站首页 › vc对话框打开view › BCB 带有可新建文件夹的选择目录对话框,SHBrowseForFolder |
#define NO_WIN32_LEAN_AND_MEAN #include #include //以上这三个要放在.cpp文件的最上边 //--------------------------------------------------------------------------- #include bool __fastcall CrnBrowserDir(HANDLE hWin, LPSTR lpCaption, LPSTR lpDir, LPSTR lpDispName){ BROWSEINFO bi; LPITEMIDLIST pidl; LPMALLOC pShellMalloc; bool bRet = false; if(SHGetMalloc(&pShellMalloc) == NO_ERROR) { memset(&bi, 0x00, sizeof(bi)); bi.hwndOwner = hWin; // Owner window bi.pidlRoot = 0; // root folder bi.pszDisplayName = lpDispName; // return display name bi.lpszTitle = lpCaption; // label caption bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; // config flags bi.lpfn = 0; // callback function pidl = SHBrowseForFolder(&bi); if(pidl) { if(SHGetPathFromIDList(pidl, lpDir)) bRet = true; pShellMalloc->Free(pidl); } pShellMalloc->Release(); } return bRet;}//---------------------------------------------------------------------------// 调用代码:void __fastcall TForm1::Button1Click(TObject *Sender){ char lpDir[MAX_PATH]; char lpDispName[MAX_PATH]; bool bRet = CrnBrowserDir(Handle, "请选择一个文件夹:", lpDir, lpDispName); if(bRet) ShowMessage(String("选择的文件夹是: ") + String(lpDir) + String("\r\n") + String("显示名称是: ") + String(lpDispName)); else ShowMessage("没有选择文件夹!");} |
CopyRight 2018-2019 实验室设备网 版权所有 |