Inserting an icon on a button

Inserting an icon on a button

Postby Natter » Fri Dec 06, 2019 7: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 ?
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Inserting an icon on a button

Postby ukoenig » 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 :D
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Inserting an icon on a button

Postby Natter » 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
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Inserting an icon on a button

Postby cnavarro » Fri Dec 06, 2019 11:01 am

Try with

Code: Select all  Expand view  RUN


@ 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
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Inserting an icon on a button

Postby Natter » Fri Dec 06, 2019 11:40 am

Thanks Cristobal, everything works !
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Inserting an icon on a button

Postby nageswaragunupudi » Fri Dec 06, 2019 1:13 pm

We can use any filename as bitmap file. FWH will extract the icon and display it as bitmap of the button.
Code: Select all  Expand view  RUN
#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
 


Image

It is not necessary to write this code
Code: Select all  Expand view  RUN

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
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests