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
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.
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)
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.
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)
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.
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)
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:
Private Const BIF_NEWDIALOGSTYLE = &H40
Then change the following (changes in bold)
VB Code:
Public Function BrowseFolder(ByVal HwndOwner As Long, ByRef Titre As String) As String
Dim lpIDList As Long
Dim sBuffer As String
Dim BrowseInfo As T_BROWSEINFO
BrowseFolder = ""
With BrowseInfo
.HwndOwner = HwndOwner
.lpszTitle = lstrcat(Titre, "")
.ulFlags = BIF_RETURNONLYFSDIRS[b] Or BIF_NEWDIALOGSTYLE [/b]
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:
Private Declare Function SendMessageString _
Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long
Private m_Path As String
Public Function BrowseFolder(ByVal hWndOwner As Long, ByVal sInitDir As String) As String
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?
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)
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.
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.
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)
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)
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)
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)
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)
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)
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.
...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)
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:
Public Function BrowseFolder(ByVal HwndOwner As Long, ByVal sInitDir As String) As String