Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window "on desktop"

Tags:

c#

wpf

I've been using Rainlendar for some time and I noticed that it has an option to put the window "on desktop". It's like a bottomMost window (as against topmost).

How could I do this on a WPF app?

Thanks

like image 950
Artur Carvalho Avatar asked Dec 13 '08 10:12

Artur Carvalho


2 Answers

My answer is in terms of the Win32 API, not specific to WPF (and probably requiring P/Invoke from C#):

Rainlendar has two options:

  • "On Desktop", it becomes a child of the Explorer desktop window ("Program Manager"). You could achieve this with the SetParent API.
  • "On Bottom" is what you describe - its windows stay at the bottom of the Z-order, just in front of the desktop. It's easy enough to put them there to begin with (see SetWindowPos) - the trick is to stop them coming to the front when clicked. I would suggest handling the WM_WINDOWPOSCHANGING message.
like image 50
Hugh Allen Avatar answered Sep 22 '22 08:09

Hugh Allen


This is what I used so the window is always "on bottom":

   using System;
    using System.Runtime.InteropServices;
    using System.Windows;
    using System.Windows.Interop;

...

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

const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;

static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

public static void SetBottom(Window window)
{
    IntPtr hWnd = new WindowInteropHelper(window).Handle;
    SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
like image 44
Artur Carvalho Avatar answered Sep 24 '22 08:09

Artur Carvalho