none
How to keep taskbar visible when WPF-App is even in fullscreen mode?

    Question

  • I create a WPF-Window in fullscreen mode.

    I want to  keep the taskbar visible.

    How?



    • Edited by gaoshengq Tuesday, July 24, 2012 2:28 AM
    Tuesday, July 24, 2012 2:03 AM

Answers

All replies

  • My first attempt would be to P/Invoke SetWindowPos() to set the taskbar window on top of the WPF window.

    Jose R. MCP
    Code Samples

    Tuesday, July 24, 2012 4:40 AM
  • My first attempt would be to P/Invoke SetWindowPos() to set the taskbar window on top of the WPF window.

    Jose R. MCP
    Code Samples

    Are there any  examples?

    I tried it,but i failured.

     
    Tuesday, July 24, 2012 5:24 AM
  • Show the code of your attempt.

    Jose R. MCP
    Code Samples

    Tuesday, July 24, 2012 1:49 PM
  • Well I got some time to spare so I tried this.  This is my WPF + P/Invoke attempt:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Runtime.InteropServices;
    
    namespace TaskbarOnTop
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            [Flags]
            private enum SWPFlags : uint
            {
                NoSize = 0x1,
                NoMove = 0x2,
                NoZOrder = 0x4,
                NoRedraw = 0x8,
                NoActivate = 0x10,
                DrawFrame = 0x20,
                ShowWindow = 0x40,
                HideWindow = 0x80,
                NoCopyBits = 0x100,
                NoOwnerZOrder = 0x200,
                NoSendChanging = 0x400,
                DeferErase = 0x2000,
                AsyncWindowPos = 0x4000,
            }
            private class SpecialHWND
            {
                public static IntPtr Bottom = new IntPtr(1);
                public static IntPtr NoTopMost = new IntPtr(-2);
                public static IntPtr Top = new IntPtr(0);
                public static IntPtr TopMost = new IntPtr(-1);
            }
            public MainWindow()
            {
                InitializeComponent();
            }
            [DllImport("user32", SetLastError = true)]
            private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int x, int y, int width, int height, SWPFlags flags);
            [DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
            private static extern IntPtr FindWindow(string className, string windowName);
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                IntPtr bar = FindWindow("Shell_TrayWnd", null);
                if (bar == IntPtr.Zero)
                {
                    MessageBox.Show("Taskbar not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                SetWindowPos(bar, SpecialHWND.Top, 0, 0, 0, 0, SWPFlags.NoSize | SWPFlags.NoMove);
            }
    
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                Close();
            }
        }
    }
    
    <Window x:Class="TaskbarOnTop.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525" WindowState="Maximized" WindowStyle="None">
        <Grid>
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="16,15,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,15,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
        </Grid>
    </Window>
    


    The above works to an extent:  It successfully shows the taskbar, but it doesn't remain visible (on top).  And yes, I also tried with SpecialHWND.TopMost.  The taskbar is obviously very special:  It will not stay on top unless it is the active window.  This is why the call to SetWindowPos() must not use the NoActivate flag.

    So this leads me to believe that there really is no way to keep the taskbar on top of a fullscreen application.  You CAN show it, but as soon as a fullscreen window is reactivated the taskbar hides again.  So if you really really need the taskbar showing the answer is simple:  Don't create a fullscreen window.  It is kind of nonsense anyway:  Create fullscreen window but not really fullscreen.  Just create a window that covers the entire working area only, not the full screen.


    Jose R. MCP
    Code Samples

    Tuesday, July 24, 2012 3:39 PM
  • Thank you for your effort and help, webJose!

    Hi gaoshengq,

    You can create a custom window and set the windowstate as Maximized, and get rid of the buttons on the top left of window. And set the Resize mode as noresize, thus you can achieve your goal.

    About how to create a custom window, you can refer to below link for your reference:http://www.codeproject.com/Articles/131515/WPF-Custom-Chrome-Library

    Hope it helps.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 25, 2012 10:25 AM
  • hi,

    i was having the same problem but following link helped me :)

    http://codekong.wordpress.com/2010/11/10/custom-window-style-and-accounting-for-the-taskbar/


    Thanks & Regards dhampall

    Wednesday, July 25, 2012 3:04 PM