SRL Archive - Delphi/FPC Help and Tutorials

Creating a shorcut in delphi?


mastaraymond

2009-11-01 07:05:13

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

2009-11-01 07:35:05

Try using Actions (TActionList, TActionManager).

mastaraymond

2009-11-01 07:43:26

From: nielsie95
Try using Actions (TActionList, TActionManager).

Yes, that indeed did the trick.
ActionList + Assigning the OnShortCut event to do ActionList.IsShortCut

ShowerThoughts

2009-11-01 12:45:33

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(TargetName))) ;
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

2009-11-01 13:04:38

From: Hermen
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 right.

ShowerThoughts

2009-11-19 08:13:55

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.