2012-06-04 63 views
2

我有一個大型的C++代碼庫,它具有運行全屏的本地Windows GUI。 它的一部分應該通過頂部顯示的WPF窗口進行交換。 設置窗口像這樣:如何防止任務欄出現WPF非全屏窗口?

<Window WindowState="Normal" 
     WindowStyle="None" 
     ShowInTaskbar="False" 
     AllowsTransparency="True" 
/> 

此共混物的窗口無縫到應用程序的其餘部分。 窗口的調用是由C++/CLI完成這樣的:

Windows::Window^ w = window(); 
Windows::Interop::WindowInteropHelper iHelp(w); 
iHelp.Owner = System::IntPtr(_parentHwnd); 
w->Show(); 

的_parentHwnd是本機應用程序的HWND。如上所述,應用程序總是以全屏顯示。 當我現在點擊WPF窗口時,Windows任務欄將會出現。 我如何阻止任務欄出現

回答

2

我已經使用這個類(一個想法被發現的地方在網絡上)隱藏/顯示任務欄:

public static class Taskbar 
{ 
    [DllImport("user32.dll")] 
    private static extern int FindWindow(string className, string windowText); 
    [DllImport("user32.dll")] 
    private static extern int ShowWindow(int hwnd, int command); 

    private const int SW_HIDE = 0; 
    private const int SW_SHOW = 1; 

    public static int Handle 
    { 
     get 
     { 
      return FindWindow("Shell_TrayWnd", ""); 
     } 
    } 
    public static int StartHandle 
    { 
     get 
     { 
      return FindWindow("Button", "Start"); 
     } 
    } 

    public static void Show() 
    { 
     ShowWindow(Handle, SW_SHOW); 
     ShowWindow(StartHandle, SW_SHOW); 
    } 

    public static void Hide() 
    { 
     ShowWindow(Handle, SW_HIDE); 
     ShowWindow(StartHandle, SW_HIDE); 
    } 
} 

適用於Windows XP/Vista/7的。

+0

非常感謝您的答覆。我測試一下 - 可能需要一天的時間才能回來。 – Pascal

+0

有趣。我認爲這是一個嚴重的黑客攻擊,但滿足了我們的需求。謝謝。 – Pascal

1

隨着Flot2011答案this我能夠假裝我的窗口屬於另一個全屏窗口。對於那些好奇缺少的部分 - 這裏是他們: 我們的啓動和關閉事件

實現處理器
<Window 
Activated="DisplayWindow_Activated" 
Deactivated="DisplayWindow_Deactivated" 
/> 

事件處理程序看起來像這樣

private void DisplayWindow_Activated(object sender, EventArgs e) 
{ 
    var screen = System.Windows.Forms.Screen.FromRectangle(
    new System.Drawing.Rectangle(
     (int)this.Left, (int)this.Top, 
     (int)this.Width, (int)this.Height)); 
    if(screen.Primary) 
    Taskbar.Hide(); 
} 

private void DisplayWindow_Deactivated(object sender, EventArgs e) 
{ 
    var screen = System.Windows.Forms.Screen.FromRectangle(
    new System.Drawing.Rectangle(
     (int)this.Left, (int)this.Top, 
     (int)this.Width, (int)this.Height)); 
    if(screen.Primary) 
    Taskbar.Show(); 
} 

所以,現在發生了什麼?任務欄將在主應用程序中消失,因爲它是全屏顯示。當我點擊疊加的窗口時,任務欄將被激活,但是由屬性事件關閉。所以混搭的行爲就像一個全屏應用程序。

screen部分是處理多顯示器設置。如果(mashup)應用程序在主監視器上全屏顯示,我們只應隱藏任務欄。目前的解決方案假定WPF窗口和底層全屏應用程序在同一個屏幕上。

如果您使用screen的東西,不要忘記引用System.DrawingSystem.Window.Forms。這裏使用的並不是一個好主意,因爲命名空間與.net中的內容相沖突。

相關問題