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
Change BtnBmp Image at runtime
Change BtnBmp Image at runtime

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Re: Change BtnBmp Image at runtime
Adolfo,
I will add a sample to Your post.
Best regards
Uwe
I will add a sample to Your post.
Best 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.
i work with FW.
If you have any questions about special functions, maybe i can help.
Re: Change BtnBmp Image at runtime
Thanks Uwe.
I'll be waiting...
From Chile
Adolfo
I'll be waiting...

From Chile
Adolfo

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Re: Change BtnBmp Image at runtime
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 !

Best regards
Uwe
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 !

Code: Select all | Expand
#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

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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- Rick Lipkin
- Posts: 2668
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Change BtnBmp Image at runtime
Adolfo
Check out this thread .. I asked the same question myself ..
Rick Lipkin
viewtopic.php?f=3&t=26855&p=148946#p148946
Check out this thread .. I asked the same question myself ..
Rick Lipkin
viewtopic.php?f=3&t=26855&p=148946#p148946
Re: Change BtnBmp Image at runtime
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
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

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Re: Change BtnBmp Image at runtime
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.
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.

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650