A problem with GradientBrush()
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
A problem with GradientBrush()
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
Any hint on how to fix this behavior?
EMG
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
A reduced sample of the problem. Just click on the button and move the second dialog over the first. You will see the problem:
EMG
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()
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
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
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
So the problem is at least under XP.
or with the recent versions of FWH ( after 9.08 )
Anser
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
This is a workaround:
Any better ideas?
EMG
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
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
Even worst. In the following sample, try to move the second dialog and you will see that the first dialog is painted:
EMG
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
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
It looks like the gradient technique is currently not usable. 
EMG

EMG
Re: A problem with GradientBrush()
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 ?
A working Solution using ON PAINT only with GradientFill :
( GRADIENTBRUSH was created, to solve the Transparent-Problem )

Best Regards
Uwe
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

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.
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
This seems to work fine but the checkbox is not transparent.
Why?
EMG

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()
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
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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
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
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: A problem with GradientBrush()
This is one more sample that unfortunately still shows the first problem I reported:
EMG
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
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: A problem with GradientBrush()
Solution for the first sample posted.
( I have set another gradient brush to the second dialog also.)
( 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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India