Unlocking the Secrets of the ShellDocVwCtl

Tuesday Nov 19th 2002 by John Percival

Unlocking the Secrets of the ShellDocVwCtl

As I was working with the WebBrowser control the other day, I noticed another control in the toolbar that I had not seen before: the ShellDocVwCtl. I had heard of the amazing power locked in the ShellDocVw.dll, but had not really had the time to be able to investigate its full potential. However I was a little disappointed when I looked at the control, as it had no properties as such. So, I decided to look in the Object Browser to see if there was anything else that I could do. Lo and behold, there were several classes with lots of different things to play about with. The first thing I did was to create one of these classes in code and have a play around:

Dim ShellControl As New Shell

To add a reference to the object library select References... on the Project menu. Scroll down the list until you find the Microsoft Internet Controls. Select this, then click OK. If you can't find it, you may need to install Internet Explorer 4.

Browse For Folder Dialog Box

Function BrowseForFolder(HWND As Long, _
Title As String, Options As Long, [RootFolder]) _
    As Folder

Use it as follows:

Hwnd Set this as the window handle for the owner form, eg. Me.Hwnd
Title The text which is displayed above the list of folders (not the caption for the window)
Options 0 if the users can select anything (ie. including control panel, etc.) and 1 if the user must select a proper folder (eg. c:windows)

This returns a folder object which we will look at later. For example

Set mynewfolder = ShellControl.BrowseForFolder(Me.hwnd, _
"Choose a folder", 0)

CascadeWindows, TileHorizontally, TileVertically

Sub CascadeWindows()
Sub TileHorizontally()
Sub TileVertically()

These three methods are the same as right-clicking on the task-bar and selecting the respective item. For example:

ShellControl.CascadeWindow 'will cascade all the windows


Sub ControlPanelItem(szDir As String)

This allows you to open a control panel applet on the default page. The possible ones are:

Accessibility Options (ACCESS.CPL)
Add/Remove Programs (APPWIZ.CPL)
Display Options (DESK.CPL)
Regional Settings (INTL.CPL)
Joystick Options (JOY.CPL)
Mouse/Keyboard/Printers/Fonts Options (MAIN.CPL)
Mail and Fax Options ( MLCFG32.CPL )
Multimedia/Sounds Options ( MMSYS.CPL )
Modem Options (MODEM.CPL)
Network Options (NETCPL.CPL)
Password Options (PASSWORD.CPL)
System/Add New Hardware Options (SYSDM.CPL)
Date and Time Options (TIMEDATE.CPL)
Microsoft Mail Postoffice Options (WGPOCPL.CPL)

Some of these may not be available on your computer, and you may have some extra 3rd party ones. For example:



Sub Explore(vDir)

This opens an explorer window for the directory specified on vDir. For example:

' will open an explorer window of C:


Sub FileRun()

This opens up the run dialog, which you get from the start menu. For example:

ShellControl.FileRun ' will show the run dialog box

FindComputer, FindFiles

Sub FindComputer()
Sub FindFiles()

These methods open up the find dialogs accessible from the start menu. For example:

' will open up the find files dialog box.

MinimizeAll, UndoMinimizeAll

Sub MinimizeAll()
Sub UndoMinimizeALL()

These both do the same as clicking right button on the task bar, and selecting the respective item. 'MinimizeAll' minimizes all windows, and 'UndoMinimizeAll' will undo the previous MinimizeAll command. For example:



Sub Open(vDir)

This opens the folder specified in vDir in a default window. For example:



Sub SetTime()

This opens the set time/date dialog box, the same as the one displayed by double clicking on the clock in the system tray. For example:



Sub ShutdownWindows()

This opens the shutdown windows dialog box, which you get by clicking on shutdown on the start menu.  For example:



Sub Suspend()

This suspends the computer and goes into power saving mode. It may not work if you do not have power saving turned on. For example:



Function NameSpace(vDir) As Folder

This function returns a Folder from a string of the path. This is, as for as I know, the only way to create a folder object for a certain directory. For example:

