Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SHBrowseForFolder() (bis)

SHBrowseForFolder() (bis)

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    super_ttd
    wrote on last edited by
    #1

    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 a CString. this compiles fine, but always starts on the desktop. if I uncomment what is commented, the compiler (VC7.1) complains about the A2W() 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.

    V 1 Reply Last reply
    0
    • S super_ttd

      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 a CString. this compiles fine, but always starts on the desktop. if I uncomment what is commented, the compiler (VC7.1) complains about the A2W() 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.

      V Offline
      V Offline
      Viorel
      wrote on last edited by
      #2

      super_ttd wrote:

      [...] the compiler (VC7.1) complains about the A2W() macro [...]

      Try the newer improved CA2W macro. Actually I think you need CT2W macro. The correct shortest usage:

      ::SHParseDisplayName(CT2W(m_strFolder), . . .
      

      Then try the rest of the code again. I hope this helps.

      S 2 Replies Last reply
      0
      • V Viorel

        super_ttd wrote:

        [...] the compiler (VC7.1) complains about the A2W() macro [...]

        Try the newer improved CA2W macro. Actually I think you need CT2W macro. The correct shortest usage:

        ::SHParseDisplayName(CT2W(m_strFolder), . . .
        

        Then try the rest of the code again. I hope this helps.

        S Offline
        S Offline
        super_ttd
        wrote on last edited by
        #3

        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 ?

        V 1 Reply Last reply
        0
        • S super_ttd

          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 ?

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          Since SHParseDisplayName requires LPCWSTR, the proposed solution should work:

          ::SHParseDisplayName(CT2W(m_strFolder), . . .);
          
          S 1 Reply Last reply
          0
          • V Viorel

            Since SHParseDisplayName requires LPCWSTR, the proposed solution should work:

            ::SHParseDisplayName(CT2W(m_strFolder), . . .);
            
            S Offline
            S Offline
            super_ttd
            wrote on last edited by
            #5

            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:

            V M 2 Replies Last reply
            0
            • S super_ttd

              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:

              V Offline
              V Offline
              Viorel
              wrote on last edited by
              #6

              super_ttd wrote:

              why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ?

              I cannot explain this. In my case it tells me that the first parameter is of PCWSTR type.

              1 Reply Last reply
              0
              • S super_ttd

                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:

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                super_ttd wrote:

                ...why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ?

                Because that is the way the function is defined. :)

                S 1 Reply Last reply
                0
                • M Mark Salsbery

                  super_ttd wrote:

                  ...why does intellisense tell me SHParseDisplayName() wants a LPWSTR then ?

                  Because that is the way the function is defined. :)

                  S Offline
                  S Offline
                  super_ttd
                  wrote on last edited by
                  #8

                  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.

                  M 1 Reply Last reply
                  0
                  • S super_ttd

                    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.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • V Viorel

                      super_ttd wrote:

                      [...] the compiler (VC7.1) complains about the A2W() macro [...]

                      Try the newer improved CA2W macro. Actually I think you need CT2W macro. The correct shortest usage:

                      ::SHParseDisplayName(CT2W(m_strFolder), . . .
                      

                      Then try the rest of the code again. I hope this helps.

                      S Offline
                      S Offline
                      super_ttd
                      wrote on last edited by
                      #10

                      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 with m_strFolder folder selected (the tree expanded to that folder). another weird thing is that SHParseDisplayName() is available only since WindowsXP. wasn't it possible to have such a behavior on Windows 2000 ?! :wtf: thanks for your contribution... ;) see you

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups