Page 1 of 1
Inserting an icon on a button
Posted: Fri Dec 06, 2019 7:36 am
by Natter
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 ?
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 10:26 am
by ukoenig
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
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 10:57 am
by Natter
I didn't understand - BmpFromIcon(EXTRACTASSICON returns a bimap handle. I can't use :LoadBitmap method to enter handle
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 11:01 am
by cnavarro
Try with
Code: Select all
@ 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
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 11:40 am
by Natter
Thanks Cristobal, everything works !
Re: Inserting an icon on a button
Posted: Fri Dec 06, 2019 1:13 pm
by nageswaragunupudi
We can use any filename as bitmap file. FWH will extract the icon and display it as bitmap of the button.
Code: Select all
#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: Select all
img:=BmpFromIcon(EXTRACTASSICON( 0, nam, @aa))
in the application program.
Both BUTTONBMP and BTNBMP automatically does this job for us, without writing this code.