I am trying to put in place a feature in a program to let the user browse and select a folder, and in the end store the user's selection (the selected folder) in an InkEdit textbox.
I searched and found this thread:
http://www.vbforums.com/showthread.p...-path-resolved
In the post#2 in there RhinoBull has provided a good piece of code that does this job.
So, I copied it into my project and made some small modifications to make it fit my needs.
Here is my code based onRhinoBull's initial suggestion:
Code:
Public Function OpenFolderInDialogBox(ByRef DlgTitle As String, ByRef FormhWndOwner As Long) As String
'=============================
Dim lpIDList As Long
Dim sBuffer As String
Dim sTitle As String
Dim tBrowseInfo As BrowseInfo
sTitle = DlgTitle
With tBrowseInfo
.hWndOwner = FormhWndOwner ' Me.hwnd
.lpszTitle = lstrcat(sTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN _
+ BIF_EDITBOX + BIF_NEWDIALOGSTYLE
End With
lpIDList = SHBrowseForFolder(tBrowseInfo)
If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
OpenFolderInDialogBox = sBuffer
End If
End Function
And here is how I call it:
Code:
InkEdit1.Text = OpenFolderInDialogBox("Input Folder", Me.hwnd)
The API declarations are the same as RhinoBull's code. I have not changed them.
At first it appeared that it worked fine, but after close inspection, I see that there are a number of problems with it:
1. This code does not return unicode folders properly because my InkEdit box shows question marks instead of foreign characters. It only shows English characters correctly.
This is not a problem with the InkEdit because I can paste any foreign character including Chinese characters in that same InkEdit box with no problem.
Therefore this is a problem with the above code. How can I fix the above code to return foreign characters correctly?
2. In the beginning when the folder browse dialogue box pops up it shows Desktop, This Pc, Libraries, external hard drives (F:\, G:\, H:\) but not C:\
I have to click on "This PC" to expand it and see all the disk drives (C:\, E:\, F:\, G:\, H:\, ).
How can I make it show a specific folder in the beginning when it pops up, so that the user can navigate from there?
3. The folder browse dialog box shows the "current folder" that the user is navigating on the bottom of it in front of the label "Folder:" For example the Chinese folder in this screen print:
http://i.imgur.com/c8lHjwL.jpg
But that is just the folder name (サンシャイン-阳光-солнечный). How can I make it show the full folder path (C:\temp2\test4\サンシャイン-阳光-солнечный) in there?
4. If the user clicks on "Cancel", the above code erases whatever already had existed in that InkEdit.
How can I fix it so that in case of a "cancel" the text in the InkEdit would remain unchanged?
5. I can pass a title to the above function and it will show that as the secondary title of the folder browse dialog box. In the above example and the screen print, that title is "Input Folder".
But the main title of that dialog box is "Browse for folder". How can I change that one too?
Please advise.
Regards
Ilia