-
"Add New Folder" button in "Folder Browser" for Win 98
hello,
i searched the forum but the NewDialog style of BrowseFolder API doesn't work for 98.
i believe that user need to make its own dialog system for that purpose. but i am unable to use TreeView control properly. could someone please explain it to me.
plus how can i Add and delete folders (in general coding and in treeview also).
thnx.
PS - I am waiting Hack :bigyello:
sister thread of this thread
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
PS - I am waiting Hack :bigyello:
:lol: Patience my New Delhi friend, is a virtue.
This was written by Matt Hart
VB Code:
Option Explicit
Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Type DirInfo
DirName As String
End Type
Private bCancel As Boolean
Private Sub FindDirs(D$, T As TreeView)
Static bFirstIn As Boolean
If bCancel Then Exit Sub
Dim nx As Node, C$
Dim N As Integer, Srch$, i As Integer, NewD$
C$ = D$
If Right$(C$, 1) <> "\" Then C$ = C$ & "\"
If Not bFirstIn Then
bFirstIn = True
Set nx = T.Nodes.Add(, , C$, C$)
End If
Srch$ = C$ & "*.*"
ReDim Dees(1 To 10) As DirInfo
Call LoadDirs(Dees(), N, Srch$)
DoEvents
If N Then
For i = 1 To N
Set nx = T.Nodes.Add(C$, 4, Dees(i).DirName, LastPath$(Left$(Dees(i).DirName, Len(Dees(i).DirName) - 1)))
Next
Else
Exit Sub
End If
For i = 1 To N
NewD$ = RTrim$(Dees(i).DirName)
Call FindDirs(NewD$, T)
Next
End Sub
Private Function LastPath$(P$)
Dim i
For i = Len(P$) To 1 Step -1
If Mid$(P$, i, 1) = "\" Then
LastPath$ = Mid$(P$, i + 1)
Exit For
End If
Next
End Function
Private Sub LoadDirs(D() As DirInfo, N As Integer, Srch$)
Dim a$, Max As Integer, i As Integer, k As Integer, W32 As WIN32_FIND_DATA, fHandle As Long, lResult As Long
Dim oPath$
Max = UBound(D)
N = 0
oPath$ = Left$(Srch$, Len(Srch$) - Len(LastPath$(Srch$)))
fHandle = FindFirstFile(Srch$, W32)
If fHandle Then
Do
a$ = Left$(W32.cFileName, InStr(W32.cFileName, Chr$(0)) - 1)
If a$ <> "." And a$ <> ".." And ((W32.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) > 0) Then
N = N + 1
If Max < N Then
Max = Max + 10
ReDim Preserve D(1 To Max) As DirInfo
End If
D(N).DirName = oPath$ & a$ & "\"
End If
DoEvents
If bCancel Then Exit Do
lResult = FindNextFile(fHandle, W32)
Loop While lResult
lResult = FindClose(fHandle)
End If
If bCancel Then Exit Sub
For i = 1 To N - 1
For k = i + 1 To N
If UCase$(D(i).DirName) > UCase$(D(k).DirName) Then
a$ = D(k).DirName
D(k).DirName = D(i).DirName
D(i).DirName = a$
End If
Next
Next
End Sub
Private Sub Command1_Click()
Static Done
If Done Then Exit Sub
Done = True
bCancel = False
Command1.Caption = "Cancel"
Call FindDirs("C:\", TV)
Command1.Caption = "Fill It!"
MsgBox "Done!"
Done = False
End Sub
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
thank you Hack. but there are few questions:
- it's only listing C: and not others like D:, E:, F: etc
- when i tried to click "Fill Up!", it showed an error
Quote:
run-time error '35602':
Key is not unique in collection
and highlights
VB Code:
For i = 1 To N
[hl]Set nx = T.Nodes.Add(C$, 4, Dees(i).DirName, LastPath$(Left$(Dees(i).DirName, Len(Dees(i).DirName) - 1)))[/hl]
Next
- it takes some time in listing folders, why so?
- how can i show it like the pic you posted in the other thread?
- the cancel button is not working.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
thank you Hack. but there are few questions:
- it's only listing C: and not others like D:, E:, F: etc
- when i tried to click "Fill Up!", it showed an error
What was the error? It doesn't error when I run it.
Quote:
Originally Posted by Harsh Gupta
- it takes some time in listing folders, why so?
Because of the number of folders you have on your PC. That routine takes about 20 minutes to finish if I run it on mine (I have over 200 folders just under \Source Code\VB6 )
Quote:
Originally Posted by Harsh Gupta
- how can i show it like the pic you posted in the other thread?
You would need to add an image control, some icons that you want to represent folders and link the image control to the treeview.
Quote:
Originally Posted by Harsh Gupta
- the cancel button is not working.
Yeah, I've never really liked the way he did the cancel thing. I would put a specific cancel button on the form and in its click event set bCancel to True.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
What was the error? It doesn't error when I run it
Quote:
run-time error '35602':
Key is not unique in collection
and highlights
VB Code:
For i = 1 To N
[hl]Set nx = T.Nodes.Add(C$, 4, Dees(i).DirName, LastPath$(Left$(Dees(i).DirName, Len(Dees(i).DirName) - 1)))[/hl]
Next
-
1 Attachment(s)
Re: "Add New Folder" button in "Folder Browser" for Win 98
Well, you error is very wierd then, because I don't get that error. It works just fine.
In fact, I have attached the form I used to test this, and on my machine it just whipped right along.
Download this form and load it into the project you are using, run it, and see what happens.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
Well, you error is very wierd then, because I don't get that error. It works just fine.
In fact, I have attached the form I used to test this, and on my machine it just whipped right along.
Download this form and load it into the project you are using, run it, and see what happens.
sorry to say, but same thing and same error :(
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
sorry to say, but same thing and same error :(
I'm running XP Pro SP1. What do you have on your machine?
Also, what VB service pack are you running? I'm running SP5.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
I am using Win 98 (thats the original problem)
without any SP. but does it make any difference?
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
without any SP. but does it make any difference?
This is the difference. This is the BIG difference.
SP5 contains a variety of patches and updates/grades to many of the VB controls with TreeView and ListView being two of them.
I would suggest you download that service pack and apply it.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
This is the difference. This is the BIG difference.
SP5 contains a variety of patches and updates/grades to many of the VB controls with TreeView and ListView being two of them.
I would suggest you download that service pack and apply it.
all right. i will do it soon and revert back to you.
but it will take some time since i am using telephone connection nowadays and it will take few days, for me to download that huge package, plus IE, plus MDAC : PHEW :
:wave: for now
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Don't you have a better/faster connection at your place of work?
You could download it there, burn it to CD, and take the CD home.
I do stuff like that for my father in-law all the time. :D
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
Don't you have a better/faster connection at your place of work?
You could download it there, burn it to CD, and take the CD home.
I do stuff like that for my father in-law all the time. :D
if that's possible for me, i would have done that ages ago ;) :LOL:
but i have no option but to download it at home. and i have applied for the Broadband connection but it will require few days to get connected.
Quote:
....place of work?
:( still looking for job :cry:
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
all right Hack, i am now ready to download the SP. but i have few queries-
1) should i also download the Windows Update from MSDN? is it going to help me any ways?
2) if i install VB SP6 instead of 5 (as you are using), does it make any difference?
thank you.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
all right Hack, i am now ready to download the SP. but i have few queries-
1) should i also download the Windows Update from
MSDN? is it going to help me any ways?
I can only speculate on this as I haven't used 98 in a few years, but I'd say...sure, why not.
Quote:
Originally Posted by Harsh Gupta
2) if i install VB SP6 instead of 5 (as you are using), does it make any difference?
Well, it will make a difference to your VB controls and that treeview code should work for you, but it is only going to affect VB.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Well, it will make a difference to your VB controls and that treeview code should work for you, but it is only going to affect VB.
couled you please elaborate on this one. :confused:
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
couled you please elaborate on this one. :confused:
The reason you are installing the service pack is because you don't have a VB service pack installed and the VB controls you are using are way out of date. This is why the treeview code worked on my machine but not on yours. One of the things these service packs do it provide updates for many of the VB6 controls.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
thank you but i knew that. all i wanted to know was will installing VB SP 6 make difference than installing SP5?
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
thank you but i knew that. all i wanted to know was will installing VB SP 6 make difference than installing SP5?
That I couldn't tell you. Maybe someone else can. I'm still running SP5.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
all right, then i will download SP6 and get back to this thread soon.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
all right, then i will download SP6 and get back to this thread soon.
As soon as you get it installed, try that treeview code.
It should work.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Btw I had completely forgotten about this fully featured browse dialog I've just found in the folder where I keep the cool stuff. It works great even under W98.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
As soon as you get it installed, try that treeview code.
It should work.
all right Hack, i downloaded and installed VB SP6, but not much help and same problem i mentioned before. now what could be the problem? :confused:
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
all right Hack, i downloaded and installed VB SP6, but not much help and same problem i mentioned before. now what could be the problem? :confused:
Good question. As you know, it works on my machine, and now that you have yours updated, it should be working on yours.
Code that doesn't work, won't work anywhere, so if it works in one place, it should work in another. However, since it isn't, then we still have some kind of difference in our VB platforms. Are you using the form that I attached that I developed on my PC and works on my PC?
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
You'll get the error simply because you have two folders with the same name, since you use the folder name (instead of full path) as the Key. Just make sure the Key is unique.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
Good question. As you know, it works on my machine, and now that you have yours updated, it should be working on yours.
Code that doesn't work, won't work anywhere, so if it works in one place, it should work in another. However, since it isn't, then we still have some kind of difference in our VB platforms. Are you using the form that I attached that I developed on my PC and works on my PC?
yes, i also tried using the form you attached before (except that you used a picturebox instead of a treeview ;) ) and the same thing/error occurred.
and thats not all. even after updation, i am not able to run this code posted by Moeur. please see the entire thread and you will see that the project posted by worked on Moeur's PC and not mine (even after updation).
it's driving me nuts!! :cry:
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
my request to you both, *SLAP ME*.
you are right JA. now all i want to learn is, how to make it look like a normal Browse for folder Dialog box (starting from desktop to all drives etc).
-icons can be set using imagelist.
-folders can be added using .Nodes.Add method.
thank you.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
hey just tried the example posted by krtxmrtz. it demonstrates the same thing, Add New folder using SHBrowseForFolder API on Win 98 too :eek: . How??
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
This is another way but i am not sure about win98
VB Code:
Dim sh As New Shell32.Shell
Dim str1 As Shell32.Folder2
Set str1 = sh.BrowseForFolder(Me.hWnd, "Select a Folder", 0, ssfDRIVES)
If Not str1 Is Nothing Then
MsgBox str1.Self.Path
End If
casey.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Did you try Casey's code example?
Have you sorta, kinda, got it working? (That is what I'm picking up anyway :) )
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Hack
Did you try Casey's code example?
:confused: which Casey's code?? :confused:
Quote:
Have you sorta, kinda, got it working? (That is what I'm picking up anyway :) )
yep it was my mistake.
but now, only one query left, how can i make it look like normal Browse for folder dialog box? mean how can i start it from Desktop and also show all the drives of the PC?
i can manage other things like Imagelist thing, and adding folders etc. though i may take a lot of time on it because i never did any work on these 2 (imagelist and treeview), but i want to do it myself.
but if you or somebody else may help me out regarding the display of all drives and starting from desktop thing.
thank you all.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
:confused: which Casey's code?? :confused:
Post #29
casey.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by vbasicgirl
Post #29
casey.
oh so sorry, i could not see your name there. i apologize.
but i think i need to add reference for it because it generates an error for
VB Code:
Dim sh As New Shell32.Shell
Dim str1 As Shell32.Folder2
if you can please tell me as i am not able to recall it.
thank you.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
I should have said, sorry. The reference is Microsoft shell controls and automation.
casey.
-
1 Attachment(s)
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
oh so sorry, i could not see your name there. i apologize.
but i think i need to add reference for it because it generates an error for
VB Code:
Dim sh As New Shell32.Shell
Dim str1 As Shell32.Folder2
if you can please tell me as i am not able to recall it.
thank you.
This is it.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
i tried running your code and it's generating an error "Object doesn't support this property or method" at the MsgBox line.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Maybe its a 98 thing, did you copy and paste the code ?, if you did try typing it out to see if the property or method is there and if not is there an alternative to grab the path.
casey.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by vbasicgirl
Maybe its a 98 thing, did you copy and paste the code ?, if you did try typing it out to see if the property or method is there and if not is there an alternative to grab the path.
casey.
actually i changed your code a little bit. i changed "Shell32.Folder2" to "Shell32.Folder" because if i use "Shell32.Folder2" then on clicking "yes" on dialog box it returns an error 13 : "type mismatch" and highlights
VB Code:
Set str1 = sh.BrowseForFolder(Me.hWnd, "Select a Folder", 0, ssfDRIVES)
and if i use ".Folder" tehn .Self thing is not available. :confused:
EDIT: was that code running on your machine??
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
try out karl e stevensons home page he's got loads of codes .may be it can help you k.e.s :wave:
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by litlewiki
try out karl e stevensons home page he's got loads of codes .may be it can help you
k.e.s :wave:
litlewiki,
he is Karl E. Peterson and not Stevenson. and sorry, i couldnot find any such utility there. but probably take a much better and deeper look at the link later. thank you anyways.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Yes, that code runs fine on mine but im using xp. One thing to try is that same code except use folder instead of folder2 because even though its not part of the propertys the Self.Path still works with mine, other than that i cant help unless i had a 98 machine infront of me.
good luck.
casey.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Setting a reference to Shell32.dll and use the COM objects instead of using the API functions directly that are available in the same file, doesn't help you with this issue simply because there is so many versions of this file. There is nothing available in the COM objects that aren't available in the API functions (the COM objects simply call these functions internally anyway).
The advantage you get from setting a reference is that you don't need all the declarations and conversions you'll need to call API functions so it requires less code and it looks more VB-like since we use COM objects all the time. The disadvantage is that you bind yourself to a particular version of the Shell32.dll file in a greater extent than with the API functions, since using the functions the declarations look the same between different versions, they just add new flags. You can always check what Windows version your code is running on an use or discard some of the flags depending on that. This approach is not available for you when you've set a reference to the library.
I'm not telling Casey or anyone else not to use the reference approach, I'm just saying that you must be aware of the limitations.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by vbasicgirl
Maybe its a 98 thing...
casey.
Must be something else, it works for me in a W98 computer.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Joacim Andersson
The disadvantage is that you bind yourself to a particular version of the Shell32.dll file...
This is a good point I wasn't aware of.
What a juicy thread, I'm really learning.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by krtxmrtz
Must be something else, it works for me in a W98 computer.
:eek: even with .Folder2??
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
:eek: even with .Folder2??
I copied and pasted casey's code at post #29.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by krtxmrtz
I copied and pasted casey's code at post #29.
krtxmrtz,
casey's code is displaying a folder browser on my pc too, but when i press OK, it generates an error. but clicking Cancel does not generate any error. is this happening on your pc too?? could you please check it??
thnx
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
krtxmrtz,
casey's code is displaying a folder browser on my pc too, but when i press OK, it generates an error. but clicking Cancel does not generate any error. is this happening on your pc too?? could you please check it??
thnx
It's exactly as you say, I simply forgot to click on the OK button the first (and only) time I tried out the code. :blush:
I'm sorry I may have been misleading you.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
all right, keeping aside all things discussed in this thread (except for the subject), is it possible to use an API along with a control on a form?
i am trying to put 1 TreeView control on a form and when that form is loaded, use SHBrowseforFolder API, but instead of opening its dialog box, call it to load its content in the control (TreeView in this case)??
thank you
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
So, you want to use the dialog to select a folder, and once selected, that folder and all of its sub folders should be loaded into a treeview. Is that correct?
Did you get the Treeview control to work on your system?
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
No, instead of opening a dialog box, open another form having TV, and use API to list all folders in that TV which the BrowseforFolder API will list in its dialog box.
but i think i am wrong. do you know how the Extract dialog box of Winzip works? it also uses a TV control but uses a seperate form for it.
hope i am clear this time.
-
1 Attachment(s)
Re: "Add New Folder" button in "Folder Browser" for Win 98
Well, I don't know about getting it to populate your TreeView control. But what you can do is to show the BrowseForFolder dialog and "steal" the folder view window it uses and simply hide the rest. This would envolve using SetParent when you have the hWnd of the treeview... Hmmm... Instead of explaining it all, I wrapped it up in a UserControl for you... This one if far from perfect, since it can only return the Path of file system folders, and if the user selects a shell folder like the control panel or something an empty string is returned by the Path property... But at least you have something to work with (or maybe just learn from).
The thing with this control is that you have to call the Create method in the Form_Activate event, and you should also call the Destroy method in the Form_Unload or QueryUnload event. The Create method takes an optional path string as argument if you want a particular folder to be selected from the start. It's all shown in the very basic demo project attached. Just open the Group1.vbg file to try it out.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Joacim Andersson
... This one if far from perfect...
:eek2:
No, in fact thats more than perfect!!!
: praying God : "please help me in getting the coding sense and style like him"
i thought of making one such control (not user-control) where the user is allowed to add folder to a present TV (for Win 98) thats why i popped this question about getting or stealing the control from an API's dialog box to my form.
One request, can i use your technique for my project?? i will list and refer your name (and all those who helped me in this) in the project.
and yes, indeed it a ver good tutorial for every newbie and those who want to get started with UC programming.
Thank you.
-
Re: "Add New Folder" button in "Folder Browser" for Win 98
Quote:
Originally Posted by Harsh Gupta
One request, can i use your technique for my project?? i will list and refer your name (and all those who helped me in this) in the project.
Everything I post in this forum is free for you or anyone else to use in anyway they like.