Inserting an icon on a button

Post Reply
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Inserting an icon on a button

Post 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 ?
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Inserting an icon on a button

Post 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 :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.
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: Inserting an icon on a button

Post by Natter »

I didn't understand - BmpFromIcon(EXTRACTASSICON returns a bimap handle. I can't use :LoadBitmap method to enter handle
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Inserting an icon on a button

Post 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

 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: Inserting an icon on a button

Post by Natter »

Thanks Cristobal, everything works !
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Inserting an icon on a button

Post 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
 
Image

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.
Regards

G. N. Rao.
Hyderabad, India
Post Reply