Page 1 of 1
How do I create an icon for my application via code?
Posted: Sat Jun 11, 2011 10:20 pm
by Ariston (BR)
Hi everybody!
I want my application to (1) check if there is an icon for it in the "\windows\start menu\" folder and (2) create the icon (shortcut) if does not exist.
I have alread found the code for Harbour/xHarbour but not for harbour-ce.
How can I do it via code?
Thanks!
Ariston Santos.
Re: How do I create an icon for my application via code?
Posted: Sun Jun 12, 2011 4:24 am
by Antonio Linares
Ariston,
I have alread found the code for Harbour/xHarbour but not for harbour-ce
Please post it here so we can review it, thanks
Re: How do I create an icon for my application via code?
Posted: Sun Jun 12, 2011 7:52 pm
by Ariston (BR)
Here is the code I found:
Code: Select all
*****************************************************************************
*** Class : ZLnk() ***
*** Descripction : To Create Shortcut Links ***
*** Author : Carles Aubia ***
*** Created on : 04.07.2006 ***
*****************************************************************************
FUNCTION CriarAtalho(cExeName)
LOCAL o
o := ZLnk():New( cExeName )
o:cNameLnk := 'SISCOM.lnk'
o:cDescription := 'Executar o SISCOM'
o:cWorkingDirectory := cFilePath( GetModuleFileName( GetInstance() ) )
o:cIconLocation := cExeName
o:cHotKey := "CTRL+SHIFT+S"
o:cFolder := 'DeskTop' //o:cFolder := 'DeskTop' or 'StartMenu' or 'StartUp' or 'Programs'
o:Run() // Create 1st shortcut on DeskTop, as indicated above
o:cFolder := 'StartMenu' //o:cFolder := 'DeskTop' or 'StartMenu' or 'StartUp' or 'Programs'
o:Run() // Create 2nd shortcut on StartMenu, as indicated above
RETURN nil
*****************************************************************************
*** ZLnk Class ***
*****************************************************************************
CLASS ZLnk
DATA cFolder AS CHARACTER INIT 'Desktop'
DATA cWindowStyle AS NUMERIC INIT 1
DATA cFile AS CHARACTER INIT ''
DATA cWorkingDirectory AS CHARACTER INIT ''
DATA cDescription AS CHARACTER INIT ''
DATA cIconLocation AS CHARACTER INIT ''
DATA cNameLnk AS CHARACTER INIT ''
DATA cHotKey AS CHARACTER INIT ''
METHOD New( cFile ) CONSTRUCTOR
METHOD Run()
ENDCLASS
*****************************************************************************
*** METHOD New( cFile ) CLASS ZLnk ***
*****************************************************************************
METHOD New( cFile ) CLASS ZLnk
::cFile := cFile
RETURN Self
*****************************************************************************
*** METHOD Run() CLASS ZLnk ***
*****************************************************************************
METHOD Run() CLASS ZLnk
LOCAL oShell, oSF, o
LOCAL cTarget
IF !File( ::cFile )
RETURN .F.
ENDIF
IF Empty( ::cNameLnk )
::cNameLnk := cFileNoExt( ::cFile ) + '.lnk'
ENDIF
oShell := TOleAuto():New( "WScript.Shell" )
IF oShell:hObj == 0
RETURN .F.
ENDIF
oSF := oShell:Get( 'SpecialFolders' )
cTarget := oSF:Item( ::cFolder )
IF Empty( cTarget )
RETURN .F.
ENDIF
o := oShell:CreateShortCut( cTarget + '\' + ::cNameLnk )
o:WindowStyle := ::cWindowStyle
o:TargetPath := ::cFile
o:WorkingDirectory := ::cWorkingDirectory
o:Description := ::cDescription
o:IconLocation := ::cIconLocation
o:HotKey := ::cHotKey
o:Save()
RETURN .T.
**************************
*** EOF() SHORTCUT.PRG ***
**************************
Re: How do I create an icon for my application via code?
Posted: Mon Jun 13, 2011 7:24 am
by Antonio Linares
Ariston,
This function is available for Windows CE, not sure if it will work on Windows mobile:
http://msdn.microsoft.com/en-us/library/ms959231.aspx
Code: Select all
#pragma BEGINDUMP
#include <windows.h>
#include <shellapi.h>
HB_FUNC( SHCREATESHORTCUT )
{
hb_retl( SHCreateShortcut( hb_parc( 1 ), hb_parc( 2 ) ) );
}
#pragma ENDDUMP
Re: How do I create an icon for my application via code?
Posted: Sun Jun 19, 2011 12:53 pm
by Ariston (BR)
After some small changes, It worked, with a small problem: It does not work if the app is stored in the “Storage Card”. Only if it is stored in the own device. When the EXE is placed in the storage card this error message shows: “Cannot find ‘Storage’. Check if required components are not missing…” (Something like this).
Here is the function changed:
Code: Select all
HB_FUNC( SHCREATESHORTCUT )
{
LPWSTR szShortcut = AnsiToWide( ( char * ) hb_parc( 1 ) );
LPWSTR szTarget = AnsiToWide( ( char * ) hb_parc( 2 ) );
hb_retl( SHCreateShortcut( szShortcut, szTarget ) );
}
Here is how I call the funciton:
Code: Select all
SHCREATESHORTCUT("\Windows\Start Menu\Programs\SisPed.lnk", CurDir()+"\sisped.exe")