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.
How do I create an icon for my application via code?
- Ariston (BR)
- Posts: 9
- Joined: Fri May 07, 2010 1:42 am
- Location: Macapá - Amapá - Brasil
- Contact:
How do I create an icon for my application via code?
Ariston Santos (Macapá-Amapá-Brasil)
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: How do I create an icon for my application via code?
Ariston,
Please post it here so we can review it, thanksI have alread found the code for Harbour/xHarbour but not for harbour-ce
- Ariston (BR)
- Posts: 9
- Joined: Fri May 07, 2010 1:42 am
- Location: Macapá - Amapá - Brasil
- Contact:
Re: How do I create an icon for my application via code?
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 ***
**************************
Ariston Santos (Macapá-Amapá-Brasil)
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: How do I create an icon for my application via code?
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
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
- Ariston (BR)
- Posts: 9
- Joined: Fri May 07, 2010 1:42 am
- Location: Macapá - Amapá - Brasil
- Contact:
Re: How do I create an icon for my application via code?
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:
Here is how I call the funciton:
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 ) );
}
Code: Select all
SHCREATESHORTCUT("\Windows\Start Menu\Programs\SisPed.lnk", CurDir()+"\sisped.exe")
Ariston Santos (Macapá-Amapá-Brasil)
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.