Page 2 of 2
Re: can create shortcut in unicode mode
Posted: Wed Jul 21, 2010 9:51 am
by Klonk
Thanks guys, works now and I'm trying to understand how it works. Basically simply a COM function is called, right?
I have another question: How to define Hotkeys?
I found the Modifiers, and I guess I have to OR them with the hotkey itself, but what value woud be correct for lets say CTRL+A ?
How to find out the correct values for Hotkey? The Purebasic ASC command does not help here.
Re: can create shortcut in unicode mode
Posted: Thu Sep 20, 2012 11:13 pm
by luis
Modified the original code to work in ascii/unicode mode with PB 4.61 (the interfaces are using automatic string conversion to unicode now through pseudotypes)
Code: Select all
Procedure.i CreateShortcut (TargetPath$, LinkPath$, TargetArgument$, TargetDescription$, WorkingDirectory$, iShowCommand, IconFile$, iIconIndexInFile)
; [DESC]
; Create a shortcut for the specified target.
;
; IN
; TargetPath$ ; The full pathname of the target.
; LinkPath$ ; The full pathname of the shortcut link (the actual .lnk file).
; TargetArgument$ ; The argument(s) to be passed to the target.
; TargetDescription$ ; A description of the shortcut (it will be visible as a tooltip).
; WorkingDirectory$ ; The desired working directory for the target.
; iShowCommand ; Start mode (SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED)
; IconFile$ ; The full pathname of the file containing the icon to be used (usually the target itself).
; iIconIndexInFile ; The index for the icon to be retrieved form the icon file.
;
; [RETURN]
; 1 if successful, else 0.
;
; [NOTES]
; Original author: Micko (+ srod)
; http://www.purebasic.fr/english/viewtopic.php?t=32806
; Ascii & Unicode
; Debug CreateShortcut ("C:\temp\program.exe", "C:\Users\luis\Desktop\program.lnk", "arg1 arg2","Test shortcut.","c:\temp", #SW_SHOWMAXIMIZED, "C:\temp\program.exe", 0)
CompilerIf Defined(CLSCTX_INPROC_SERVER, #PB_Constant) = 0
#CLSCTX_INPROC_SERVER = 1
CompilerEndIf
Protected *psl.IShellLinkW, *ppf.IPersistFile
Protected iRetVal
CoInitialize_(#Null)
If CoCreateInstance_(?CLSID_ShellLink, 0, #CLSCTX_INPROC_SERVER, ?IID_IShellLinkW, @*psl) = #S_OK
; The file to which is linked ( = target for the Link )
*psl\SetPath(TargetPath$)
; Arguments for the Target
*psl\SetArguments(TargetArgument$)
; Working Directory
*psl\SetWorkingDirectory(WorkingDirectory$)
; Description ( also used as Tooltip for the Link )
*psl\SetDescription(TargetDescription$)
; Show command:
; SW_SHOWNORMAL = Default
; SW_SHOWMAXIMIZED = Maximized
; SW_SHOWMINIMIZED = Minimized
*psl\SetShowCmd(iShowCommand)
; Hotkey (not implemented):
; The virtual key code is in the low-order byte,
; and the modifier flags are in the high-order byte.
; The modifier flags can be a combination of the following values:
;
; HOTKEYF_ALT = ALT key
; HOTKEYF_CONTROL = CTRL key
; HOTKEYF_EXT = Extended key
; HOTKEYF_SHIFT = SHIFT key
*psl\SetHotkey(#Null)
; Icon for the Link:
; There can be more than 1 icons in an icon resource file,
; so you have to specify the index.
*psl\SetIconLocation(IconFile$, iIconIndexInFile)
; Query IShellLink for the IPersistFile interface for saving the
; shortcut in persistent storage.
If *psl\QueryInterface(?IID_IPersistFile, @*ppf) = 0
;Save the link by calling IPersistFile::Save.
If *ppf\Save(LinkPath$, #True) = #S_OK
iRetVal = 1
EndIf
*ppf\Release()
EndIf
*psl\Release()
EndIf
CoUninitialize_()
ProcedureReturn iRetVal
DataSection
CLSID_ShellLink:
; 00021401-0000-0000-C000-000000000046
Data.l $00021401
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
IID_IPersistFile:
; 0000010b-0000-0000-C000-000000000046
Data.l $0000010B
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
IID_IShellLinkW: ; {000214F9-0000-0000-C000-000000000046}
Data.l $000214F9
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection
EndProcedure