Board index » cppbuilder » Brush.Style := bsClear doesn't work, but SetBkMode does

Brush.Style := bsClear doesn't work, but SetBkMode does

Why does this fail:

    GradientFill(Canvas.Handle, @vert, 2, @gRect, 1, GRADIENT_FILL_RECT_H);
    Canvas.Brush.Style := bsClear;
    Canvas.TextOut(ARect.Left, ARect.Top, 'Text goes here');

and this works:

    GradientFill(Canvas.Handle, @vert, 2, @gRect, 1, GRADIENT_FILL_RECT_H);
    SetBkMode(Canvas.Handle, TRANSPARENT);
    SetTextColor(Canvas.Handle, Canvas.Font.Color and $00FFFFFF);
    TextOut(Sender.Canvas.Handle, ARect.Left, ARect.Top, PChar('Text goes
here'), Length('Text goes here'));

Trying to draw some text transparently, it won't work using VCL controls if
the Canvas.Handle was just used in a call to Windows API GradientFill. What
could it be that Delphi does with canvas handles that i cannot stand someone
calling an API call with it?

Delphi 5, Windows XP

p.s. Don't even try to figure it out - you'll hurt your brain.

 

Re:Brush.Style := bsClear doesn't work, but SetBkMode does


Quote
"Ian Boyd" <ian.borlandnews...@avatopia.com> wrote in message

news:3eba95f8$1@newsgroups.borland.com...

Quote
> Why does this fail:

Because TextOut() calls ExtTextOut() which doesn't use the Brush but the
Font instead, and is influenced by the current characteristics of the
underlying HDC.

Quote
> and this works:

Because you are altering the underlying HDC and then using a drawing
function that utilizes them correctly.

Quote
> Trying to draw some text transparently, it won't work
> using VCL controls if the Canvas.Handle was just used
> in a call to Windows API GradientFill.

Calling SetBkMode() is the correct way to go.  Just make sure you call
SetBkMode() a second time to reset the previous settings when you're done:

    GradientFill(Canvas->Handle, &vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
    int prevmode = SetBkMode(Canvas->Handle, TRANSPARENT);
    SetTextColor(Canvas->Handle, ColorToRGB(Canvas->Font->Color);
    Canvas->TextOut(ARect.Left, ARect.Top, "Text goes here");
    SetBkMode(Canvas->Handle, prevmode);

Gambit

Re:Brush.Style := bsClear doesn't work, but SetBkMode does


What is the VCL-way to accomplish the same task?

"Remy Lebeau (TeamB)" <gambi...@yahoo.com> wrote in message
news:3ebaa99a$1@newsgroups.borland.com...

Quote

> "Ian Boyd" <ian.borlandnews...@avatopia.com> wrote in message
> news:3eba95f8$1@newsgroups.borland.com...

> > Why does this fail:

> Because TextOut() calls ExtTextOut() which doesn't use the Brush but the
> Font instead, and is influenced by the current characteristics of the
> underlying HDC.

> > and this works:

> Because you are altering the underlying HDC and then using a drawing
> function that utilizes them correctly.

> > Trying to draw some text transparently, it won't work
> > using VCL controls if the Canvas.Handle was just used
> > in a call to Windows API GradientFill.

> Calling SetBkMode() is the correct way to go.  Just make sure you call
> SetBkMode() a second time to reset the previous settings when you're done:

>     GradientFill(Canvas->Handle, &vert, 2, &gRect, 1,

GRADIENT_FILL_RECT_H);

- Show quoted text -

Quote
>     int prevmode = SetBkMode(Canvas->Handle, TRANSPARENT);
>     SetTextColor(Canvas->Handle, ColorToRGB(Canvas->Font->Color);
>     Canvas->TextOut(ARect.Left, ARect.Top, "Text goes here");
>     SetBkMode(Canvas->Handle, prevmode);

> Gambit

Re:Brush.Style := bsClear doesn't work, but SetBkMode does


Quote
"Ian Boyd" <ian.borlandnews...@avatopia.com> wrote in message

news:3ebbe62b$1@newsgroups.borland.com...

Quote
> What is the VCL-way to accomplish the same task?

There isn't any.  You have to call SetBkMode() directly yourself.  The only
time the VCL calls SetBkMode() is when the Brush is created for the first
time, but then never again after that.

Gambit

Other Threads