如何在MFC应用程序中获取FolderPath

发布于 2024-08-12 23:11:45 字数 167 浏览 3 评论 0原文

我正在使用 Visual Studio 2008...我正在尝试在设计中获取输出文件的文件夹路径...我知道有一个名为 CFolderDialog 的类..但它在我的 pgm 中不起作用..我应该包含任何头文件才能得到这个..如果是的话,任何人都可以告诉我如何包含在 Visual Studio 2008 中..请帮助我

I am using visual studio 2008...I am tryin to get the folder path for my output file in my design ...I know there is a class called CFolderDialog ..but its not working in my pgm..should I include any header file inorder to get that..if YES,can anybody tell me how to include in visual studio 2008..plz help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2024-08-19 23:11:45

忘记 CFolderdialog..而不是那个..iam 使用另一个来获取文件夹路径...检查下面的代码...当我尝试在编辑框中打印文件夹路径名称时出现运行时错误..

无效 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)
{
浏览信息bi = { 0 };
LPITEMIDLIST pidl;
TCHAR szDisplay[256];
BOOL 检索;

//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;

}
静态 int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData)
{
// 如果收到 BFFM_INITIALIZED 消息
// 将路径设置为起始路径。
开关(uMsg)
{
案例 BFFM_INITIALIZED:
{
if (NULL != lpData)
{
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
}
}
}

return 0; // The function should always return 0.

}

Forget about the CFolderdialog..instead of that..iam using another 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 should always return 0.

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文