disabling and/or hiding Windows taskbar

Could somebody post code that disables and/or hides Windows taskbar and enables it when I or user click on the button in Form.

Goran



Answer this question

disabling and/or hiding Windows taskbar

  • Alaska

    first use

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices; // add this

    namespace server_1._
    {
    public partial class Form1 : Form
    {
    [DllImport("user32.dll")]


    Good luck!!


  • Anubhava

    It doesn't work!
  • Telemachus

    I don't know where to include [DllImport("user32.dll")]. In which part of the source code
  • briandra3

    I am not sure that above is real solution.

    If you want true Full Screen app, you need to request it from WinAPI.

    Detailed explanation is here:

    How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#

    (based on:
    KB Article Q179363: How To Cover the Task Bar with a Window )

    Most important piece of code is:
    public class WinApi
    {
    [DllImport(”user32.dll”, EntryPoint = “GetSystemMetrics”)]
    public static extern int GetSystemMetrics(int which);

    [DllImport(”user32.dll”)]
    public static extern void
    SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
    int X, int Y, int width, int height, uint flags);

    private const int SM_CXSCREEN = 0;
    private const int SM_CYSCREEN = 1;
    private static IntPtr HWND_TOP = IntPtr.Zero;
    private const int SWP_SHOWWINDOW = 64; // 0×0040

    public static int ScreenX
    {
    get { return GetSystemMetrics(SM_CXSCREEN);}
    }

    public static int ScreenY
    {
    get { return GetSystemMetrics(SM_CYSCREEN);}
    }

    public static void SetWinFullScreen(IntPtr hwnd)
    {
    SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
    }
    }

    --

    Regards,

    Dejan Vesi

    MCP & MCAD for .Net technologies

    Home: http://www.vesic.org/english/

    Blog: http://www.vesic.org/english/blog/



  • Airex

    Why do you import user32.dll two times...I dont get this

  • J. Ho

    Thanks for the detailed breakdown. This was exactly what I was looking for.
  • dinsdale

    Thanks alot, that put me in the right direction I think. Though there's still one problem for me - the place where the taskbar was just leaves a "black hole" where the program doesn't react to any mouse clicks. Isn't there any way which I can maximize the program to the fullscreen, over that "black hole" or just register mouse clicks in that area Thanks in advance, Peter
  • Praj

    Helper class:

    using System;
    using System.Runtime.InteropServices;

    public 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;

    private int _taskbarHandle;

    public Taskbar()
    {
    _taskbarHandle = FindWindow("Shell_TrayWnd","");
    }

    public void Show()
    {
    ShowWindow(_taskbarHandle, SW_SHOW);
    }

    public void Hide()
    {
    ShowWindow(_taskbarHandle, SW_HIDE);
    }
    }



    Using:

    Taskbar taskbar = new Taskbar();
    taskbar.Hide();




  • Christopher.Gao

    The P/Invoke needs:


    [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;



    Usage:


    int hwnd = FindWindow("Shell_TrayWnd","");
    ShowWindow(hwnd,SW_HIDE);




  • Rahul_hk1

    Do you get any exception

    I have tested this class on Windows XP, here is the code:


    public 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;

    protected static int Handle
    {
    get
    {
    return FindWindow( "Shell_TrayWnd", "" );
    }
    }

    private Taskbar()
    {
    // hide ctor
    }

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

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



    Using:

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    Taskbar.Hide();

    Application.ApplicationExit += new EventHandler( Application_ApplicationExit );
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new FrmMain());

    }

    static void Application_ApplicationExit( object sender, EventArgs e )
    {
    Taskbar.Show();
    }




  • elias_adum

    You must specify the dll for every external method.


  • disabling and/or hiding Windows taskbar