Results 1 to 33 of 33

Thread: Select folder to save into

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Select folder to save into

    I want to use the common dialog box to select a folder which the user wants to save a load of files in.

    When the user click a folder i want that directory path as a result.

    When i do it using .ShowSave it will want to save a file, not select a folder to save to later.

    I hope you all understand

    ILMV
    Last edited by I_Love_My_Vans; Sep 24th, 2005 at 04:59 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Browse for Folder
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const BIF_RETURNONLYFSDIRS = &H1      
    4. Private Const BIF_DONTGOBELOWDOMAIN = &H2      
    5. Private Const BIF_STATUSTEXT = &H4              
    6. Private Const BIF_RETURNFSANCESTORS = &H8
    7. Private Const BIF_EDITBOX = &H10                
    8. Private Const BIF_VALIDATE = &H20              
    9. Private Const BIF_BROWSEFORCOMPUTER = &H1000    
    10. Private Const BIF_BROWSEFORPRINTER = &H2000    
    11. Private Const BIF_BROWSEINCLUDEFILES = &H4000  
    12.  
    13. Private Const MAX_PATH = 260
    14.  
    15. Private Type T_BROWSEINFO
    16.     HwndOwner      As Long
    17.     pIDLRoot       As Long
    18.     pszDisplayName As Long
    19.     lpszTitle      As Long
    20.     ulFlags        As Long
    21.     lpfnCallback   As Long
    22.     lParam         As Long
    23.     iImage         As Long
    24. End Type
    25.  
    26. Private Declare Function SHBrowseForFolder Lib "shell32" _
    27.         (lpbi As T_BROWSEINFO) As Long
    28.  
    29. Private Declare Function SHGetPathFromIDList Lib "shell32" _
    30.         (ByVal pidList As Long, _
    31.         ByVal lpBuffer As String) As Long
    32.  
    33. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
    34.         (ByVal lpString1 As String, ByVal _
    35.         lpString2 As String) As Long
    36.  
    37. Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
    38.  
    39.     Dim lpIDList As Long
    40.     Dim sBuffer As String
    41.     Dim BrowseInfo As T_BROWSEINFO
    42.  
    43.     BrowseFolder = ""
    44.     With BrowseInfo
    45.         .HwndOwner = HwndOwner
    46.         .lpszTitle = lstrcat(Titre, "")
    47.         .ulFlags = BIF_RETURNONLYFSDIRS
    48.     End With
    49.  
    50.     lpIDList = SHBrowseForFolder(BrowseInfo)
    51.  
    52.     If (lpIDList) Then
    53.         sBuffer = Space(MAX_PATH)
    54.         SHGetPathFromIDList lpIDList, sBuffer
    55.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    56.         BrowseFolder = sBuffer
    57.     End If
    58. End Function

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Select folder to save into

    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Select folder to save into

    Hack i am trying your method. How do i call t, i havnt got a clue.

    Obv Call BrowseFolder, but whatare th parametres?

    EDIT: Sorry, found out, however what fdoes the first parametre do?
    VB Code:
    1. ByVal HwndOwner As Long

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Select folder to save into

    Just use the hWnd of the current form:

    VB Code:
    1. Private Sub Form_Load()
    2.   Dim str As String
    3.   str = BrowseFolder(Me.hWnd, "D:\Temp")
    4.   MsgBox str
    5. End Sub

  6. #6

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Select folder to save into

    Back again, i have another problem, i have used hack's method, but how do create a new folder, usually there is a button sayin "Creat Ne wFolder"

    any ideas
    ILMV

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Create a routine, separate from the Browse routine, that creates the folder for you. Put up a textbox and have the user enter the name they want, and then use MkDir to create it.

    After that is done it will show up when you Browse.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Select folder to save into


  9. #9
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    Browse for Folder
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const BIF_RETURNONLYFSDIRS = &H1      
    4. Private Const BIF_DONTGOBELOWDOMAIN = &H2      
    5. Private Const BIF_STATUSTEXT = &H4              
    6. Private Const BIF_RETURNFSANCESTORS = &H8
    7. Private Const BIF_EDITBOX = &H10                
    8. Private Const BIF_VALIDATE = &H20              
    9. Private Const BIF_BROWSEFORCOMPUTER = &H1000    
    10. Private Const BIF_BROWSEFORPRINTER = &H2000    
    11. Private Const BIF_BROWSEINCLUDEFILES = &H4000  
    12.  
    13. Private Const MAX_PATH = 260
    14.  
    15. Private Type T_BROWSEINFO
    16.     HwndOwner      As Long
    17.     pIDLRoot       As Long
    18.     pszDisplayName As Long
    19.     lpszTitle      As Long
    20.     ulFlags        As Long
    21.     lpfnCallback   As Long
    22.     lParam         As Long
    23.     iImage         As Long
    24. End Type
    25.  
    26. Private Declare Function SHBrowseForFolder Lib "shell32" _
    27.         (lpbi As T_BROWSEINFO) As Long
    28.  
    29. Private Declare Function SHGetPathFromIDList Lib "shell32" _
    30.         (ByVal pidList As Long, _
    31.         ByVal lpBuffer As String) As Long
    32.  
    33. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
    34.         (ByVal lpString1 As String, ByVal _
    35.         lpString2 As String) As Long
    36.  
    37. Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
    38.  
    39.     Dim lpIDList As Long
    40.     Dim sBuffer As String
    41.     Dim BrowseInfo As T_BROWSEINFO
    42.  
    43.     BrowseFolder = ""
    44.     With BrowseInfo
    45.         .HwndOwner = HwndOwner
    46.         .lpszTitle = lstrcat(Titre, "")
    47.         .ulFlags = BIF_RETURNONLYFSDIRS
    48.     End With
    49.  
    50.     lpIDList = SHBrowseForFolder(BrowseInfo)
    51.  
    52.     If (lpIDList) Then
    53.         sBuffer = Space(MAX_PATH)
    54.         SHGetPathFromIDList lpIDList, sBuffer
    55.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    56.         BrowseFolder = sBuffer
    57.     End If
    58. End Function
    Is it possible to allow more physical space for "Titre"? I'd like to pass a string with the current default (app's) directory but it is a very long string and doesn't fit even if you break it in 2 lines.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Quote Originally Posted by krtxmrtz
    Is it possible to allow more physical space for "Titre"? I'd like to pass a string with the current default (app's) directory but it is a very long string and doesn't fit even if you break it in 2 lines.
    Post an example of the directory string, and I'll play around with it.

  11. #11
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    Post an example of the directory string, and I'll play around with it.
    Well, I don't have any name handy now, but you can make one up yourself, something just like this:

    "c:\MainFolder\SubFolder1\SubFolder2\...\SubFolderN\"

    Make it as long as possible so it does not fit in "Titre"... Well, I know one approach could be to use something like EllipseText, but I thought you could configure the dialog so as to place the directory tree window below the "Titre" text.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    This is as big a path as I could get on it. Do you have paths longer than this?
    Attached Images Attached Images  

  13. #13
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Select folder to save into

    ILMV, If I were you I would use the CCRP link the dglienna posted. They have some other good stuff there. If you want to do it without a dependency file I can upload Joacim Andersson's class module that lets you do the same thing without knowing how all the APIs work.

    Here is one like the CCRP one, but its from vbAccelerator and you could add all the source code directly to your project: http://www.vbaccelerator.com/home/NE...er/article.asp
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  14. #14
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    This is as big a path as I could get on it. Do you have paths longer than this?
    Probably not, perhaps occasionally but in this case I think I should ellipse the text and figure out the text length to see if it fits in the label... is it a label that the text is placed in? How do you retrieve its length to be compared to the text length?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Select folder to save into

    As you can see by the attached image, it's fully possible to have a sizable browse for folder dialog box with a "Make New Folder" button. As you also can see this will be enough for viewing any path as the title, the example in the image is 260 characters long which is the maximum path length you can have in Windows.

    To get this new style add this constant to your declaration section.
    VB Code:
    1. Private Const BIF_NEWDIALOGSTYLE = &H40
    Then change the following (changes in bold)
    VB Code:
    1. Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
    2.     Dim lpIDList As Long
    3.     Dim sBuffer As String
    4.     Dim BrowseInfo As T_BROWSEINFO
    5.  
    6.     BrowseFolder = ""
    7.     With BrowseInfo
    8.         .HwndOwner = HwndOwner
    9.         .lpszTitle = lstrcat(Titre, "")
    10.         .ulFlags = BIF_RETURNONLYFSDIRS[b] Or BIF_NEWDIALOGSTYLE [/b]
    11.     End With
    12.  
    13.     lpIDList = SHBrowseForFolder(BrowseInfo)
    14.  
    15.     If (lpIDList) Then
    16.         sBuffer = Space(MAX_PATH)
    17.         SHGetPathFromIDList lpIDList, sBuffer
    18.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    19.         BrowseFolder = sBuffer
    20.     End If
    21. End Function
    But wouldn't it be much slicker to initilize the dialog to automatically select the current path and then let the use go from there? This is possible if you add a callback procedure for the SHBrowseForFolder API function. A callback procedure/function must exist in a regular BAS module, so if you have the rest of this code already in a module you can just change the code like this (origional declaration not included here)
    VB Code:
    1. Private Declare Function SendMessageString _
    2.  Lib "user32" Alias "SendMessageA" ( _
    3.  ByVal hWnd As Long, _
    4.  ByVal wMsg As Long, _
    5.  ByVal wParam As Long, _
    6.  ByVal lParam As String) As Long
    7.  
    8. Private m_Path As String
    9.  
    10. Public Function BrowseFolder(ByVal hWndOwner As Long, ByVal sInitDir As String) As String
    11.     Dim lpIDList As Long
    12.     Dim sBuffer As String
    13.     Dim BrowseInfo As T_BROWSEINFO
    14.    
    15.     BrowseFolder = ""
    16.     With BrowseInfo
    17.         .hWndOwner = hWndOwner
    18.         If Len(sInitDir) Then
    19.             m_Path = sInitDir
    20.             .lpfnCallback = ReturnParam(AddressOf ShowFolderCallback)
    21.         End If
    22.         .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_NEWDIALOGSTYLE
    23.     End With
    24.  
    25.     lpIDList = SHBrowseForFolder(BrowseInfo)
    26.  
    27.     If (lpIDList) Then
    28.         sBuffer = Space(MAX_PATH)
    29.         SHGetPathFromIDList lpIDList, sBuffer
    30.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    31.         BrowseFolder = sBuffer
    32.     End If
    33. End Function
    34.  
    35. Private Function ReturnParam(ByVal nAddress As Long) As Long
    36.     ReturnParam = nAddress
    37. End Function
    38.  
    39. Private Function ShowFolderCallback( _
    40.  ByVal hWnd As Long, _
    41.  ByVal uMsg As Long, _
    42.  ByVal lParam As Long, _
    43.  ByVal lpData As Long) As Long
    44.  
    45.     Const WM_USER = &H400
    46.     Const BFFM_SETSELECTIONA = (WM_USER + 102)
    47.     Const BFFM_INITIALIZED = 1
    48.    
    49.     If uMsg = BFFM_INITIALIZED Then
    50.         If Len(m_Path) > 0 Then
    51.             SendMessageString hWnd, BFFM_SETSELECTIONA, 1&, m_Path
    52.         End If
    53.     End If
    54.     ShowFolderCallback = 0
    55. End Function
    Attached Images Attached Images  

  16. #16
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Joacim Andersson, with the second version of the code the folder path text is not shown, nor is the "make new folder" button desplayed, as you can see in the attached image. I wonder if you have transcribed in your post above the full code or some part of it may have inadvertently slipped out? Could regional settings have screwed it up?
    Attached Images Attached Images  
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Hmmm....Joacim's code worked just fine for me.
    Attached Images Attached Images  

  18. #18
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Select folder to save into

    krtxmrtz, Joacim's Code will not work on Win 98, if by any chance you are using one.

    i believe that you need to create your own dialog box for that. if someone can also tell me how to use treeview and list all folders in it. i dont know how to use it and also how to create new folder in it.
    Show Appreciation. Rate Posts.

  19. #19
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Quote Originally Posted by Harsh Gupta
    if someone can also tell me how to use treeview and list all folders in it. i dont know how to use it and also how to create new folder in it.
    I have a piece of code that will list all of the folders on your hard drive in a treeview, however, this is off topic from what ILMV created this thread for, and we don't want to hijack his thread. If you create a new one on your topic, I'll post what I have.

  20. #20
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    Hmmm....Joacim's code worked just fine for me.
    I don't see any path name above the directory tree in your attached image. haven't you selected one yet or is it not working for you either?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  21. #21
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Harsh Gupta
    krtxmrtz, Joacim's Code will not work on Win 98, if by any chance you are using one.
    So that's why, I should have figured.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  22. #22
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Quote Originally Posted by krtxmrtz
    I don't see any path name above the directory tree in your attached image. haven't you selected one yet or is it not working for you either?
    I didn't select one. I was just testing to ensure the Make New Folder Button was there.

  23. #23
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    If you create a new one on your topic, I'll post what I have.
    Harsh Gupta, if you create that new thread please post a link to it here so I can subscribe to it later. Thanks.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  24. #24
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Select folder to save into

    Quote Originally Posted by krtxmrtz
    Harsh Gupta, if you create that new thread please post a link to it here so I can subscribe to it later. Thanks.
    sure i will do it Sir!!

    so are you using win 98?

    link to my thread
    Last edited by Harsh Gupta; Dec 9th, 2005 at 10:40 AM.
    Show Appreciation. Rate Posts.

  25. #25
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    I didn't select one. I was just testing to ensure the Make New Folder Button was there.
    The "new folder" button is displayed in XP, but the path string isn't! Are you folks sure this feature is working?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  26. #26
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Harsh Gupta
    sure i will do it Sir!!

    so are you using win 98?

    link to my thread
    Thank you.
    I'm using XP at home but 98 at the office.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  27. #27
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Select folder to save into

    Quote Originally Posted by krtxmrtz
    The "new folder" button is displayed in XP, but the path string isn't! Are you folks sure this feature is working?
    Yes it does. See Post #12 in this thread.

  28. #28
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Hack
    Yes it does. See Post #12 in this thread.
    Well, actually I was referring to Joacim Andersson's code, that he claims can admit a very long path string.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  29. #29
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Select folder to save into

    The BIF_NEWDIALOGSTYLE flag is only supported in version 5.0 and above of the Shell32.dll file (which I should have mentioned). That version came with Windows 2000. However the callback code will still work. It doesn't show the path as the title, instead it selects the path when you open the dialog, in other words the correct folder will be selected already which means that there is no reason to show the path string. Maybe you can try to use the BIF_EDITBOX flag instead (which is supported from version 4.71 and above, in other words in all versions from Win98 and later). The BIF_EDITBOX flag is already declared in Hack's origional code so you just need to use it.

    If you need to build your own dialog box there are several free Folder TreeView controls available that you can use. One is available at the Common Controls Replacement Project website.

  30. #30

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Select folder to save into

    Such a fruitful conversation

  31. #31
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Select folder to save into

    Quote Originally Posted by Joacim Andersson
    ...in other words the correct folder will be selected already which means that there is no reason to show the path string.
    This makes sense. It looks, however, like there is some space still reserved for the path string that is now empty, therefore the treeview window could have a smalller top value, i.e. it could be shifted somewhat toward the titlebar.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  32. #32
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Select folder to save into

    Well, you can still use that area to display any message you like. For example (changes in bold):
    VB Code:
    1. Public Function BrowseFolder(ByVal HwndOwner As Long, ByVal sInitDir As String) As String
    2.     Dim lpIDList As Long
    3.     Dim sBuffer As String
    4.     Dim BrowseInfo As T_BROWSEINFO
    5.    
    6.     BrowseFolder = ""
    7.     With BrowseInfo
    8.         .HwndOwner = HwndOwner
    9. [b]        .lpszTitle = lstrcat("Select a new path.", "") [/b]
    10.         If Len(sInitDir) Then
    11.             m_Path = sInitDir
    12.             .lpfnCallback = ReturnParam(AddressOf ShowFolderCallback)
    13.         End If
    14.         .ulFlags = BIF_RETURNONLYFSDIRS
    15.     End With
    16.  
    17.     lpIDList = SHBrowseForFolder(BrowseInfo)
    18.  
    19.     If (lpIDList) Then
    20.         sBuffer = Space(MAX_PATH)
    21.         SHGetPathFromIDList lpIDList, sBuffer
    22.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    23.         BrowseFolder = sBuffer
    24.     End If
    25. End Function
    If you like you can even expand this area with an additional status line. This status line can however only be set in the callback procedure. This could be helpful if you for example want the user to see the currently selected path when they expand and select a new folder in the tree.
    VB Code:
    1. Public Function BrowseFolder(ByVal HwndOwner As Long, ByVal sInitDir As String) As String
    2.     Dim lpIDList As Long
    3.     Dim sBuffer As String
    4.     Dim BrowseInfo As T_BROWSEINFO
    5.    
    6.     BrowseFolder = ""
    7.     With BrowseInfo
    8.         .HwndOwner = HwndOwner
    9. [b]        .lpszTitle = lstrcat("Current selected path:", "") [/b]
    10.         If Len(sInitDir) Then
    11.             m_Path = sInitDir
    12.             .lpfnCallback = ReturnParam(AddressOf ShowFolderCallback)
    13.         End If
    14.         .ulFlags = BIF_RETURNONLYFSDIRS[b] Or BIF_STATUSTEXT [/b]
    15.     End With
    16.  
    17.     lpIDList = SHBrowseForFolder(BrowseInfo)
    18.  
    19.     If (lpIDList) Then
    20.         sBuffer = Space(MAX_PATH)
    21.         SHGetPathFromIDList lpIDList, sBuffer
    22.         sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
    23.         BrowseFolder = sBuffer
    24.     End If
    25. End Function
    26.  
    27. Private Function ShowFolderCallback( _
    28.  ByVal hWnd As Long, _
    29.  ByVal uMsg As Long, _
    30.  ByVal lParam As Long, _
    31.  ByVal lpData As Long) As Long
    32.  
    33.     Const WM_USER = &H400
    34.     Const BFFM_SETSELECTIONA = (WM_USER + 102&)
    35. [b]    Const BFFM_SETSTATUSTEXTA = (WM_USER + 100&) [/b]
    36.     Const BFFM_INITIALIZED = 1&
    37. [b]    Const BFFM_SELCHANGED = 2&
    38.  
    39.     Dim sNewPath As String [/b]
    40.     If uMsg = BFFM_INITIALIZED Then
    41.         If Len(m_Path) > 0 Then
    42.             SendMessageString hWnd, BFFM_SETSELECTIONA, 1&, m_Path
    43.         End If
    44. [b]    ElseIf uMsg = BFFM_SELCHANGED Then
    45.         sNewPath = String(MAX_PATH, vbNullChar)
    46.         Call SHGetPathFromIDList(lParam, sNewPath)
    47.         SendMessageString hWnd, BFFM_SETSTATUSTEXTA, 0&, sNewPath [/b]
    48.     End If
    49.     ShowFolderCallback = 0
    50. End Function
    The second example will produce the result you see in the attached image, the status text (the actual path) is changed when the selection is changed.
    Attached Images Attached Images  

  33. #33
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: Select folder to save into

    Is it possible with Hack's code to limit access, so a user can only select a network location in "My network places"?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width