PDA

View Full Version : Creating a shorcut in delphi?



mastaraymond
11-01-2009, 12:05 PM
How would I create a custom shortcut in delphi.. I really cannot find how to do it. Only way I can get them to work right now is using a TMainMenuItem, but I want to have this keyboard shorcut without a MenuItem.

Another way would be using Form.OnKeyUp; But this even doesn't seems to get called when the focus is in sub-components.

I'm puzzled.

nielsie95
11-01-2009, 12:35 PM
Try using Actions (TActionList, TActionManager).

mastaraymond
11-01-2009, 12:43 PM
Try using Actions (TActionList, TActionManager).
Yes, that indeed did the trick.
ActionList + Assigning the OnShortCut event to do ActionList.IsShortCut

ShowerThoughts
11-01-2009, 05:45 PM
I got the code for you, if you check out my tutorial in the computers section or my signature ;).

Edit: I see now it's not in there, but I got it here:


procedure CreateBF2ShortCut(STR:String);
var
IObject : IUnknown;
ISLink : IShellLink;
IPFile : IPersistFile;
PIDL : PItemIDList;
TargetName:String;
InFolder : array[0..MAX_PATH] of Char;
LinkName : WideString;
begin
TargetName := STR;
IObject := CreateComObject(CLSID_ShellLink) ;
ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile;
with ISLink do
begin
SetPath(pChar(TargetName)) ;
SetWorkingDirectory(pChar(ExtractFilePath(TargetNa me))) ;
end;
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
SHGetPathFromIDList(PIDL, InFolder) ;
LinkName := InFolder + '\Battlefield 2.lnk';
IPFile.Save(PWChar(LinkName), false) ;
end;

Just check out what you can do with ISlink and that is a lot, like custom Shortcut Icon etc.
Arguments also.

nielsie95
11-01-2009, 06:04 PM
I got the code for you, if you check out my tutorial in the computers section or my signature ;).

Edit: I see now it's not in there, but I got it here:
Just check out what you can do with ISlink and that is a lot, like custom Shortcut Icon etc.
Arguments also.

Just make sure you credit (http://delphi.about.com/od/windowsshellapi/a/create_lnk.htm)right.

ShowerThoughts
11-19-2009, 01:13 PM
Sorry, if there was a mistunderstanding, I said "I got the code for you", I didn't code it but I know how it works etc.
But yes I could have said it was from About.