Page 1 of 5
A problem with GradientBrush()
Posted: Thu Jan 28, 2010 4:37 pm
by Enrico Maria Giordano
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
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 8:57 am
by Enrico Maria Giordano
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: Select all | Expand
#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
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 9:25 am
by anserkk
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
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 9:27 am
by Enrico Maria Giordano
So the problem is at least under XP.
EMG
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 9:36 am
by anserkk
So the problem is at least under XP.
or with the recent versions of FWH ( after 9.08 )
Anser
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 9:37 am
by Enrico Maria Giordano
Yes. I'm using 9.12.
EMG
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:11 am
by Enrico Maria Giordano
This is a workaround:
Code: Select all | Expand
#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
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:23 am
by Enrico Maria Giordano
Even worst. In the following sample, try to move the second dialog and you will see that the first dialog is painted:
Code: Select all | Expand
#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
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 10:24 am
by Enrico Maria Giordano
It looks like the gradient technique is currently not usable.

EMG
Re: A problem with GradientBrush()
Posted: Fri Jan 29, 2010 11:58 am
by ukoenig
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: Select all | Expand
#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: Select all | Expand
#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

Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 5:11 pm
by Enrico Maria Giordano
This seems to work fine but the checkbox is not transparent.

Why?
Code: Select all | Expand
#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
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 5:59 pm
by ukoenig
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

Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 7:06 pm
by Enrico Maria Giordano
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
Re: A problem with GradientBrush()
Posted: Sat Jan 30, 2010 7:09 pm
by Enrico Maria Giordano
This is one more sample that unfortunately still shows the first problem I reported:
Code: Select all | Expand
#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
Re: A problem with GradientBrush()
Posted: Sun Jan 31, 2010 12:58 am
by nageswaragunupudi
Solution for the first sample posted.
( I have set another gradient brush to the second dialog also.)
Code: Select all | Expand
#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