2009-12-27 84 views
3

可以说我在C#中有一个简单的窗口。它没有边框样式,所以它不能被移动或调整大小等。我如何定位该窗口,使其出现在与桌面或上面相同的级别?桌面上的C#位置窗口

像一个部件或rainmeter皮肤。有任何想法吗?

回答

6

如果我理解正确的话,你要画在桌面上,基本上,那么这可能帮助: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(); 

,但我没有给它一个尝试自己至今。

+1

为什么不能像这样简单.OnDesktop:P感谢,像一个魅力工作 – Ozzy 2009-12-27 15:48:26