Set myfolder = ShellControl.NameSpace("C:")

Folder Object

This is the object that explorer uses when referring to folders. One of the most useful functions is the ParseName function:

Function ParseName(bName As String) As FolderItem

This returns a FolderItem object, which we can use to get several properties about the Item. For example:

Set myfolder = ShellControl.NameSpace("C:")
Set startfile = myfolder.ParseName("autoexec.bat")

You can also enumerate all files and sub-directories using the Items collection. For example:

Dim myShell As New shell
Dim Fold As Folder
Dim FoldItem As FolderItem
Set Fold = myShell.NameSpace("C:")
For Each FoldItem In Fold.Items
List1.AddItem FoldItem.Name

FolderItem Object

With this object we can use the IsFolder and GetFolder functions to return a folder object if the item is a folder. For example:

Dim myshell As New Shell
Dim fold As Folder
Set fold=myshell.NameSpace("C:")
If fold.ParseName("windows").IsFolder Then _
MsgBox ("C:windows is a folder")

We can use the IsLink and GetLink functions to return a ShellLink object, which we will look at later, if the item is a link. We can use the ModifyDate, Size, Name and Path functions to find out more information about the file. There is also the Verbs collection. 'Verbs' are the things that you can do to files, eg. Open, Delete, Rename and Properties to name the default ones. These can be executed by using the invoke verb Function:

Sub InvokeVerb([vVerb])

vVerb can either be a string containing the name of the verb(eg. "&Open" - don't forget the shortcut key), or an index.

Now that we know all that, we can try out some examples:

Dim myshell As New Shell

This shows properties for c:autoexec.bat


This opens the c:windows directory

Debug.Print myshell.NameSpace("C:").ParseName("autoexec.bat").ModifiedDate

This returns the date that c:autoexec.bat was last modified

To enumerate all possible verbs, you can do the following:

Dim myShell As New shell
Dim Fold As Folder
Dim FoldItem As FolderItem
Dim myVerb As FolderItemVerb
Set Fold = myShell.NameSpace("C:")
Set FoldItem = Fold.ParseName("autoexec.bat")
For Each myVerb In FoldItem.Verbs
List1.AddItem myVerb.Name


This object allows you to access and modify existing links (*.lnk and *.pif). A reference to a ShellLinkObject is returned by the GetLink function of the FolderItem object. You can change the Path (what to run), WorkingDirectory, Arguments and Description properties. You can also access the ShowCommand property. This seems to be 1 for a Normal Window, 3 for opening in a maximised window and 7 for a minimised window.

The Hotkey Property is more complicated. This lowest 8 bits are the ASCII code of the character (eg A=65). The 9th bit is whether Shift is selected. The 10th bit is Ctrl, and the 11th bit is Alt. So, to make a new HotKey:

newhotkey=IIf(bAlt = True, 1024, 0) + _
IIf(bCtrl = True, 512, 0) + IIf(bShift = True, _
256, 0) + Asc(keychar)

To get the char out of a hotkey:

keychar=Chr$(hotkey And 255)

To get Shift, Ctrl and Alt:

bShift=(hotkey And 256)=256
bCtrl=(hotkey And 512)=512
bAlt=(hotkey And 1024)=1024

Don't worry if that didn't all make sense. A little maths is needed to explain it, so just use the example I have given.

GetIconLocation retrieves the index of the icon from the file. The index starts at 0 and goes up to however many icons there are, minus one. SetIconLocation allows you to set the file from which to get the icon, and the index within the file:

Dim mylink As New ShellLinkObject
mylink.SetIconLocation "c:windowssystempifmgr.dll",10
' This selects the 11th icon in pifmgr.dll (some money)

Don't forget that after you have made all the changes to save the link, using the Save method.

Have a play around. There are lots of things that you can do with this library. If you discover something that you think that other programmers will find useful, send me an email.

Note: There are some restrictions on distribution of the ShellDocVw.dll. Be careful that you don't breach any rules, etc. as you must distribute all of IE4 just to use this DLL. These functions do not work under IE 5 unfortunately.

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved