Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Layered windows and DrawText

141 views
Skip to first unread message

Mike D Sutton

unread,
Jul 20, 2005, 9:07:26 AM7/20/05
to
> Hey everyone, this problem is really causing me a lot of grief.
>
> I'm new to layered windows on the whole and I'm not all that good with
> GDI,
> but nonetheless I got my first layered window up and running. I composed a
> 32
> bit bitmap from two bitmaps on my harddrive (a colour one and an alpha
> one),
> and now it sits in the bottom right corner of my screen. The problem is,
> when
> I try to draw text on the DC I'm passing to UpdateLayeredWindow (with my
> bitmap selected onto it), I get the text, but it's got 0 alpha. I've tried
> setting the text colour with SetTextColor(hBitmap, RGB(127, 0, 0)),
> DrawText()..., as well as trying a 32 bit colour value generated from
> D3DCOLOR_ARGB(). I've also tried using the exact same 32 bit values as
> used
> in pixels in the bitmap with 255 alpha. And I've tried typecasting an
> RGBQUAD
> * to COLORREF * and dereferencing it to use RGBQUAD like a 32 bit value,
> but
> to no avail. I get colour if I move a window underneath it, but that's not
> what I want. I want the colour with 255 alpha. Any ideas?

Most GDI functions have no idea what alpha is and as such simply use a
24-bit colour, ignoring the high byte. What I do is to render the text as
an alpha mask to an 8-bit greyscale buffer then use that as the alpha
channel in a 32-bit DIB and inject colour into the RGB channels, then
AlphaBlend() that to the window.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ED...@mvps.org
WWW: Http://EDais.mvps.org/


Todd Aspeotis

unread,
Jul 20, 2005, 6:01:03 PM7/20/05
to
Thanks for that, I don't suppose GDI+ understands what alpha is, either? And
is there any way of exposing the microsoft text engine so I can possibly
force it to acknowledge the a << 24?

"Mike D Sutton" wrote:

> blah

Mike D Sutton

unread,
Jul 21, 2005, 4:01:19 AM7/21/05
to
> Thanks for that, I don't suppose GDI+ understands what alpha is, either?
> And
> is there any way of exposing the microsoft text engine so I can possibly
> force it to acknowledge the a << 24?

GDI+ does support alpha natively, however I don't know offhand whether it's
text drawing functions will draw with 32-bit colours. It's definitely worth
a try though.

Todd Aspeotis

unread,
Jul 21, 2005, 5:18:05 AM7/21/05
to
I posted a question about this, but it doesn't seem to be getting any loving
:'(. How do you create a bitmap from a DC. I've seen scenarios where people
have just typecast the DC to a HBITMAP. Is this the way to do it? I'm also
tossing up the idea of just using Direct3D and drawing everything to a
texture and using IDirect3DSurface9::GetDC to get the damn DC. I don't
suppose it's possible to create a device without a valid HWND, is it?

Mike D Sutton

unread,
Jul 21, 2005, 7:05:24 AM7/21/05
to
>I posted a question about this, but it doesn't seem to be getting any
>loving
> :'(. How do you create a bitmap from a DC.

It depends on what kind of Bitmap you want to create (and which type you
create depends on what you want to do with it.) In your case I would assume
that you don't want to work at screen resolution in which case a DIB would
be the way to go. To create a DIB you use the CreateDIBSection() API call,
simply fill out a BITMAPINFOHEADER structure and pass it to the call.

> I've seen scenarios where people have just typecast the DC to a HBITMAP.
> Is this the way to do it?

God no, this would lead to all kinds of problems since they're not really
compatible types (at least as far as GDI is concerned.)

> I'm also tossing up the idea of just using Direct3D and drawing everything
> to a
> texture and using IDirect3DSurface9::GetDC to get the damn DC. I don't
> suppose it's possible to create a device without a valid HWND, is it?

You have to specify a window when filling out your PresentParams structure
to DirectX, however if you don't actually have a window handle then you can
I imagine just specify the desktop window handle - Not sure if this is
considered bad practice though even if you were creating a full-screen
application.
A better approach would most likely be to simply create a window and use
that instead, but you may want to follow that up on a DX group just to be
sure.

Todd Aspeotis

unread,
Jul 21, 2005, 5:54:03 PM7/21/05
to
Thanks for that, I'm not all that used to GDI and I thought that by selecting
a HBITMAP into a DC, and then drawing on the DC with GDI functions, it didn't
affect the HBITMAP (ie non destructive). Now I know.
0 new messages