2009-12-27 88 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