FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour BTNBMP on Gradient in Resources, the right way ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
BTNBMP on Gradient in Resources, the right way ?
Posted: Wed May 13, 2009 11:12 PM
Hello,

After many tests, I could solve the problem, painting BTNBMP's inside Resources with all combinations.
I'm not really shure, if there is maybe still another solution for it.
I had to use two functions :
1. The normal Gradient-Painting on Dialogs
2. I used Antonio's Function, for the Gradient-painting on transparent Buttons.
( Without Antonio's Function, Buttons are not transparent. )

Code (fw): Select all Collapse
// nSTYLE = 2 => Gradient
// D_MOVE => Color-Position
// D_DIRECT => Horizontal or Vertical

ACTIVATE DIALOG oDlg4 CENTERED NOWAIT ;
ON INIT ( oDlg4:Move( 400, 470, 430, 290, .f. ), DisableX(oDlg4, .T.), ;
        oBtn1:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ), ;
        oBtn2:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ), ;
        oBtn3:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ), ;
        oBtn4:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ), ;
        oBtn5:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ), ;
        oBtn6:SetSize( D_BUTTONH * 2, D_BUTTONV * 2, .T. ) ) ;
ON PAINT ( IIF( nSTYLE = 2 .and. D_DIRECT = 1, ;
   ( D_GRADIENT( hDC, oDlg4 ), ;
     GradientBrush( oDlg4, { { D_MOVE, D_COLOR1, D_COLOR2 },;
     { D_MOVE, D_COLOR2, D_COLOR1 } }, .T. ) ), NIL ), ;
    IIF( nSTYLE = 2 .and. D_DIRECT = 2, ;
   ( D_GRADIENT( hDC, oDlg4 ), ;
     GradientBrush( oDlg4, { { D_MOVE, D_COLOR1, D_COLOR2 },;
     { D_MOVE, D_COLOR2, D_COLOR1 } }, .F. ) ), NIL ), ;
    IIF( nSTYLE = 5, DL_IMAGE( hDC, oDlg4 ), NIL ), ;
       D_ALPHA( hDC ) )

RETURN ( NIL )



// ---- The Buttons :
// -----  1. Line, 1. Button  Transparent NOBORDER ---------

REDEFINE BTNBMP oBtn1 ID 100 OF oDlg3 ;
NOBORDER ;
FILENAME c_path + "\project\" + D_BUTTON1 ;
ACTION MsgAlert( "Button-Click", "Button 1" ) ;
PROMPT "But.1" ;
FONT oButtFont ;
RIGHT
oBtn1:lTransparent = .t.   
oBtn1:cTooltip := "Button1"

// ----- 2. Line, 1. Button Transparent BORDER ---------

REDEFINE BTNBMP oBtn4 ID 200 OF oDlg3 ;
FILENAME c_path + "\project\" + D_BUTTON1 ;
ACTION MsgAlert( "Button-Click", "Button 4" ) ;
PROMPT "But.4" ;
FONT oButtFont ;
BOTTOM
oBtn4:lTransparent = .t.   
oBtn4:cTooltip := "Button4"


// -------------- DIALOG - GRADIENT --------------------

STATIC FUNCTION D_GRADIENT( hDC, oDlg )
local aGrad := { { D_MOVE, D_COLOR1, D_COLOR2 }, ;  
                          { D_MOVE, D_COLOR2, D_COLOR1 } }    

IF D_DIRECT = 1 // Horizontal
   GradientFill( hDC,  0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, .T. )
ENDIF
IF D_DIRECT = 2 // Vertical
   GradientFill( hDC,  0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, .F. )
ENDIF

RETURN NIL

// ----- Antonio's function with added lPos ( Gradient-Direction ) -------

FUNCTION GradientBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush

if Empty( oDlg:hBitmap )
      hDC = CreateCompatibleDC( oDlg:GetDC() )
      hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
      hBmpOld = SelectObject( hDC, hBmp )
      GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
      DeleteObject( oDlg:hBrush )
      oDlg:hBitmap = hBmp
      oDlg:hBrush = CreatePatternBrush( hBmp ) 
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif   

RETURN NIL


There is still the same problem with Images to solve.


Using only Antonio's Function without < D_GRADIENT( hDC, oDlg ) >
the controls are painted without Dlg-Background.


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.

Continue the discussion