From: Mayayana on
A few additional tips on that Shell code:

Working with the shell can be a bit tricky. The
interfaces are somewhat funky and half-baked.
For instance, you need to set "Show hidden" in
the object browser to even see some of this stuff.
And ShellFolderView is a very limited object model.

Also, notice that my code says:

WB.Document.CurrentViewMode = FVM_SMALLICON

If I use SFV.CurrentViewMode = FVM_SMALLICON
it causes an error. Likewise when you do things
like enumerating folder files. VB sees these things
as "unsupported variant types". You can access
them fine as variants, but you can run into trouble
sometimes with strong data typing. So just keep that
in mind. If you run into weird errors along those lines
just try using variants and Object data types. You
can have early binding with SFV. You just can't use
it in all cases.

Another issue is with the WB control. It
loads a page at startup no matter what. If you don't
feed it an about:blank it will load a 404 page.
So it's always good to use error trapping with a WB.

Also, you have to discern the difference between a
webpage and a folder in DocumentComplete before
you set the SFV object, and to be on the safe side
you should make sure you have an SFV before using it.
You can check the URL parameter of DocumentComplete,
but I think the TypeName method I'm using below is
easier and more dependable.

With all that in mind, here's an improved sample,
with error trapping:

'------------------------------------------------------

Enum FOLDERVIEWMODE
FVM_ICON = 1
FVM_SMALLICON = 2
FVM_LIST = 3
FVM_DETAILS = 4
FVM_THUMBNAIL = 5
FVM_TILE = 6
FVM_THUMBSTRIP = 7
End Enum

Dim WithEvents SFV As ShellFolderView

Private Sub Command1_Click()
WB.Navigate2 "C:\"
If Not SFV Is Nothing Then WB.Document.CurrentViewMode = FVM_SMALLICON
End Sub

Private Sub SFV_SelectionChanged()
If SFV.SelectedItems.Count = 1 Then
Label1.Caption = SFV.SelectedItems.Item(0).Name
End If
End Sub

Private Sub WB_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next
Set SFV = Nothing
Debug.Print TypeName(pDisp.Document)
If InStr(TypeName(pDisp.Document), "IShellFolder") = False Then Exit Sub
Set SFV = WB.Document
End Sub

'----------------------------------------


When you start the project it may or may not
work OK with the first code I posted. It might
error out when it loads the initial page. The new
code has this in DocumentComplete:

Debug.Print TypeName(pDisp.Document)

You'll probably see this when the project starts:

Nothing
HTMLDocument

When you click the button to navigate to C:\ you
should see something like this in debug.print:

IShellFolderViewDual2

That tells you that you've got an SFV. You can fool
around with this stuff to optimize error trapping.
I think I've pretty much got the bugs out with my
second sample.
(Also note: I started out using the variable name
SFW instead of SFV, accidentally. Then I changed
it. Sorry for any confusion. Just switch to the second
code block and it should work fine.)


From: Mayayana on
Not to overload you, but if you get involved
with this shell stuff, here's something else that
might be useful:

http://www.jsware.net/jsware/vbcode.php5#shlop

It demonstrates the possibilities for accessing
and controlling Explorer windows. The code is not
meant to be a clear, usable project on its own. It's
meant to show pros and cons of different methods.
There's also a lot of info. in the comments. The big
thing you need to remember when using Explorer
and ShellFolderView is that the whole thing is
visual. It's not an alternate file system tool. It's a
limited object model designed only for specific,
limited Explorer functionality. In XP a SFV FolderItems
collection will not return hidden files. On Win9x it
doesn't even include some file extensions, such as .drv.
It varies by Windows version. As I said before, the whole
thing is somewhat half-baked. (Check out the
FolderItemVerb object for another good example of
something best avoided.)

It's best to use SFV to access folder activity in the
GUI. You can hook into Explorer, catch the event when
an item is selected, and get limited control over the view.
But it's better to use basic file system APIs when you
want to actually enumerate or handle files and folders.

In your current case all of that may not matter so much.
If all you want is to have a lot of Explorer windows
lined up then you can get that easily with WBs. You'll
get all of the Explorer functionality, like context menus,
automatically with no effort needed on your part.


From: mp on

"Mayayana" <mayayana(a)invalid.nospam> wrote in message
news:i055ro$so0$1(a)news.eternal-september.org...
> Not to overload you, but if you get involved
> with this shell stuff, here's something else that
> might be useful:
>
> http://www.jsware.net/jsware/vbcode.php5#shlop
>
> It demonstrates the possibilities for accessing
> and controlling Explorer windows. The code is not
> meant to be a clear, usable project on its own. It's
> meant to show pros and cons of different methods.
> There's also a lot of info. in the comments. The big
> thing you need to remember when using Explorer
> and ShellFolderView is that the whole thing is
> visual. It's not an alternate file system tool. It's a
> limited object model designed only for specific,
> limited Explorer functionality. In XP a SFV FolderItems
> collection will not return hidden files. On Win9x it
> doesn't even include some file extensions, such as .drv.
> It varies by Windows version. As I said before, the whole
> thing is somewhat half-baked. (Check out the
> FolderItemVerb object for another good example of
> something best avoided.)
>
> It's best to use SFV to access folder activity in the
> GUI. You can hook into Explorer, catch the event when
> an item is selected, and get limited control over the view.
> But it's better to use basic file system APIs when you
> want to actually enumerate or handle files and folders.
>
> In your current case all of that may not matter so much.
> If all you want is to have a lot of Explorer windows
> lined up then you can get that easily with WBs. You'll
> get all of the Explorer functionality, like context menus,
> automatically with no effort needed on your part.
>
>

Thanks for all the great ideas...sounds exactly likewhat i was looking for.
i'll dig into those samples and links and see what emerges.
thanks again,
mark


First  |  Prev  | 
Pages: 1 2
Prev: Date format for any LCID
Next: ListView Hit test