Reputation: 2319
I have a large C++ codebase with native Windows GUI that runs fullscreen. A part of it shall be exchanged by a WPF window shown on top of it. The window is set up like this:
<Window WindowState="Normal"
WindowStyle="None"
ShowInTaskbar="False"
AllowsTransparency="True"
/>
This blends the window seamless into the rest of the application. The invocation of the window is done from C++/CLI like this:
Windows::Window^ w = window();
Windows::Interop::WindowInteropHelper iHelp(w);
iHelp.Owner = System::IntPtr(_parentHwnd);
w->Show();
The _parentHwnd is the HWND of the native application. As said the application is always shown fullscreen. When I now click on the WPF window the Windows taskbar will appear. How do I prevent the taskbar from appearing?
Upvotes: 3
Views: 3335
Reputation: 2319
With Flot2011 answer this I was able to pretend that my window belongs to another fullscreen window. For those curious about the missing parts - here are they: We implement handler for the activated and deactivated events
<Window
Activated="DisplayWindow_Activated"
Deactivated="DisplayWindow_Deactivated"
/>
The event handler look like this
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();
}
So what happens now? The taskbar will vanish in the main application because it is fullscreen. When I click on the overlaid window the taskbar would be activated but is deactivated by the propert event. So the mashup behaves like one fullscreen application.
The screen
part is to handle multi-monitor setups. We should only hide the taskbar if the (mashup) application is shown fullscreen on the primary monitor. The current solution assumes that WPF-window and underlying fullscreen application are on the same screen.
If you use the screen
stuff, don't forget to include references to System.Drawing
and System.Window.Forms
. Usings are not such a great idea here because the namespaces collide with stuff from .net.
Upvotes: 1
Reputation: 4671
I have used this class (an idea was found somewhere on the Net) to hide/show the taskbar:
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);
}
}
Works on Windows XP/Vista/7.
Upvotes: 2