1

So I want to have something similar to an desktop overlay. So the thing is I tried to draw to the desktop wallpaper directly but this will get redrawn and from what I read there is really no good way around this. So I tried to go with a broderless completely transparent WinForm with text on it.

The Problem I have with is that hitting Windows+D will hide the application and I didn't found a way to prevent this or bring it up again. Also I read that setting the form as a Child of the Desktop can cause problems aswell.

What I did so far was setting the position of the Form directly above the Desktop:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;

//By calling SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); it will move to the very back of all windows.

What I want in the end is a Win Form that is always ontop of the Desktop but under every other window.

3
  • 2
    There is no documented way to do this, Microsoft does not like making this easy. But it is hackable by pinvoking FindWindowEx() to find a window named "Progman", FindWindowEx() again to find its child window named "SHELLDLL_DefView", SetParent() to glue your window to it. It does void the warranty multiple ways, not something that I would want to support. Google "windows forms replace desktop window" to find people that are more courageous than me. Oct 4, 2018 at 21:41
  • I will look into that a bit later thanks a lot!
    – Twenty
    Oct 4, 2018 at 21:51
  • @HansPassant Thanks a lot it works like a charm!
    – Twenty
    Oct 4, 2018 at 22:00

1 Answer 1

-2

You should run a thread which in fraction of time ( such as 100ms) call BringWindowToTop api and bring your window aplication to top, it will solve to Win+D issue.

[DllImport("user32.dll", SetLastError=true)]
static extern bool BringWindowToTop(IntPtr hWnd);

[DllImport("user32.dll", SetLastError=true)]
static extern bool BringWindowToTop(HandleRef hWnd);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.