FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour A problem with GradientBrush()
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
A problem with GradientBrush()
Posted: Thu Jan 28, 2010 04:37 PM

In the sample gradbrus.prg, please try to click on "First" button, then on "Another" button and then close and reopen the second dialog many times. Now move the second dialog over the first. You will see that the first dialog is now painted with robbish.

Any hint on how to fix this behavior?

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 08:57 AM
A reduced sample of the problem. Just click on the button and move the second dialog over the first. You will see the problem:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush: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 )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


EMG
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 09:25 AM

Dear EMG,

I tested your sample code but I did not experience the problem which you have explained. For me it is working fine.

I am using Vista Business, FWH 9.08.

Regards
Anser

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 09:27 AM

So the problem is at least under XP.

EMG

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 09:36 AM
So the problem is at least under XP.


or with the recent versions of FWH ( after 9.08 )

Anser
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 09:37 AM

Yes. I'm using 9.12.

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:11 AM
This is a workaround:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    oDlg:aControls[ 1 ]:bLostFocus = { || oDlg:Refresh() }

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SendMsg( WM_PAINT );
             ON PAINT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush: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 )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


Any better ideas?

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:23 AM
Even worst. In the following sample, try to move the second dialog and you will see that the first dialog is painted:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SendMsg( WM_PAINT );
             ON PAINT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld
   
    IF EMPTY( oDlg:oBrush: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 )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:24 AM

It looks like the gradient technique is currently not usable. :-(

EMG

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 11:58 AM
Enrico,

like Anser, I use Vista as well.
I call the Gradient-painting ON INIT using Function GRADIENTBRUSH

Pushing the < Test-button >, opens Dialog 2


Using a 2. Dialog, moving over Dialog 1


It is not a XP-problem. Maybe a change in Function < GRADIENTBRUSH > needed ?

Code (fw): Select all Collapse
#include "FiveWin.ch"

FUNCTION MAIN()
LOCAL oDlg1

DEFINE DIALOG oDlg1

@ 1, 1 BUTTON "Test";
           ACTION TEST()

ACTIVATE DIALOG oDlg1 CENTER ;
ON INIT ( GRADBRUSH( oDlg1, { { 1, 14198567, 16117445 } }, .T. ), ;
                 oDlg1:Move( 110, 460, 430, 215, .f. ) )

RETURN NIL

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

FUNCTION TEST()
LOCAL oDlg2

DEFINE DIALOG oDlg2

ACTIVATE DIALOG oDlg2 CENTER ;
ON INIT ( GRADBRUSH( oDlg2, { { 1, 128, 16117445 } }, .T. ), ;
                 oDlg2:Move( 200, 500, 430, 215, .f. ) )

*ON INIT oDlg2:SendMsg( WM_PAINT )

RETURN NIL

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

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

if Empty( oDlg:oBrush: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:oBrush:hBrush )
      oDlg:oBrush:hBitmap = hBmp
      oDlg:oBrush:hBrush = CreatePatternBrush( hBmp ) 
      SelectObject( hDC, hBmpOld )
      oDlg:ReleaseDC()
endif   

RETURN NIL


A working Solution using ON PAINT only with GradientFill :
( GRADIENTBRUSH was created, to solve the Transparent-Problem )


Code (fw): Select all Collapse
#include "FiveWin.ch"
Static hDC

FUNCTION MAIN()
LOCAL oDlg1

DEFINE DIALOG oDlg1

@ 1, 1 BUTTON "Test";
           ACTION TEST()

ACTIVATE DIALOG oDlg1 ;
ON PAINT  DLG_GRAD( hDC, oDlg1, { { 1, 14198567, 16117445 } }, .T. ) ;
ON INIT oDlg1:Move( 110, 460, 430, 215, .f. ) 

RETURN NIL

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

FUNCTION TEST()
LOCAL oDlg2

DEFINE DIALOG oDlg2

ACTIVATE DIALOG oDlg2 CENTER ;
ON PAINT DLG_GRAD( hDC, oDlg2, { { 1, 128, 16117445 } }, .T. ) ;
ON INIT oDlg2:Move( 200, 500, 430, 215, .f. ) 

RETURN NIL

// --------------  GRADIENT --------------------

STATIC FUNCTION DLG_GRAD( hDC, oDlg, aGrad, lPos )

GradientFill( hDC,  0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, lPos )

RELEASEDC( hDC )

RETURN NIL


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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 05:11 PM
This seems to work fine but the checkbox is not transparent. :-) Why?

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL lVar := .F.

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    @ 3, 1 CHECKBOX lVar

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:oBrush := GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg;
           TRANSPARENT

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:oBrush := GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld, oBrush
   
    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 )
    oBrush = TBrush():New( , , , , hBmp )
    SELECTOBJECT( hDC, hBmpOld )
    DELETEDC( hDC )
    oDlg:ReleaseDC()

    RETURN oBrush


