How to draw text on the desktop in Windows?

c++, drawing, winapi

Solution

I'm assuming your ultimate goal is displaying some sort of status information on the desktop.

You will have to do either:

Inject a DLL into Explorer's process and subclass the desktop window (the `SysListView32` at the bottom of the `Progman` window's hierarchy) to paint your text directly onto it.

Create a nonactivatable window whose background is painted using `PaintDesktop` and paint your text on it.

First solution is the most intrusive, and quite hard to code, so I would not recommend it.

Second solution allows the most flexibility. No "undocumented" or reliance on a specific implementation of Explorer, or even of just having Explorer as a shell.

In order to prevent a window from being brought to the top when clicked, you can use the extended window style `WS_EX_NOACTIVATE` on Windows 2000 and up. On downlevel systems, you can handle the `WM_MOUSEACTIVATE` message and return `MA_NOACTIVATE`.

You can get away with the `PaintDesktop` call if you need true transparency by using layered windows, but the concept stays the same. I wrote another answer detailing how to properly do layered windows with alpha using GDI+.

Problem

How Would I go about placing text on the windows desktop? I've been told that GetDesktopWindow() is what I need but I need an example.

Original source

Related problems