How do I create an icon for my application via code?

How do I create an icon for my application via code?

Postby Ariston (BR) » Sat Jun 11, 2011 10:20 pm

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.
Ariston Santos (Macapá-Amapá-Brasil)
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
User avatar
Ariston (BR)
 
Posts: 9
Joined: Fri May 07, 2010 1:42 am
Location: Macapá - Amapá - Brasil

Re: How do I create an icon for my application via code?

Postby Antonio Linares » Sun Jun 12, 2011 4:24 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41205
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How do I create an icon for my application via code?

Postby Ariston (BR) » Sun Jun 12, 2011 7:52 pm

Here is the code I found:
Code: Select all  Expand view

*****************************************************************************
*** 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.
User avatar
Ariston (BR)
 
Posts: 9
Joined: Fri May 07, 2010 1:42 am
Location: Macapá - Amapá - Brasil

Re: How do I create an icon for my application via code?

Postby Antonio Linares » Mon Jun 13, 2011 7:24 am

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  Expand view
#pragma BEGINDUMP

#include <windows.h>
#include <shellapi.h>

HB_FUNC( SHCREATESHORTCUT )
{
   hb_retl( SHCreateShortcut( hb_parc( 1 ), hb_parc( 2 ) ) );
}

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41205
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How do I create an icon for my application via code?

Postby Ariston (BR) » Sun Jun 19, 2011 12:53 pm

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  Expand view

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  Expand view
SHCREATESHORTCUT("\Windows\Start Menu\Programs\SisPed.lnk", CurDir()+"\sisped.exe")
Ariston Santos (Macapá-Amapá-Brasil)
FWPPC, Fwh26, xHb, xDev, WorkShop, Php, MySQL.
User avatar
Ariston (BR)
 
Posts: 9
Joined: Fri May 07, 2010 1:42 am
Location: Macapá - Amapá - Brasil


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 4 guests