after many tests, I coudn't find a solution, to define
transparent buttons with BTNBMP on a image-background.
It seems, it works only with colors and brushes.
All Tests :
Color :
Gradient :
Style :
Brush :
Image :
A extended version of sample testbtnb.prg for easy testing :
( define nStyle 1 to 5 for different backgrounds )
Copy the prg with a new name to the FWH-sample-directory and
change inside the functions the path for the brush-bmp and image.
You only need to change the number of nStyle for a different test.
To change :
DEFINE BRUSH oImage FILE "Marble.bmp"
DEFINE IMAGE oImage FILE "Background.jpg"
- Code: Select all Expand view
// Testing the FiveWin Class TBtnBmp at a DialogBox from resources
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oDlg, nStyle, hDC
SET _3DLOOK ON
DEFINE DIALOG oDlg RESOURCE "Main" // COLOR "N/B"
REDEFINE BTNBMP ID 110 OF oDlg ;
RESOURCE "Yes" ;
NOBORDER ;
ACTION oDlg:End()
REDEFINE BTNBMP ID 120 OF oDlg 2007 ;
RESOURCE "No"
REDEFINE BTNBMP ID 130 OF oDlg 2007 ;
RESOURCE "Cancel" ;
ACTION oDlg:End()
oDlg:aControls[ 1 ]:lTransparent = .t.
// ----- selected Background -------------
// -----------------------------------------------
// 1 = Color
// 2 = Gradient
// 3 = Style
// 4 = Brush
// 5 = Image
nSTYLE := 5
// -----------------------------------------------
// -----------------------------------------------
// Color
// -------
IF nSTYLE = 1
D_COLOR( oDlg )
ENDIF
// Style-Brush
// ----------------
IF nSTYLE = 3
D_BRUSH( oDlg )
ENDIF
// ImageBrush
// ----------------
IF nSTYLE = 4
DB_IMAGE( oDlg )
ENDIF
ACTIVATE DIALOG oDlg CENTERED ;
ON PAINT ( IIF( nSTYLE = 2, ( D_GRADIENT( hDC, oDlg ), ;
GradientBrush( oDlg, { { 0.3, 10389063, 16777215 }, ;
{ 0.3, 16777215, 5156778 } }, .T. ), NIL ), ;
IIF( nSTYLE = 5, DL_IMAGE( hDC, oDlg ), NIL ) ) )
return nil
// ------------- 1 ) COLOR ----------------------------------
STATIC FUNCTION D_COLOR( oDlg )
local oBrush
DEFINE BRUSH oBrush COLOR 5156778
SET BRUSH OF oDlg TO oBrush
RELEASE BRUSH oBrush
RETURN NIL
// -------------- 2 ) DIALOG - GRADIENT --------------------
STATIC FUNCTION D_GRADIENT( hDC, oDlg )
local aGrad := { { 0.3, 10389063, 16777215 },{ 0.3, 16777215, 5156778 } }
GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, .T. )
RETURN NIL
//----------------- 3 ) STYLE ----------------
FUNCTION D_BRUSH( oDlg )
LOCAL oBrush
DEFINE BRUSH oBrush STYLE "TILED"
SET BRUSH OF oDlg TO oBrush
RELEASE BRUSH oBrush
RETURN NIL
//------------- 4 ) IMAGE - BRUSH --------------------
FUNCTION DB_IMAGE( oDlg )
LOCAL oImage
DEFINE BRUSH oImage FILE "Marble.bmp"
SET BRUSH OF oDlg TO oImage
RELEASE BRUSH oImage
RETURN NIL
//------------- 5 ) IMAGE - PICTURE --------------------
FUNCTION DL_IMAGE( hDC, oDlg )
LOCAL oImage
DEFINE IMAGE oImage FILE "Background.jpg"
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , oDlg:nWidth(), oDlg:nHeight(), , .T. )
RETURN NIL
// ---------------------------------------
FUNCTION GradientBrush( oDlg, aColors , lDir)
local hDC, hBmp, hBmpOld , nWidth , nHeight
DEFAULT lDir := .T.
if Empty( oDlg:oBrush:hBitmap )
nHeight := if(lDir,oDlg:nHeight,1)
nWidth := if(lDir,1,oDlg:nWidth)
hDC = CreateCompatibleDC( oDlg:GetDC() )
hBmp = CreateCompatibleBitMap( oDlg:hDC, nWidth, nHeight )
hBmpOld = SelectObject( hDC, hBmp )
GradientFill( hDC, 0, 0, nHeight, nWidth, aColors,lDir )
DeleteObject( oDlg:oBrush:hBrush )
oDlg:oBrush:hBitmap = hBmp
oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
SelectObject( hDC, hBmpOld )
oDlg:ReleaseDC()
endif
RETURN NIL
//----------------------------------------------------------------------------//
procedure AppSys // Xbase++ requirement
return
Best Regards
Uwe