EDN Admin
Well-known member
I use BFFM_SETSELECTION and BIF_NEWDIALOGSTYLE in the code below. <br/>In XP and Vista this selects the folder and scrolls the list to make the selected folder visible to the user.<br/><br/>In Windows 7 the list is not scrolled to show the selected folder.<br/><br/> Is there a workaround? (without removing BIF_NEWDIALOGSTYLE)<br/><br/><br/><br/><br/>
<div style="background-color:white;color:black
<pre><span style="color:blue int CALLBACK BrowseCallbackProc(HWND hWnd,UINT uMsg, LPARAM, LPARAM ) {
TCHAR szDir[MAX_PATH+1];
<span style="color:blue switch(uMsg) {
<span style="color:blue case BFFM_INITIALIZED:
<span style="color:blue if( ::GetCurrentDirectory( MAX_PATH, szDir))
::SendMessage(hWnd,BFFM_SETSELECTION,<span style="color:blue true,(LPARAM)szDir);
<span style="color:blue break;
}
<span style="color:blue return 0;
}
<span style="color:blue bool BrowseForFolder( HWND hParent, LPTSTR szOutPath )
{
<span style="color:blue bool bSelected = <span style="color:blue false;
{ <span style="color:green /* Gets the Shells default allocator */
LPMALLOC pMalloc;
<span style="color:blue if( SUCCEEDED:SHGetMalloc(&pMalloc)) ) {
BROWSEINFO bi; ZeroMemory(&bi,<span style="color:blue sizeof(bi));
bi.hwndOwner = hParent;
bi.ulFlags = BIF_NEWDIALOGSTYLE |
BIF_RETURNFSANCESTORS |
BIF_RETURNONLYFSDIRS;
bi.lpfn = BrowseCallbackProc;
LPITEMIDLIST pidl = ::SHBrowseForFolder(&bi);
<span style="color:blue if( pidl ) {
bSelected = ::SHGetPathFromIDList(pidl,szOutPath)!=0;
pMalloc->Free(pidl); <span style="color:green // Free the PIDL allocated by SHBrowseForFolder.
}
pMalloc->Release(); <span style="color:green // Release the shells allocator.
}
}
<span style="color:blue return bSelected;
}
[/code]
View the full article
<div style="background-color:white;color:black
<pre><span style="color:blue int CALLBACK BrowseCallbackProc(HWND hWnd,UINT uMsg, LPARAM, LPARAM ) {
TCHAR szDir[MAX_PATH+1];
<span style="color:blue switch(uMsg) {
<span style="color:blue case BFFM_INITIALIZED:
<span style="color:blue if( ::GetCurrentDirectory( MAX_PATH, szDir))
::SendMessage(hWnd,BFFM_SETSELECTION,<span style="color:blue true,(LPARAM)szDir);
<span style="color:blue break;
}
<span style="color:blue return 0;
}
<span style="color:blue bool BrowseForFolder( HWND hParent, LPTSTR szOutPath )
{
<span style="color:blue bool bSelected = <span style="color:blue false;
{ <span style="color:green /* Gets the Shells default allocator */
LPMALLOC pMalloc;
<span style="color:blue if( SUCCEEDED:SHGetMalloc(&pMalloc)) ) {
BROWSEINFO bi; ZeroMemory(&bi,<span style="color:blue sizeof(bi));
bi.hwndOwner = hParent;
bi.ulFlags = BIF_NEWDIALOGSTYLE |
BIF_RETURNFSANCESTORS |
BIF_RETURNONLYFSDIRS;
bi.lpfn = BrowseCallbackProc;
LPITEMIDLIST pidl = ::SHBrowseForFolder(&bi);
<span style="color:blue if( pidl ) {
bSelected = ::SHGetPathFromIDList(pidl,szOutPath)!=0;
pMalloc->Free(pidl); <span style="color:green // Free the PIDL allocated by SHBrowseForFolder.
}
pMalloc->Release(); <span style="color:green // Release the shells allocator.
}
}
<span style="color:blue return bSelected;
}
[/code]
View the full article