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. BFFM_SETSELECTION question

BFFM_SETSELECTION question

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 2 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.
  • N Offline
    N Offline
    nm_114
    wrote on last edited by
    #1

    The MSDN docs say "The path can be specified as a Unicode string or a PIDL" for the BFFM_SETSELECTION message (inside a BrowseCallbackProc function after calling SHBrowseForFolder), but when I send a Unicode string instead of an ansi one it fails. Is the documentation wrong?

    P 1 Reply Last reply
    0
    • N nm_114

      The MSDN docs say "The path can be specified as a Unicode string or a PIDL" for the BFFM_SETSELECTION message (inside a BrowseCallbackProc function after calling SHBrowseForFolder), but when I send a Unicode string instead of an ansi one it fails. Is the documentation wrong?

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      Did you set the wParam as true?


      -Prakash

      N 1 Reply Last reply
      0
      • P Prakash Nadar

        Did you set the wParam as true?


        -Prakash

        N Offline
        N Offline
        nm_114
        wrote on last edited by
        #3

        yep, it works fine with an ansi string.

        P 1 Reply Last reply
        0
        • N nm_114

          yep, it works fine with an ansi string.

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          How are you sending the unicode string ? can you dump the section of code ?


          -Prakash

          N 1 Reply Last reply
          0
          • P Prakash Nadar

            How are you sending the unicode string ? can you dump the section of code ?


            -Prakash

            N Offline
            N Offline
            nm_114
            wrote on last edited by
            #5

            if you uncomment the commented out lines it works fine in unicode builds but not ansi. it's being converted to unicode ok because OutputDebugStringW prints what it's supposed to.

            int CALLBACK BrowseCallbackProc_SetInitFolder(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
            {
            	if (uMsg == BFFM_INITIALIZED)
            	{
            //#ifdef UNICODE
            		SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);
            //#else
            //		WCHAR sz[MAX_PATH];
            //		MultiByteToWideChar(CP_ACP, 0, (LPTSTR)lpData, -1, sz, MAX_PATH);
            //		OutputDebugStringW(sz);
            //		SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)sz);
            //#endif
            	}
            	return 0;
            }
            
            P 1 Reply Last reply
            0
            • N nm_114

              if you uncomment the commented out lines it works fine in unicode builds but not ansi. it's being converted to unicode ok because OutputDebugStringW prints what it's supposed to.

              int CALLBACK BrowseCallbackProc_SetInitFolder(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
              {
              	if (uMsg == BFFM_INITIALIZED)
              	{
              //#ifdef UNICODE
              		SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);
              //#else
              //		WCHAR sz[MAX_PATH];
              //		MultiByteToWideChar(CP_ACP, 0, (LPTSTR)lpData, -1, sz, MAX_PATH);
              //		OutputDebugStringW(sz);
              //		SendMessage(hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)sz);
              //#endif
              	}
              	return 0;
              }
              
              P Offline
              P Offline
              Prakash Nadar
              wrote on last edited by
              #6

              In Ansi build you should NOT convert the string to Unicode while using windows APIs, Check this link[^] and search for BFFM_SETSELECTION The Microsoft documentation has a couple of minor errors I should point out in case you try to program SHBrowseForFolder in C. The documentation says to pass the string for BFFM_SETOKTEXT in WPARAM; actually, it's LPARAM. It also says that BFFM_SETSELECTION requires a Unicode string, but BFFM_SETSELECTION is available in both A and W flavors, so you can use LPCTSTR.


              -Prakash -- modified at 23:38 Sunday 8th January, 2006

              N 1 Reply Last reply
              0
              • P Prakash Nadar

                In Ansi build you should NOT convert the string to Unicode while using windows APIs, Check this link[^] and search for BFFM_SETSELECTION The Microsoft documentation has a couple of minor errors I should point out in case you try to program SHBrowseForFolder in C. The documentation says to pass the string for BFFM_SETOKTEXT in WPARAM; actually, it's LPARAM. It also says that BFFM_SETSELECTION requires a Unicode string, but BFFM_SETSELECTION is available in both A and W flavors, so you can use LPCTSTR.


                -Prakash -- modified at 23:38 Sunday 8th January, 2006

                N Offline
                N Offline
                nm_114
                wrote on last edited by
                #7

                Mr.Prakash wrote:

                The Microsoft documentation has a couple of minor errors

                ah, thats what i thought. thanks.

                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