Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New VB6 Tutorial: Creating Shell Commands
#1
I hope this helps someone out...I've tested this in Windows 98 as well as Windows XP, so it seems to be quite universal.

Quote:CREATING SIMPLE SHELL COMMANDS
by Necros Ihsan Nodtveidt
Finished March 22nd, 2004 at 12:31AM Atlantic Standard Time! Smile

PRIMER
This quick tutorial is intended to show how to create simple shell commands for folders. It is not intended to be used as a registry guide, nor an exhaustive programming guide. It is assumed that the user has a solid understanding of string manipulation and directory structure.

I recommend downloading the Registry Module for quickest results in this demonstration. It's a collection of registry and control functions that are not intrinsic to Visual Basic 6. It is comprised of mostly third-party code snippets.

THE BASICS
Basic shell commands are kept within HKEY_CLASSES_ROOT under the Directory key. The focus of this quick tutorial is on the 'shell' key under the Directory key.

CREATING THE SHELL COMMAND
We'll need a "Parent" key that will contain a value to be displayed in the shell. For the purposes of this demonstration, we'll call it "My.Command". Create a key like so:

HKEY_CLASSES_ROOT\Directory\shell\My.Command

As with all created keys, there will be a Default value. You will need to alter this to change the text for your shell command. If using the Registry Module from this page, you set a default value by passing no value for the 'Key' argument. The ampersand rule applies in setting the default value, so you'll be able to set a keyboard shortcut just like when you build any menu in Visual Basic 6.

Now that you have the Parent key, you need a Command key. Create a child key from My.Command:

HKEY_CLASSES_ROOT\Directory\shell\My.Command\command

This will tell Windows that your new key has a command that can be invoked. Again, this new key has a default value which you will set with your executable file and a %1. You will need to enclose both in double quotes, like so:

"C:\Program Files\My Program\My Program.exe" "%1"

You can easily do this in VB by using Chr$(34).

CONSIDERATIONS
-Upon using your new shell command, your application will receive a Command$ when it starts. This Command$ will likely be enclosed in double quotes.
-Multiple folders can be selected and opened with your new shell command. When this happens, multiple instances of your program are started.
-This technique can also be used on the Drive key as opposed to the Directory key. This will pass the root of the drive as the Command$. This can be quite useful for programs which affect entire drives.
-Don't use + to combine strings. VB will convert string variables to Variants before combining them if you use this method, which is inefficient. Use & to combine string variables.
-An easy way of keeping the registry setting up-to-date in case your program ever moves is to write its location on startup using the application's current path. An often-used mistake is to directly rely on App.Path for this. However, since App.Path will return a backslash for a drive root and no backslash for normal directories, it is wise to copy App.Path to a string variable and then check its last character with the Right$ function. It is always a good idea to make sure your directory string has a trailing backslash:

Dim appie As String
appie = App.Path
If Right$(appie, 1) <> "\" Then appie = appie & "\"
I'd knock on wood, but my desk is particle board.
Reply
#2
Woohoo! Thanx nek. This will surely help me in my VB progging =)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)