2010-01-09 87 views
0

長標題,但簡單的問題。C#在桌面上創建一個粘滯窗口,具有transperancy

我試圖讓一個窗口粘到destop(或腳),我可以做到這一點是這樣的:

[DllImport("User32.dll")] 
    static extern IntPtr FindWindow(String lpClassName, String lpWindowName); 
    [DllImport("user32.dll", SetLastError = true)] 
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); 
    [DllImport("user32.dll")] 
    static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 

     IntPtr pWnd = FindWindow("Progman", null); 
     pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null); 
     pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null); 
     IntPtr tWnd = this.Handle; 
     SetParent(tWnd, pWnd); 

這工作得很好,但我不能改變transperancy或opacitiy。

我可以使用CreateWindowEx創建一個很好的透明窗口分層,但是這種方法不再適用於將其固定到桌面上!

任何人都知道如何做到這一點?

謝謝!

+1

爲什麼不這種方法「工作了」? – Thomas 2010-01-09 10:44:04

回答

1

只有頂層窗口可以創建爲分層。用你的方法,你正在爲桌面窗口創建一個子窗口,因此它不能分層。

如果試圖通過將某個窗口「粘住」/「固定」到桌面來解釋您的意思可能會更好。我假設你想把窗口設置在桌面上的特定位置,並始終保持在那裏,但是我必須有更多的東西丟失。否則,爲什麼不把窗口定位在屏幕上的特定座標不適合你?

+0

我希望我的表單能夠「粘」到deskopt,所以如果我最小化所有內容,它仍然可見,它必須是桌面屏幕的一部分,非常類似於小工具邊欄!這對於發佈的代碼來說工作正常,但transperancy不會以這種方式工作,所以我正在尋找一個解決方案,可以同時做到這一點! :) – YesMan85 2010-01-09 13:53:16