无法打印 EditBox-MFC 中的文件夹路径
我正在使用以下函数..而不是 CFolderDialog.. 来获取文件夹路径...检查下面的代码...当我尝试在编辑框中打印文件夹路径名称时出现运行时错误..
无效 CSelfExtractorUIDlg::OnBnClickedButton1() {
CDialog dlg;
HWND hwnd = NULL; LPCTSTR szCurrent = (LPCTSTR)malloc(25*sizeof(TCHAR)); sz当前=空; LPTSTR szPath = (LPTSTR)malloc(25*sizeof(TCHAR));布尔值 检查= BrowseForFolder(hwnd,szCurrent,szPath); 如果(检查== TRUE){ dlg.SetDlgItemTextW(IDC_EDIT1,szPath); }
}
BOOL BrowseForFolder(HWND hwnd, LPCTSTR sz当前,LPTSTR sz路径){ 浏览信息bi = { 0 }; LPITID列表 pidl; TCHAR szDisplay[256];布尔值 检索值;
//CoInitialize();
bi.hwndOwner = hwnd; bi.pszDisplayName = szDisplay; bi.lpszTitle = TEXT("请 选择一个文件夹。"); bi.ulFlags
= BIF_RETURNONLYFSDIRS | BIF_NEWDDialogStyle;双 lpfn
= 浏览回调过程; bi.lParam = (LPARAM) szCurrent;pidl = SHBrowseForFolder(&bi);
if (NULL != pidl) { retval = SHGetPathFromIDList(pidl, szPath); CoTaskMemFree(pidl); } 别的 { retval = 假; }
如果(!retval){ szPath[0] = TEXT('\0'); }
CoUninitialize();返回retval;
} 静态 int 回调 BrowseCallbackProc(HWND hwnd,UINT uMsg、LPARAM lParam、LPARAM lpData) { // 如果 BFFM_INITIALIZED 消息是 receive // 设置起始路径 路径。
开关 (uMsg) { 案例 BFFM_INITIALIZED: { if (NULL != lpData) { SendMessage(hwnd, BFFM_SETSELECTION,真,lpData); } } }返回0; // 函数
I am using the following function ..instead of CFolderDialog.. to get the folder path...check my code below....am getting a run time error when i try toprint the folder path name in a edit box..
void
CSelfExtractorUIDlg::OnBnClickedButton1()
{CDialog dlg;
HWND hwnd = NULL; LPCTSTR szCurrent =
(LPCTSTR)malloc(25*sizeof(TCHAR));
szCurrent = NULL; LPTSTR szPath =
(LPTSTR)malloc(25*sizeof(TCHAR)); BOOL
check =
BrowseForFolder(hwnd,szCurrent,szPath);
if( check == TRUE) {
dlg.SetDlgItemTextW(IDC_EDIT1,szPath);
}}
BOOL BrowseForFolder(HWND hwnd,
LPCTSTR szCurrent, LPTSTR szPath) {
BROWSEINFO bi = { 0 }; LPITEMIDLIST
pidl; TCHAR szDisplay[256]; BOOL
retval;//CoInitialize();
bi.hwndOwner = hwnd;
bi.pszDisplayName = szDisplay;
bi.lpszTitle = TEXT("Please
choose a folder."); bi.ulFlags
= BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; bi.lpfn
= BrowseCallbackProc; bi.lParam = (LPARAM) szCurrent;pidl = SHBrowseForFolder(&bi);
if (NULL != pidl) {
retval = SHGetPathFromIDList(pidl, szPath);
CoTaskMemFree(pidl); } else {
retval = FALSE; }if (!retval) {
szPath[0] = TEXT('\0'); }CoUninitialize(); return retval;
} static int CALLBACK
BrowseCallbackProc(HWND hwnd,UINT
uMsg, LPARAM lParam, LPARAM lpData)
{
// If the BFFM_INITIALIZED message is
received // set the path to the start
path.
switch (uMsg) { case
BFFM_INITIALIZED: { if (NULL !=
lpData) { SendMessage(hwnd,
BFFM_SETSELECTION, TRUE, lpData); }
} }return 0; // The function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
25 个字符对于完整路径长度来说似乎有点短,我会使用 MAX_PATH。
25 characters seems a little short for a full path length, I'd use MAX_PATH.