|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis is the second in a series of (probably four) articles on context menu extensions. Despite the GUI orientation of Windows programs, it is sometimes necessary to pass command line parameters to a program. The most prominent example of this in my experience has been ATL services: in order to register the COM objects within, one had to run the executable with the command line parameter "/regserver" or "/service". Up until now, there were only a few rather cumbersome methods to accomplish this task.
As I have mentioned in my previous article and some of the comments posted on it, I am extremely lazy when it comes to repetitive tasks. I don't want to do something that takes three clicks if I can get it done in one. With this in mind, I created this context menu extension that, with a couple mouse clicks and minimal typing, accomplishes the same thing as the above methods. By simply selecting "Run with Parameters" from the context menu, you are presented with a snappy dialog that allows you to specify the command-line parameters. The extension features auto-completion (a la Netscape and MSIE), a drop-down history list, and just for nostalgia's sake, a blinking DOS prompt. CodeThe code is fairly well documented, so I'm not going to go into much detail here, but I will give an overview. The The commands are stored in the registry like so:
As the name implies, the strings will appear in the drop-down combobox in the order specified by the "Order" key. In this example, /regserver followed by -install followed by /service, etc. When the user types a parameter not in the list, the value is saved to the next available key (in this case "f") and its name prefixed on to the order string (e.g. "fadbce"). If the history list is full, the last item in the order string (here, "e") is appropriated and moved to the beginning of the queue. In the above example, the key "e" would receive the new parameter value and the "Order" key would become "eadbc". When the user selects one of the items already in the list, the key name is simply moved to the head of the order string. So, if the user selects "/unregserver", the order string would become "cadbe". The autocomplete feature is fairly straightforward. In response to the As this is a pure ATL project, none of the convenient MFC wrapper classes are available ( Build Versions and RegisteringThere are several build configurations you need to consider in the project:
To register the file, simply select the appropriate version of the DLL (remember that Unicode builds will not work correctly on Win95/98), copy it to an appropriate location (Windows System Directory recommended), and run "RegSvr32 CmdLineExt.dll" from the command line. The item "Run with Parameters" will now appear when you right-click on executables!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||