Is it possible to create a "transparent" hwnd window ? What I mean by that is that there is no background or borders of that window but that only text is visible...like if I have a main window background and I have something written on the background ( or if I just want to add text on some area via window ) and I want to make it a clickable option, to create that kind of window that will be invisible but still clickable.
-
Related: [Creating a transparent window in C++ Win32](https://stackoverflow.com/q/3970066/3357935) and [Make a window transparent using Win32?](https://stackoverflow.com/q/4549213/3357935) – Stevoisiak Aug 14 '18 at 14:58
3 Answers
On Windows 2000 and later, you can create a top-level window with the WS_EX_LAYERED
style (on Windows 8 and later, child windows can now use the WS_EX_LAYERED
style as well), and then use SetLayeredWindowAttributes()
or UpdateLayeredWindow()
to make the window transparent.
Create a solid background color, and then set that color as the window's transparent color. Anything on the window that is not using that color will not be transparent. The OS will handle the rest for you.
Refer to MSDN for more details:

- 23,794
- 27
- 122
- 225

- 555,201
- 31
- 458
- 770
-
You may want to add that `SetLayeredWindowAttributes` offers two techniques to implement transparency: *Alpha transparency* (`LWA_ALPHA`) and *Color keying* (`LWA_COLORKEY`). The latter - as you explained - is the way to go. How well this cooperates with *ClearType* text rendering is something I do not know. – IInspectable May 11 '14 at 11:30
From your tag of hwnd
, I'm assuming that you are working with C++ or at least have access to the Win32 API, there are plenty of resources to help you get started. The concept is called Window Compositing
.
Transparent win32 window and text
Quick and Dirty Window Transparency
If you use WPF instead of C++, here's a link: Transparent Windows in WPF
-
Yes, the code is C++ and I'm using Windows.h, I've read that question already but I'm fairly new to Win32 API, been doing it for a week or two now so all of that is kinda chinese to me, I was hoping it's doable with a function like ShowWindow or something like that, or is it really that complex ? – Survaf93 May 10 '14 at 20:21
-
Dealing with transparency does make you go into the guts of the Win32 API. But in most cases, it is just standard boilerplate code in `InitInstance` and `WndProc`. The CodeProject article (second link) gives a lot of details on what the code actually means. – metacubed May 10 '14 at 20:26
First set the styles to enable the layers:
SetWindowLong(itsec->first, GWL_EXSTYLE, GetWindowLong(itsec->first, GWL_EXSTYLE) & WS_EX_LAYERED);
Then indicate if you want the transparency to be alpha or not:
SetLayeredWindowAttributes(itsec->first, RGB(154,255,214), 200, LWA_ALPHA);

- 177
- 2
- 5