Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Position Window On Desktop

Lets say I have a plain window in C#. It has no border styles so it cannot be moved or resized etc. How would i position that window so it appears at the same level as the desktop or one above?

Like a widget or a rainmeter skin. Any ideas?

like image 790
Ozzy Avatar asked Feb 28 '23 21:02

Ozzy


1 Answers

If I understand you correctly and you want to draw on the desktop, basically, then this might help: http://www.neowin.net/forum/lofiversion/index.php/t293883.html

[DllImport("user32.dll", CharSet=CharSet.Auto)]
 public static extern IntPtr FindWindow(
  [MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
  [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
[DllImport("user32.dll")]
 public static extern IntPtr SetParent(
  IntPtr hWndChild,      // handle to window
  IntPtr hWndNewParent   // new parent window
  );


IntPtr hwndf = this.Handle;
IntPtr hwndParent = FindWindow("ProgMan", null);
SetParent(hwndf,hwndParent);
this.TopMost = false;

That would reparent your form as a child window of the desktop itself.

After reading the code some more times I'm not sure why they use FindWindow() looking for "ProgMan" instead of using

[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();

but I didn't give it a try myself so far.

like image 91
Benjamin Podszun Avatar answered Mar 13 '23 07:03

Benjamin Podszun