C#在桌面上定位窗口

时间:2009-12-27 15:38:47

标签: c# desktop z-index

假设我在C#中有一个普通的窗口。它没有边框样式,因此无法移动或调整大小等。我如何定位该窗口,使其显示在与桌面或上面相同的级别?

像小工具或雨量计皮肤。有什么想法吗?

1 个答案:

答案 0 :(得分:7)

如果我理解正确并且您想在桌面上绘图,基本上,这可能会有所帮助: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;

这会将您的表单重新显示为桌面本身的子窗口。

在多次阅读代码后,我不确定为什么他们使用FindWindow()寻找“ProgMan”而不是使用

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

但到目前为止我自己都没试过。