SHBrowseForFolder() (bis)
-
hi everyone, I know, I already asked about that topic, but I still can't get it to work. the problem was that i want the dialog opened by SHBrowseForFolder() to get opened on a specified folder. here is the code i wrote :
void CFileRenamerDlg::OnBrowseFolder()
{
CoInitialize(NULL);char folderBuf\[MAX\_PATH\]; LPITEMIDLIST pidl = NULL;
/*
ULONG ul;
TCHAR strFolderT[MAX_PATH];
_tcscpy(strFolderT, m_strFolder);
WCHAR strFolderW[MAX_PATH] = A2W(strFolderT);
::SHParseDisplayName(strFolderW, NULL, &pidl, SFGAO_FOLDER, &ul);
*/
BROWSEINFO bi;
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.pszDisplayName = folderBuf;
bi.lpszTitle = _T("Select the folder where your files are located in...");
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE;
bi.lpfn = NULL;
pidl = SHBrowseForFolder(&bi);
if (pidl != NULL) {
SHGetPathFromIDList(pidl, folderBuf);
m_Directory.SetWindowText(folderBuf);
m_strFolder = folderBuf;
}
}for your information,
m_strFolder
is declared as aCString
. this compiles fine, but always starts on the desktop. if I uncomment what is commented, the compiler (VC7.1) complains about theA2W()
macro (actually, not directly the macro, but the "variables" used within). did anybody already encountered this ? can anyone suggest a better way (if any) to get SHBrowseForFolder() to get opened on a specified folder ? thanks in advance. -
hi everyone, I know, I already asked about that topic, but I still can't get it to work. the problem was that i want the dialog opened by SHBrowseForFolder() to get opened on a specified folder. here is the code i wrote :
void CFileRenamerDlg::OnBrowseFolder()
{
CoInitialize(NULL);char folderBuf\[MAX\_PATH\]; LPITEMIDLIST pidl = NULL;
/*
ULONG ul;
TCHAR strFolderT[MAX_PATH];
_tcscpy(strFolderT, m_strFolder);
WCHAR strFolderW[MAX_PATH] = A2W(strFolderT);
::SHParseDisplayName(strFolderW, NULL, &pidl, SFGAO_FOLDER, &ul);
*/
BROWSEINFO bi;
bi.hwndOwner = this->GetSafeHwnd();
bi.pidlRoot = pidl;
bi.pszDisplayName = folderBuf;
bi.lpszTitle = _T("Select the folder where your files are located in...");
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_SHAREABLE;
bi.lpfn = NULL;
pidl = SHBrowseForFolder(&bi);
if (pidl != NULL) {
SHGetPathFromIDList(pidl, folderBuf);
m_Directory.SetWindowText(folderBuf);
m_strFolder = folderBuf;
}
}for your information,
m_strFolder
is declared as aCString
. this compiles fine, but always starts on the desktop. if I uncomment what is commented, the compiler (VC7.1) complains about theA2W()
macro (actually, not directly the macro, but the "variables" used within). did anybody already encountered this ? can anyone suggest a better way (if any) to get SHBrowseForFolder() to get opened on a specified folder ? thanks in advance.super_ttd wrote:
[...] the compiler (VC7.1) complains about the A2W() macro [...]
Try the newer improved
CA2W
macro. Actually I think you needCT2W
macro. The correct shortest usage:::SHParseDisplayName(CT2W(m_strFolder), . . .
Then try the rest of the code again. I hope this helps.
-
super_ttd wrote:
[...] the compiler (VC7.1) complains about the A2W() macro [...]
Try the newer improved
CA2W
macro. Actually I think you needCT2W
macro. The correct shortest usage:::SHParseDisplayName(CT2W(m_strFolder), . . .
Then try the rest of the code again. I hope this helps.
thanks for you answer. however, I have to add some more details. actually, my A2W() was a mistake when I posted the message. I actually used T2W(), but not CT2W() because SHParseDisplayName() waits for a LPWSTR. hum, not i'm checking the msdn and it tells me a LPCWSTR, but intellisense was telling LPWSTR. which to believe, and how to solve that ?
-
thanks for you answer. however, I have to add some more details. actually, my A2W() was a mistake when I posted the message. I actually used T2W(), but not CT2W() because SHParseDisplayName() waits for a LPWSTR. hum, not i'm checking the msdn and it tells me a LPCWSTR, but intellisense was telling LPWSTR. which to believe, and how to solve that ?
-
Since
SHParseDisplayName
requiresLPCWSTR
, the proposed solution should work:::SHParseDisplayName(CT2W(m_strFolder), . . .);
-
yup, I think so (but i have no compiler for the moment, so I'll give you feedback tomorrow when I test it at home. By the way, why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ? :confused:
-
yup, I think so (but i have no compiler for the moment, so I'll give you feedback tomorrow when I test it at home. By the way, why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ? :confused:
super_ttd wrote:
...why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ?
Because that is the way the function is defined. :)
-
super_ttd wrote:
...why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ?
Because that is the way the function is defined. :)
-
did you read the other posts of the thread ? boths ways are how the function is defined ! the problem is one is the doc online, and the other is what i'm using in my code.
super_ttd wrote:
boths ways are how the function is defined
My point is as far as the compiler knows, at the point of the call there is only 1 definition. Are you sure you didn't see LPCWSTR with intellisense? Same thing as PCWSTR. I can't find any old reference (in header files) to SHParseDisplayName() taking anything but a const WCHAR * as the first argument. The L part of the macro is a holdover from Win16 days.
-
super_ttd wrote:
[...] the compiler (VC7.1) complains about the A2W() macro [...]
Try the newer improved
CA2W
macro. Actually I think you needCT2W
macro. The correct shortest usage:::SHParseDisplayName(CT2W(m_strFolder), . . .
Then try the rest of the code again. I hope this helps.
hello Viorel, then i tried your sample, and it does compile. but the behavior is not the one expected. :^) actually, it does open the "browse for folder" dialogBox, but the folder in m_
strFolder
is drawn as the root folder. what i wanted to have is still have the desktop folder as the root (exactly as if pidl was set to NULL), but withm_strFolder
folder selected (the tree expanded to that folder). another weird thing is thatSHParseDisplayName()
is available only since WindowsXP. wasn't it possible to have such a behavior on Windows 2000 ?! :wtf: thanks for your contribution... ;) see you