How do I create a window( on which I will draw some text) that will be 50% transparent? I want the user to see both the text in the window and whatever is behind that. Both of them need to be legible, so I figure that 50% should work.
Posted on 2001-09-08 15:22:00 by Hel
Not very sure but i _think_ you have to include this extended style when calling CreateWindowEx:

WS_EX_TRANSPARENT

Also the hbrBackground member of the WNDCLASSEX structure that you pass to RegisterClassEx should be NULL.

Hope that helps ..

Latigo
Posted on 2001-09-08 16:36:06 by latigo
It isn't that usefull, but it can be done only in windows 2000 (maybe also XP) and you have to deals with WS_EX_LAYERED style and UpdateLayeredWindow. Sorry, but I haven't other info, maybe look at MSDN and at this document from Microsoft:
http://www.rusdev.newmail.ru/winapi/articles/layerwin/layerwin.html
Posted on 2001-09-08 16:54:07 by LuHa
Maybe this is what you are after.

Not by me.
Posted on 2001-09-08 17:32:52 by edgarbrits
Thanks!
Posted on 2001-09-08 20:15:59 by Hel
This is just a quick and dirty hack but it looks like it does what you want. Heres how I got the effect:

- Set hbrBackground to NULL so you can repaint the BG yourself
- process WM_ERASEBKGND and return 1 to get the client area transparency
- in WM_PAINT: use SetBkMode() with TRANSPARENT, and draw your text
- update your client area when you receive WM_SIZE

This is a pretty simplistic approach though, you'd want to do a lot more processing of window movement events and updating the window appropriately.

I can post the entire source if you need it, its in C though ;)
Posted on 2001-09-08 20:50:25 by Boggy
This is another possible solution.... takes a bit of graphic work to set up on the WM_CREATE tho... (I used Hiro's Skinned window example..)

NaN
Posted on 2001-09-08 22:46:41 by NaN
As well it does more interesting results if you replace:

"invoke ShowWindow, hwnd,SW_SHOWNORMAL"

with:

"invoke SetWindowPos, hwnd, HWND_TOPMOST, NULL, NULL, NULL, NULL,SWP_SHOWWINDOW or SWP_NOSIZE or SWP_NOMOVE"

NaN
Posted on 2001-09-08 23:01:27 by NaN
This will make a client are that captures whatever is behind it.
Only usefull if your not going to move or size the window.


invoke CreateCompatibleDC,NULL
mov cdc,eax

invoke CreateCompatibleBitmap,hdc,rect.right,rect.bottom

mov hbmp,eax


invoke SelectObject,cdc,hbmp
invoke BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT
Posted on 2001-09-09 11:41:02 by titan
here the window
Posted on 2001-09-09 11:53:25 by titan
oops i made a mistake in my original post


you have to BitBlt twice

invoke BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT

invoke
BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT
Posted on 2001-09-09 13:00:43 by titan
Boggy could you post some code?
Thanks :)


Latigo
Posted on 2001-09-09 16:49:28 by latigo

Boggy could you post some code?
Thanks :)


Latigo


NOTES:
- Needs to react to WM_MOVE
- Needs a better way to clear the entire window and repaint it again, I used ShowWindow() for brevity sake.

Just paste this into your window.

When you set up your WNDCLASS:
wndclass.hbrBackground = NULL;

In your window procedure:
case WM_ERASEBKGND:
return 1;

case WM_SIZE:
ShowWindow (hwnd, SW_HIDE);
ShowWindow (hwnd, SW_RESTORE);
return 0;

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
SetTextColor (hdc, 255);
SetBkMode (hdc, TRANSPARENT);
TextOut (hdc, 10, 10, "Hello", 5);
EndPaint (hwnd, &ps);
return 0;
Posted on 2001-09-09 22:09:33 by Boggy

This will make a client are that captures whatever is behind it.
Only usefull if your not going to move or size the window.


invoke CreateCompatibleDC,NULL
mov cdc,eax

invoke CreateCompatibleBitmap,hdc,rect.right,rect.bottom

mov hbmp,eax


invoke SelectObject,cdc,hbmp
invoke BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT

this works for the first time called i guess.. but for the 2nd doesn't copy the updated "behing".. dunno why. Any ideas?
Posted on 2002-06-10 15:49:12 by coder
code 7345

I'm not sure what your asking?

Could you be more specific?
Posted on 2002-06-11 22:01:34 by titan
ah ok sorry..

for example, when the window is created and receives WM_PAINT for the first time, i can get what is behing the window with that code, but on the secound paint (coz 1 window was moved and pass over mine..for example) bitblt copies blank (white) to mine window. Maybe even in the first time i can't get the real "behind" (using that method), coz at the first time if i don't paint nothing on my window it remains the same as what is behind it i guess.

hoppe u understand now..

i'm gonna to explain what i realy wanna do. Using some alpha blend function, i've 2 choises; change alpha of window, BitBlt() but with alpha suport. Since i don't wanna change my hole window alpha but just some parts of it, i've to use AlphaBlend() and its the same as BitBlt but suports alphablend. Thus i've to have 2 DCs; 1 with the bitmap selected, and the other with what is behing mine window on where i'm gonna paint.

Jean
Posted on 2002-06-12 08:06:36 by coder
Here is a example:
http://www.asmcommunity.net/board/index.php?topic=510&highlight=transparent

But works only under 2K/XP as LuHa mentioned.

BTW, happy birthday afterwards, LuHa!
Posted on 2002-06-12 09:34:52 by bazik
Thank you bAZiK (please note the perfect capitalization of your nick), first quarter of century passed :grin:.
Posted on 2002-06-12 12:48:47 by LuHa