FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Inserting an icon on a button
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Inserting an icon on a button
Posted: Fri Dec 06, 2019 07:36 AM

Hi,

There is a TButtonBmp button. I select a file via cGetFile and get the icon associated with the type of this file

nam:=cGetFile()
aa:=0
img:=BmpFromIcon(EXTRACTASSICON( 0, nam, @aa))

Now I need to insert this icon into the button. How can I do that ?

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 10:26 AM
Buttonaction of oBtn2 changes the bitmap < setup1.bmp > of oBtn3 to < setup2.bmp >

@ 50, 180 BTNBMP oBtn2 ;
OF oDlg FLAT ;
SIZE 64, 64 ;
PIXEL ;
RESOURCE 0xE10B ;
ACTION ( oBtn3:LoadBitmap( 'SETUP2.bmp' ), oBtn3:Refresh() ) ; // update of oBtn3
COLOR CLR_WHITE, 12088150

There is a TButtonBmp button. I select a file via cGetFile and get the icon associated with the type of this file
Now I need to insert this icon into the button. How can I do that ?


@ 50 , 280 BUTTONBMP oBtn3 BITMAP 'SETUP1.bmp' SIZE 64, 64 PIXEL OF oDlg ;
ACTION MsgAlert( "Test" )

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 10:57 AM

I didn't understand - BmpFromIcon(EXTRACTASSICON returns a bimap handle. I can't use :LoadBitmap method to enter handle

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 11:01 AM
Try with

Code (fw): Select all Collapse
@ 50, 180 BTNBMP oBtn2 ;
OF oDlg FLAT ;
SIZE 64, 64 ;
PIXEL ;
RESOURCE 0xE10B ;
ACTION ( nam:=cGetFile(), oBtn3:LoadBitmap( nam ), oBtn3:Refresh() ) ; // update of oBtn3
COLOR CLR_WHITE, 12088150
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 11:40 AM

Thanks Cristobal, everything works !

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 01:13 PM
We can use any filename as bitmap file. FWH will extract the icon and display it as bitmap of the button.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oDlg, oFont, aSave
   local aFile := { "c:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRD32.Exe", ;
                    "c:\Windows\System32\notepad.exe", ;
                    "c:\fwh\samples\pdfharu1H.pdf", ;
                    "c:\fwh\manual\fwcmd.chm" }

   aSave := SetDefaultIconSize()
   SetDefaultIconSize( 64, 64 )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-20
   DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL FONT oFont

   @  40,40 BUTTONBMP PROMPT "AcrobatReader.Exe" BITMAP aFile[ 1 ] ;
            SIZE 300,80 PIXEL OF oDlg TEXTRIGHT

   @ 140,40 BUTTONBMP PROMPT "NotePad.Exe"       BITMAP aFile[ 2 ] ;
            SIZE 300,80 PIXEL OF oDlg TEXTRIGHT

   @ 240,40 BUTTONBMP PROMPT "PdfHaru1.pdf"      BITMAP aFile[ 3 ] ;
            SIZE 300,80 PIXEL OF oDlg TEXTRIGHT

   @ 340,40 BUTTONBMP PROMPT "fwcmd.chm"         BITMAP aFile[ 4 ] ;
            SIZE 300,80 PIXEL OF oDlg TEXTRIGHT

   SetDefaultIconSize( aSave[ 1 ], aSave[ 2 ] )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil




It is not necessary to write this code
Code (fw): Select all Collapse
img:=BmpFromIcon(EXTRACTASSICON( 0, nam, @aa))

in the application program.
Both BUTTONBMP and BTNBMP automatically does this job for us, without writing this code.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion