Everybody knows, there is(for example) in right-down side message "Windows not actived". It's watermark always topmost in all applications. Maybe who know, what the winapi or another mechanism can create similiar overlay?
-
You don't need to be a programmer to know, that what you're asking for isn't possible. You're going to have to ask yourself, [what if two programs did this?](https://devblogs.microsoft.com/oldnewthing/20050607-00/?p=35413) – IInspectable Jan 15 '21 at 11:31
-
@IInspectable It’s possible, and always was. Windows 2000 introduced true per-pixel alpha-transparent windows. Since Vista the compositor even runs on GPU, i.e. pretty efficient. Just because you can’t answer the question doesn’t mean there’s something wrong with the question. – Soonts Jan 15 '21 at 13:58
1 Answers
There’re two parts of the puzzle.
To place the window on the top, set WS_EX_TOPMOST
bit in the extended style of the window. You probably also want WS_EX_NOACTIVATE
and WS_EX_TRANSPARENT
bits there, otherwise clicking on that window gonna steal input focus from whatever app is underneath that window.
This approach will of course fail if some other application on the same desktop creates another topmost window at the same position. While possible to workaround, I wouldn’t recommend doing anything about that. Windows apps rarely use WS_EX_TOPMOST
windows, you can just ignore that use case. It’s not going to crash Windows or anything like that, just one of the overlays will be on top of another one.
Now, next question — how to render stuff.
The most straightforward (but not the only one) way is layered window. Set WS_EX_LAYERED
extended window style, and use one of the two methods to render, either SetLayeredWindowAttributes
(allows to specify global alpha, and a color to become transparent), or UpdateLayeredWindow
(this one allows to implement true per-pixel transparency). The main downside of this approach — it won’t look good if you want to render your text with ClearType. Grayscale anti-aliasing is fine, as long as you set the correct per-pixel alpha values.
If that’s a small static label for the UX similar to that “not activated” watermark, I would create 32-bit/pixel PNG image in Photoshop with grayscale AA on transparent background, then in runtime decode the PNG, and render with UpdateLayeredWindow
.
Just don’t forget there’re two kinds of alpha blending, straight alpha and pre-multiplied alpha. PNG viewers assume straight alpha, photoshop saves it too, while UpdateLayeredWindow
API expects pre-multiplied alpha. See this question how to pre-muiltiply the alpha.
Also see this article for more info on layered windows.

- 20,079
- 9
- 57
- 130
-
How do you make sure that this window stays on top of any other window with the `WS_EX_TOPMOST` window style? – IInspectable Jan 15 '21 at 14:10
-
-
@IInspectable “It doesn't matter how well your solution performs IFF your window is topmost” not 100% reliable. No watermark will be visible on logon screen, too early. No watermark will be visible on UAC protected desktop, that desktop has a security descriptor denying apps from rendering there. No watermark will be visible in full-screen D3D apps who use exclusive mode as opposed to borderless windowed, that mode bypasses desktop compositor. What I wrote is good enough for many practical use cases. Whether it suits the OP’s particular use case, that’s up to OP to decide, not you. – Soonts Jan 15 '21 at 14:57
-
You've listed lots and lots of edge cases and apparently never considered the most obvious and common scenario where this fails. Now would be a perfect time to re-read the article titled: [What if two programs did this](https://devblogs.microsoft.com/oldnewthing/20050607-00/?p=35413). – IInspectable Jan 15 '21 at 15:26
-
@IInspectable By now I ain’t sure you’re able to understand written text, but I’ll try once again still. Not only I have considered that scenario, I addressed that concern in the 3-rd paragraph of my answer. – Soonts Jan 15 '21 at 15:48
-
Don't you worry, I do understand written text. Like this: *"Windows apps rarely use `WS_EX_TOPMOST` windows, you can just ignore that use case."* Which is unfounded, opinionated, and wrong. If you need to prove this statement wrong, you're going to have to produce evidence. – IInspectable Jan 15 '21 at 15:58
-
@IInspectable “Which is unfounded, opinionated, and wrong” the only topmost thing constantly visible on my particular PC is mouse pointer. if you believe that’s wrong because on your PC you observe lots of translucent overlays on top of other windows, I recommend asking for technical help with your computer. Windows shouldn’t behave that way; you likely have a malware. – Soonts Jan 15 '21 at 16:33
-
It's not be work for D3D applications, but screenwatermark can ignore Z-layers and full-screen for this app's. ScreenWatermark it's system API, and i try find solution for reproduce similiar possibilities. I understand that it's can be hidden solution Microsoft and don't provided for any API for developers. But some app's can draw topmost any messages on D3D app's without override directX dll and endScene() method, although I can't know for sure. – Naydachi Kamikadze Jan 15 '21 at 16:34
-
@NaydachiKamikadze IInspectable probably has a malware on their PC. Windows with `WS_EX_TOPMOST` position consistently stay on top of others, full screen or not. The only exception are other windows with that particular bit. – Soonts Jan 15 '21 at 16:45