EMG
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 05:59 PM
Enrico,

the transparent-painting for the checkbox works,
but uses a wrong gradient ( from top )

with same colors ( no gradient ) :
GRADIENTBRUSH( oDlg1, { { 1, RGB( 103, 154, 194 ), RGB( 103, 154, 194 ) } } )


Moving the checkbox to Dialog-Top-position :
GRADIENTBRUSH( oDlg1, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } )


to solve this problem, I used only the checkbox-square and a extra text.


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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 07:06 PM
ukoenig wrote:to solve this problem, I used only the checkbox-square and a extra text.


It doesn't solve the problem because also the radio buttons are not transparent. :-)

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 07:09 PM
This is one more sample that unfortunately still shows the first problem I reported:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL lVar := .F.

    DEFINE DIALOG oDlg;
           TRANSPARENT

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    @ 3, 1 CHECKBOX lVar

    oDlg:oBrush = TBrush():New()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION TEST()

    LOCAL oDlg

    DEFINE DIALOG oDlg;
           TRANSPARENT

    oDlg:oBrush = TBrush():New()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RETURN NIL


FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld

    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 )

    DELETEOBJECT( oDlg:oBrush:hBrush )

    oDlg:oBrush:hBitmap = hBmp
    oDlg:oBrush:hBrush  = CREATEPATTERNBRUSH( hBmp )

    SELECTOBJECT( hDC, hBmpOld )

    DELETEDC( hDC )

    oDlg:ReleaseDC()

    RETURN NIL


EMG
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: A problem with GradientBrush()
Posted: Sun Jan 31, 2010 12:58 AM
Solution for the first sample posted.
( I have set another gradient brush to the second dialog also.)

Code (fw): Select all Collapse
#include "Fivewin.ch"

FUNCTION MAIN()

    LOCAL oDlg, oBrush  // added oBrush

    DEFINE BRUSH oBrush   // inserted
    DEFINE DIALOG oDlg BRUSH oBrush

    @ 1, 1 BUTTON "Test";
           ACTION TEST()

    ACTIVATE DIALOG oDlg;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
             CENTER

    RELEASE BRUSH oBrush // inserted
    RETURN NIL

FUNCTION TEST()

    LOCAL oDlg, oBrush
  
    // gradient brush for this dialog also
    DEFINE BRUSH oBrush  
    DEFINE DIALOG oDlg BRUSH oBrush

    ACTIVATE DIALOG oDlg;
             CENTER ;
             ON INIT GRADIENTBRUSH( oDlg, { { 1, CLR_RED, CLR_WHITE } } );


    RELEASE BRUSH oBrush
    RETURN NIL

FUNCTION GRADIENTBRUSH( oDlg, aColors )

    LOCAL hDC, hBmp, hBmpOld

    IF EMPTY( oDlg:oBrush: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 )
        DELETEOBJECT( oDlg:oBrush:hBrush )
        oDlg:oBrush:hBitmap = hBmp
        oDlg:oBrush:hBrush = CREATEPATTERNBRUSH( hBmp )
        oDlg:oBrush:cBmpfile = LTrim( Str( hBmp ) ) // inserted to trick the aBrushes behavior
        SELECTOBJECT( hDC, hBmpOld )
        DELETEDC( hDC )
        oDlg:ReleaseDC()
    ENDIF

    RETURN NIL
Regards



G. N. Rao.

Hyderabad, India