visual c++ - SHBrowseForFolder "Make New Folder" behavior in Windows XP -


i using shbrowseforfolder new dialog style gives 'make new folder' button on

i getting problems in windows xp.

the behavior this:

1) first when invoke dialog, behaviour usual(i.e, selecting current folder. focus not on tree item(dimmed).

if click make new folder button state new folder creating not in selected state(i.e, when ever create new folder allow rename folder selection on item , editbox).

if select directory(i.e, setting focus item) , clicking on new folder creating folder in selected state. (in windows 8,windows 7 , windows vista working fine) faced problem.

is there solution this?

        bool getfolder(std::string& folderpath, const char* szcaption = null, hwnd       howner = null) 

{ bool retval = false;

// browseinfo struct tells shell  // how should display dialog. browseinfo bi; memset(&bi, 0, sizeof(bi));  bi.ulflags   = bif_newdialogstyle|bif_returnfsancestors|bif_returnonlyfsdirs;    bi.hwndowner = howner; bi.lpsztitle = szcaption;  // must call if using bif_usenewui ::oleinitialize(null);  // show dialog , itemidlist selected folder. lpitemidlist pidl = ::shbrowseforfolder(&bi);  if(pidl != null) {     // create buffer store path, path.     char buffer[_max_path] = {'\0'};     if(::shgetpathfromidlist(pidl, buffer) != 0)       {           // set string value.            folderpath = "";            retval = true;       }             // free item id list           cotaskmemfree(pidl);   }      ::oleuninitialize();      return retval;     } 

this seems bug in windows xp.

try code below. may not quite want, automatically expands default folder, @ least results in more or less correct behaviour. tested on windows xp , on windows 7. on later versions of windows might not work expected, possibily should check if running under xp , quirk if running under xp.

int callback browsecallbackproc(hwnd hwnd, uint umsg, lparam lparam, lparam pdata) {   if (umsg == bffm_initialized)   {     hwnd hchild = getwindow(hwnd, gw_child) ;      while (hchild != null)     {       tchar classname[200] ;       getclassname(hchild, classname, 200) ;        if (lstrcmp(classname, "shbrowseforfolder shellnamespace control") == 0)       {         // hchild handle shellname space control         hwnd hlistctrl = getwindow(hchild, gw_child) ;                  {           // browse through controls of shellnamespace control           getclassname(hlistctrl, classname, 200) ;            if (lstrcmp(classname, "systreeview32") == 0)             break ;   // we've got list control            hlistctrl = getwindow(hlistctrl, gw_hwndnext) ;         } while (hlistctrl != null) ;          if (hlistctrl != null)         {           // handle selected item           htreeitem ht = (htreeitem)::sendmessage(hlistctrl, tvm_getnextitem, tvgn_caret, 0) ;            if (ht != null)           {             // expand selected item             ::sendmessage(hlistctrl, tvm_expand, tve_expand, (lparam)ht) ;           }         }       }        hchild = getwindow(hchild, gw_hwndnext) ;     }   }    return 0; }   bool getfolder(cstring& folderpath, const char* szcaption, hwnd howner) {   bool retval = false;   // how should display dialog.   browseinfo bi;   memset(&bi, 0, sizeof(bi));    bi.ulflags   = bif_newdialogstyle|bif_returnfsancestors|bif_returnonlyfsdirs;     bi.lpfn = browsecallbackproc ;   bi.hwndowner = howner;   bi.lpsztitle = szcaption;    // must call if using bif_usenewui   ::oleinitialize(null);    // show dialog , itemidlist selected folder.    lpitemidlist pidl = ::shbrowseforfolder(&bi);    if (pidl != null)   {     // create buffer store path, path.     char buffer[_max_path] = {'\0'};     if(::shgetpathfromidlist(pidl, buffer) != 0)     {       // set string value.        folderpath = buffer;        retval = true;     }           // free item id list     cotaskmemfree(pidl);   }    ::oleuninitialize();    return retval; } 

another solution using bffm_setexpanded message shown below. in example "c:" folder automatically expanded , "new folder" button behaves correctly.

int callback browsecallbackproc(hwnd hwnd, uint umsg, lparam lparam, lparam pdata) {   if (umsg == bffm_initialized)   {     ::sendmessage(hwnd, bffm_setexpanded, true, (lparam)l"c:\\") ;   }    return 0; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -