Change BtnBmp Image at runtime

Change BtnBmp Image at runtime

Postby Adolfo » Tue Mar 25, 2014 2:26 pm

Hi everyone.

I need to create a BtnBmp, really an array of BtnBmps, but I need to change Its bitmap according to external conditions.
I can't "preload" the image, since I don't know which is going to be in each position.
I already change its prompt, associated Action, tooltip but the Image, I can't

I tried
hBmp = FILoadFromMemory( oDbPro:IMAGEN)
aBoton[x,y]:hBitmap1:=hBmp
aBoton[x,y]:Refresh()

with no success at all
Any Idea will be appreciated.

Thanks in Advance

From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Change BtnBmp Image at runtime

Postby ukoenig » Tue Mar 25, 2014 2:55 pm

Adolfo,

I will add a sample to Your post.

Best regards
Uwe :lol:
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: Change BtnBmp Image at runtime

Postby Adolfo » Tue Mar 25, 2014 3:38 pm

Thanks Uwe.
I'll be waiting... ;-)

From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Change BtnBmp Image at runtime

Postby ukoenig » Tue Mar 25, 2014 7:03 pm

Adolfo,
the sample :

oBtn1:SetFile( ..\bitmaps\Info.Bmp", ..\bitmaps\Info.Bmp" ) // can be different
oBtn2:SetFile( ..\bitmaps\Info.Bmp", ..\bitmaps\Info.Bmp" )


Original Bmp's changed to Info.bmp
Button 1 changes button 2
and button 2 changes button 1
Bmp-change with radio and checkbox-selection


You can define two images UP and DOWN !

Image

Code: Select all  Expand view

#Include "Fivewin.ch"

STATIC oFont

Function Main()
Local oWnd, oDlg, oFld, oBtn1, oBtn2, oBtn3
Local oFont, oBrush1, oBrush2, oBrush3
Local c_path, c_path1
Local oCbx1, nCbx1 := 3, oRadio1, nRadio1 := 3

c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "SYSTEM\"

oFont  := TFont():New("
Arial",,-14,.F.,.T. ,,,,.F. )

DEFINE BRUSH oBrush1  GRADIENT { { 0.50, 16710607, 16759929 }, { 0.50, 16759929, 16710607 } }
DEFINE BRUSH oBrush2 GRADIENT { { 1, 16710607, 16759929 } }
DEFINE BRUSH oBrush3 GRADIENT { { 1, 16759929, 16710607 } }

oFont  := TFont():New("
Arial",,-14,.F.,.F. ,,,,.F. )

DEFINE WINDOW oWnd TITLE "
Foldertest FWH-version => "  + FWVERSION  BRUSH oBrush1

DEFINE DIALOG oDlg FROM 50, 50 TO 450, 610 TITLE "
Test folder" PIXEL OF oWnd BRUSH oBrush2

@ 15, 10 FOLDEREX SIZE 260, 170 oFld PIXEL ROUND 5 UPDATE ;
PROMPT  "
Page &1", "Page &2", "&EXIT" OF oDlg ;
ON PAINT TAB PaintTab( Self, nOption );
ON CHANGE ( nSavePage := oFld:nOption, ;
                            IF( nOption == 3, If( MsgYesNo( "
Do you want exit??" ), ;
                                                                oWnd:End(), ( ::SetOption( nOldOption ), ::Refresh() ) ), ) ) ;                        
ON PAINT TEXT( If( nOption == ::nOption .and. nOption == 2, 8388608, 0 ) );
TOP OPTION 1 ALIGN 0, 0, 0

 oFld:lTransparent := .T.
oFld:nFolderHeight := 40
oFld:nSeparator := 2
oFld:bClrText := {| o, n | 128 }
oFld:oFont := oFont
oFld:nOption := 1

oFld:aDialogs[ 1 ]:SetBrush( oBrush1 )
oFld:aDialogs[ 2 ]:SetBrush( oBrush2 )
oFld:aDialogs[ 3 ]:SetBrush( oBrush3 )

@ 20, 50 BTNBMP oBtn1 OF oFld:adialogs[1] ;
SIZE 50, 30 PIXEL 2007 ;
NOBORDER ;
PROMPT "
Change &2" ;
FILENAME c_path1 + "
Exit1.Bmp" ;
ACTION oBtn2:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ) ;
FONT oFont ;
TOP
oBtn1:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
    { { 0.50, 11513775, 16777215 }, ;
    { 0.50, 16777215, 11513775 } }, ;
    { { 0.50, 16761992, 16777215 }, ;
    { 0.50, 16777215, 16761992 } } ) }
oBtn1:lTransparent := .t.
oBtn1:cToolTip =  { "
Test" + CRLF + "Button 1","Button", 1, CLR_BLACK, 14089979 }
oBtn1:SetColor( 0, )

@ 60, 50 BTNBMP oBtn2 OF oFld:adialogs[1] ;
SIZE 50, 30 PIXEL 2007 ;
NOBORDER ;
PROMPT "
Change &1" ;
FILENAME c_path1 + "
Preview.Bmp" ;
ACTION oBtn1:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ) ;
FONT oFont ;
TOP
oBtn2:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
    { { 0.50, 6711039, 16777215 }, ;
    { 0.50, 16777215, 6711039 } }, ;
    { { 0.50, 16761992, 16777215 }, ;
    { 0.50, 16777215, 16761992 } } ) }
oBtn2:lTransparent := .t.
oBtn2:cToolTip =  { "
Change Image" + CRLF + "Button 1","CHANGE", 1, CLR_BLACK, 14089979 }
oBtn2:SetColor( 0, )

@ 100, 50 BTNBMP oBtn3 OF oFld:adialogs[1] ;
SIZE 50, 30 PIXEL 2007 ;
NOBORDER ;
PROMPT "
&Reset" ;
FILENAME c_path1 + "
Recall.Bmp" ;
ACTION ( nSelect1 := .F., nSelect2 := .F. , ;
              oBtn1:SetFile( c_path1 + "
Exit1.Bmp", c_path1 + "Exit1.Bmp" ), ;
              oBtn2:SetFile( c_path1 + "
Preview.Bmp", c_path1 + "Preview.Bmp" ), ;
              nRadio1 := 3, oRadio1:Refresh(), ;
          nCbx1 := 3, oCbx1:Refresh() ) ;        
FONT oFont ;
TOP
oBtn3:bClrGrad = { | lMouseOver | If( ! lMouseOver,;
    { { 0.50, 3067734, 16777215 }, ;
    { 0.50, 16777215, 3067734 } }, ;
    { { 0.50, 3145727, 16777215 }, ;
    { 0.50, 16777215, 3145727 } } ) }
oBtn3:lTransparent := .t.
oBtn3:cToolTip =  { "
Change Image" + CRLF + "Button 1","CHANGE", 1, CLR_BLACK, 14089979 }
oBtn3:SetColor( 0, )

// ------------------------

@ 20, 125 COMBOBOX oCbx1 VAR nCbx1  ITEMS { "
Change Button 1", "Change Button 2", "Reset" } ;
SIZE 110, 100 OF oFld:adialogs[1]  PIXEL ;
ON CHANGE ( IIF( nCbx1 = 1, oBtn1:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ), NIL ), ;  
     IIF( nCbx1 = 2, oBtn2:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ), NIL ), ;
     IIF( nCbx1 = 3, ( oBtn1:SetFile( c_path1 + "
Exit1.Bmp", c_path1 + "Exit1.Bmp" ), ;
          oBtn2:SetFile( c_path1 + "
Preview.Bmp", c_path1 + "Preview.Bmp" ) ), NIL ) )             
               
oCbx1:oFont := oFont

// -----

@ 55, 125 RADIO oRadio1 VAR nRadio1 ITEMS "
Button 1", "Button 2", "Reset" SIZE 40, 15 ;
OF oFld:adialogs[1] PIXEL ;
ON CHANGE { || ( IIF( nRadio1 = 1, oBtn1:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ), NIL ), ;  
    IIF( nRadio1 = 2, oBtn2:SetFile( c_path1 + "
Info.Bmp", c_path1 + "Info.Bmp" ),NIL), ;
    IIF( nRadio1 = 3, ( oBtn1:SetFile( c_path1 + "
Exit1.Bmp", c_path1 + "Exit1.Bmp" ), ;
         oBtn2:SetFile( c_path1 + "
Preview.Bmp", c_path1 + "Preview.Bmp" ) ),NIL) ) } UPDATE

AEval( oRadio1:aItems, { | oRad | oRad:lTransparent := .T., ;
     oRad:SetFont ( oFont ), oRad:nClrText := 0 } )

ACTIVATE DIALOG oDlg NOWAIT CENTER

ACTIVATE WINDOW oWnd MAXIMIZED

RELEASE BRUSH oBrush1, oBrush2, oBrush3, oFont

RETURN NIL

// ------------------------

FUNCTION PaintTab( o, nOption )

IF nOption == o:nOver .OR. nOption == o:nOption
      o:SetAlphaLevel( nOption, 255 )
ELSE
      o:SetAlphaLevel( nOption, 50 )
ENDIF
   
RETURN o:SetFldColors( o, nOption )    


Best regards
Uwe :lol:
Last edited by ukoenig on Tue Mar 25, 2014 7:38 pm, edited 11 times in total.
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: Change BtnBmp Image at runtime

Postby Rick Lipkin » Tue Mar 25, 2014 7:06 pm

Adolfo

Check out this thread .. I asked the same question myself ..

Rick Lipkin
viewtopic.php?f=3&t=26855&p=148946#p148946
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Change BtnBmp Image at runtime

Postby Adolfo » Tue Mar 25, 2014 7:45 pm

Thanks.

But there is a tiny problem... The Image is loaded from a BLOB field in an Mysql DB... so the use of oBtn2:SetFile() won't work, since theres no "file" to load.
I do have the image handle in hBmp

I tried ti load it directly with ::loadbitmaps() with no success

Any idea will be appreciated

From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Change BtnBmp Image at runtime

Postby Adolfo » Tue Mar 25, 2014 8:02 pm

Done...

Here's the code


.............
If Len(Alltrim(oDbPro:IMAGEN)) > 0
aBoton[x,y]:hBitmap1 := FILoadFromMemory( oDbPro:IMAGEN, 10 )
aBoton[x,y]:hPalette1 := 0
Endif

For some reason, if the first BMP is null, the others won't work, so asking if there is something inside oDbPro:IMAGEN solve the problem.
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests

cron