| Header file: | shortcuts.h |
| Object name: | fSHORTCUT |
| Object index: | 1 of 1 Object |
The fSHORTCUT component was designed to be a component that can read and write shortcuts - ie. .LNK files, like those shortcuts on your desktop and in your start menu.
However, Microsoft bit me good with this one - the only way to fiddle with shortcuts is via COM interfaces - which is nice for those people running VisualC++ or Borland C++ Builder, or something highly-commercial and expensive like that. However, for those of us on a shoestring budget and are using MinGW... the functions to use COM interfaces are there, but they don't work. Currently, any shortcut that you create with this component will be damaged afterwards, so be very careful if you decide to play with it, and be sure not to overwrite something (you can only create shortcuts at the moment). I'd like to know if it does actually work under VC++ or some other compiler like that.
Anyway, here it is, in the hope that one day I can get it to work...
Last notes: this header file includes shlobj.h because it needs the definitions in that file. MinGW might complain about some extra command line commands because of COM - and give them to MinGW. Also, before you actually use the component, you'll have to call CoInitialize(), and then call CoUnInitialize() afterwards. Complicated enough? Just see the example at the end...
| Prototype | Description |
| bool CreateShortcut(char* FileName); | This function actually creates a shortcut. Please use the following functions first, to set all of the parameters for the shortcut, and then call this function. FileName is the name and path of the shortcut (for example, to put an icon on the usual desktop, just specify something like "C:\Windows\Desktop\My Shortcut.lnk" - but keep in mind that the Desktop folder DOES move!). This function will return TRUE if successful, and FALSE otherwise. The only other thing of note would be any of the things that you set that are strings - the strings are not copied, only the pointer is remembered. So that means that all of the pointers to strings that you pass along must point to valid strings until after you have created the shortcut. |
| void SetTargetFile(char* TargetFile); | You can set the file that the shortcut points to with this function. The shortcut can really be to anything - a path, a program, or a document, or even a web-address. |
| void SetDescription(char* Description); | It seems that the description is just an application defined description for the link - I don't know where this would show up, but feel free to add a description. |
| void SetHotkey(WORD Hotkey); |
This function sets the Hotkey that activates this shortcut. The first byte is the virtual key value and the top byte is a mixture of these following values (taken from the Win32 SDK Reference manual):
Where the key is set to F - this can be any VK_ value too. Once this WORD value is created, you can then pass it along to the SetHotkey() function to set the hotkey.
|
| void SetIcon(char* Path, int Index); | This function sets the icon that the shortcut will use. Let's say that we want the first icon found in SHELL32.DLL - in this case, we would pass "SHELL32.DLL" for Path, and 0 (Zero) for Index. If we wanted the tenth icon in SHELL32.DLL, we would pass 9 for Index. You can pass along any program at all for Path. |
| void SetShowHow(int ShowHow); |
This function sets how to show the program when the shortcut is activated. This value can be any one of the following values (taken from the Win32 SDK Reference Manual):
|
| void SetWorkingDirectory(char* WorkingDirectory); | This function sets the working directory of the program specified by the shortcut. You can use this to make the program think that it is in another directory and other fun stuff like that... by default this is the directory in which the program is in. |
The following snippet gives a basic idea of how to use this component.
//Initialise COM...
CoInitialize(NULL);
//Create a shortcut object...
fSHORTCUT ShortCut;
//Make up a shortcut!
ShortCut.SetTargetFile("C:\\Autoexec.bat");
ShortCut.SetDescription("AutoExec.bat");
ShortCut.SetIcon("SHELL32.DLL", 0);
ShortCut.SetShowHow(SW_SHOW);
ShortCut.CreateShortcut("C:\\Windows\\Desktop\\Shortcut to AutoExec.bat");
//Clean up COM...
CoUnInitialize();
| Back to index | The FreeFoote Foundation Classes Documentation |