2009-11-28 4 views
0

J'utilise Visual Studio 2008 ... J'essaye d'obtenir le chemin du dossier pour mon fichier de sortie dans ma conception ... Je sais qu'il existe une classe appelée CFolderDialog ..mais son ne fonctionne pas dans mon pgm..dois-je inclure un fichier en-tête inorder pour obtenir that..if OUI, quelqu'un peut-il me dire comment inclure dans Visual Studio 2008..plz m'aiderComment obtenir le FolderPath dans l'application MFC

+0

De quelle manière est-il ne fonctionne pas? Veuillez donner plus de détails, par exemple une erreur de compilation. Et peut-être montrer du code. –

+0

plz consulter mon code ci-dessous – kiddo

Répondre

0

Oubliez le CFolderdialog..instead de that..iam en utilisant un autre pour obtenir le chemin du dossier ... vérifier mon code ci-dessous .... j'obtiens une erreur d'exécution lorsque j'essaie d'imprimer le nom du chemin du dossier dans une boîte d'édition.

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; 

} int CALLBACK BrowseCallbackProc statique (HWND hwnd, UINT uMsg, lParam lParam, lParam lpData) {// Si le message est reçu BFFM_INITIALIZED // définir le chemin vers le chemin de départ. interrupteur (uMsg) { cas BFFM_INITIALIZED: { if (! = NULL lpData) { SendMessage (hwnd, BFFM_SETSELECTION, TRUE, lpData); }} }

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

}

Questions connexes