开发者

How to get the FolderPath in MFC application

开发者 https://www.devze.com 2022-12-13 04:47 出处:网络
I am using visual studio 2008...I am tryin to get the folder path for my output 开发者_JS百科file in my design ...I know there is a class called CFolderDialog ..but its not working in my pgm..should I

I am using visual studio 2008...I am tryin to get the folder path for my output 开发者_JS百科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


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.

}

0

精彩评论

暂无评论...
验证码 换一张
取 消