A problem with GradientBrush()
- Enrico Maria Giordano
- Posts: 8758
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: A problem with GradientBrush()
It would seem that we now need to move these changes into TDialog so one doesn't have to write code for each dialog using a brush.
Regards,
James
Regards,
James
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
Rao,
Many thanks!
Lets see if we can migrate those changes into FWH classes
Many thanks!

Lets see if we can migrate those changes into FWH classes
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
Enrico,
Your examples on Windows 7 work fine
Going to test them on XP...
Your examples on Windows 7 work fine
Going to test them on XP...
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
Enrico,
Statements like these should not be used:
because the above does not respect the FWH brushes reuse implementation.
Instead, method oWnd:SetBrush( oBrush ) should be used.
Statements like these should not be used:
Code: Select all | Expand
oDlg:oBrush = TBrush():New()
because the above does not respect the FWH brushes reuse implementation.
Instead, method oWnd:SetBrush( oBrush ) should be used.
- Enrico Maria Giordano
- Posts: 8758
- 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()
Enrico,
I'm still testing as well the Gradients and Brushes.
I need a working example to adjust a Brush to Dialog-Size ( a Image is used ).
I don't know what's wrong, but anyway, i don't get it working.
The results don't look as aspected.
// a. Now any image file ( jpg, png, etc. ) can be used to create a Brush.
// b. Brush can also be created from a bitmap handle by
// specifying the handle as the fifth parameter of TBrush():New() method.
must be used like :
TBrush():New( nil, nil, nil, nil, hBmp )
Do You have a working example for this ?
Best Regards
Uwe
I'm still testing as well the Gradients and Brushes.
I need a working example to adjust a Brush to Dialog-Size ( a Image is used ).
I don't know what's wrong, but anyway, i don't get it working.
The results don't look as aspected.
// a. Now any image file ( jpg, png, etc. ) can be used to create a Brush.
// b. Brush can also be created from a bitmap handle by
// specifying the handle as the fifth parameter of TBrush():New() method.
must be used like :
TBrush():New( nil, nil, nil, nil, hBmp )
Do You have a working example for this ?
Best Regards
Uwe

Last edited by ukoenig on Mon Feb 01, 2010 11:00 pm, edited 1 time in total.
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: 8758
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- Enrico Maria Giordano
- Posts: 8758
- 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()
One more problem. How can I get transparent controls (ie. the SAY in the following sample) and not transparent image control at the same time?
EMG
Code: Select all | Expand
#include "Fivewin.ch"
#include "Image.ch"
FUNCTION MAIN()
LOCAL oDlg
DEFINE DIALOG oDlg;
TRANSPARENT
@ 0, 0 SAY "This is a test"
@ 1, 1 IMAGE;
SIZE 50, 50;
FILE "e:\fwharbour\bitmaps\select.bmp";
NOBORDER ADJUST
oDlg:SetBrush( 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
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
Enrico,
Yes, you can use:
but never use:
because this way the brush "counter" does not get incremented.
Yes, you can use:
Code: Select all | Expand
oDlg:SetBrush( TBrush():New() )
but never use:
Code: Select all | Expand
oDlg:oBrush = TBrush():New()
because this way the brush "counter" does not get incremented.
- Enrico Maria Giordano
- Posts: 8758
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
- nageswaragunupudi
- Posts: 10722
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: A problem with GradientBrush()
Mr EMG
>>
One more problem. How can I get transparent controls (ie. the SAY in the following sample) and not transparent image control at the same time?
>>
Please try this modified code:
function GradientBrush will be the same as in the code posted by me already.
Result:

>>
One more problem. How can I get transparent controls (ie. the SAY in the following sample) and not transparent image control at the same time?
>>
Please try this modified code:
#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL oDlg, oBrush
LOCAL cPath := 'c:\fwh\bitmaps\' // change to your path
DEFINE BRUSH oBrush
DEFINE DIALOG oDlg SIZE 240,200 PIXEL BRUSH oBrush TRANSPARENT
@ 10, 10 SAY 'Say on Transparent Dialog' SIZE 100,10 PIXEL OF oDlg
@ 25, 25 IMAGE FILE cPath + "select.bmp" SIZE 20,20 PIXEL NOBORDER ADJUST
@ 50, 25 IMAGE FILE cPath + "AlphaBmp\ichat.bmp" SIZE 50,50 PIXEL NOBORDER ADJUST
ACTIVATE DIALOG oDlg;
ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
CENTER
RELEASE BRUSH oBrush
RETURN NIL
function GradientBrush will be the same as in the code posted by me already.
Result:

Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
Enrico,
Please try this example which provides a good understanding about how brushes reuse works.
The problem with your examples is that you were modifying a brush that was already in use by the previous dialog. The solution is to end() its use and create a new one, so we don't interfere with the original one.
Please try this example which provides a good understanding about how brushes reuse works.
The problem with your examples is that you were modifying a brush that was already in use by the previous dialog. The solution is to end() its use and create a new one, so we don't interfere with the original one.
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 GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
CENTER
oDlg:oBrush:End()
MsgInfo( oDlg:oBrush:nCount )
RETURN NIL
FUNCTION TEST()
LOCAL oDlg
DEFINE DIALOG oDlg;
TRANSPARENT
ACTIVATE DIALOG oDlg;
ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
CENTER
oDlg:oBrush:End()
MsgInfo( oDlg:oBrush:nCount )
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 )
oDlg:oBrush:End()
oDlg:SetBrush( TBrush():New( ,,,, hBmp ) )
AEval( oDlg:aControls, { | o | o:SetBrush( oDlg:oBrush ) } )
SELECTOBJECT( hDC, hBmpOld )
DELETEDC( hDC )
oDlg:ReleaseDC()
RETURN NIL
- Antonio Linares
- Site Admin
- Posts: 42560
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 32 times
- Been thanked: 80 times
- Contact:
Re: A problem with GradientBrush()
In this example, lets asume that we want to use the same gradient colors for all our dialogs, so we can create just one brush and reuse it in all dialogs:
Code: Select all | Expand
#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL oDlg
LOCAL lVar := .F.
DEFINE DIALOG oDlg;
TRANSPARENT
@ 1, 1 BUTTON "Test";
ACTION TEST( oDlg:oBrush )
@ 3, 1 CHECKBOX lVar
ACTIVATE DIALOG oDlg;
ON INIT GRADIENTBRUSH( oDlg, { { 1, RGB( 216, 230, 238 ), RGB( 103, 154, 194 ) } } );
CENTER
oDlg:oBrush:End()
MsgInfo( oDlg:oBrush:nCount )
RETURN NIL
FUNCTION TEST( oBrush )
LOCAL oDlg
MsgInfo( oBrush:nCount )
DEFINE DIALOG oDlg;
TRANSPARENT BRUSH oBrush
ACTIVATE DIALOG oDlg;
CENTER
MsgInfo( oDlg:oBrush:nCount )
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 )
oDlg:oBrush:End()
oDlg:SetBrush( TBrush():New( ,,,, hBmp ) )
AEval( oDlg:aControls, { | o | o:SetBrush( oDlg:oBrush ) } )
SELECTOBJECT( hDC, hBmpOld )
DELETEDC( hDC )
oDlg:ReleaseDC()
RETURN NIL
- Enrico Maria Giordano
- Posts: 8758
- 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()
Antonio Linares wrote:Code: Select all | Expand
oDlg:oBrush:End()
oDlg:SetBrush( TBrush():New( ,,,, hBmp ) )
If I understand correctly, SetBrush() method already ends the previous brush, if assigned:
Code: Select all | Expand
METHOD SetBrush( oBrush ) INLINE If( ::oBrush != nil, ::oBrush:End(),),;
EMG