Share via


disabling and/or hiding Windows taskbar

Question

Sunday, March 12, 2006 10:20 AM | 1 vote

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

 

All replies (14)

Sunday, March 12, 2006 11:05 AM ✅Answered | 1 vote

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

Sunday, March 12, 2006 1:28 PM ✅Answered | 1 vote

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();
}
 

Sunday, March 12, 2006 11:47 AM

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


Sunday, March 12, 2006 12:22 PM

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!!


Sunday, March 12, 2006 12:30 PM

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();
 

Sunday, March 12, 2006 12:57 PM

It doesn't work!


Sunday, March 12, 2006 1:36 PM

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


Sunday, March 12, 2006 2:08 PM

You must specify the dll for every external method.


Monday, November 13, 2006 7:26 AM

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


Monday, November 20, 2006 4:43 PM

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


Sunday, December 3, 2006 5:03 PM

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/


Wednesday, February 10, 2010 6:59 AM

I want to Show 'Hide' Task Bar Using C# (Windows Form). Code is Perfectly working,But when I minimize the Form the Task Bar again Hide. I want to Show my Task Bar, Once Form get Run, Task Bar Should never Hide.Please Reply As soon as possible


Tuesday, May 18, 2010 9:57 AM

Use this to show the taskbar when you need it to be showed:

ShowWindow( Handle, SW_SHOW );

And this when you need to hide it again:

ShowWindow( Handle, SW_HIDE );

Trust No one


Wednesday, November 2, 2011 2:45 PM

What a terrible idea to mess with system state like this. Don't hide the task bar.

 

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

 

What an incredibly misguided idea.