Howto:Auto hide windows task bar

  • Thread starter Thread starter Gopinath Munisifreddy
  • Start date Start date
G

Gopinath Munisifreddy

hi,
can any one provide a sample code to auto hide windows task bar using a
..NET
program

Thanx in advance
 
Hi,

In order to set the Windows taskbar to the auto hide mode you have to resort
to use some Windows API functions. Specifically you need to use the
SHAppBarMessage function.

The following example shows how to use it:

using System;
using System.Runtime.InteropServices;

namespace TaskBarTest
{
class Class1
{
// FindWindow import
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);

// SHAppBarMessage import
[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage,
ref APPBARDATA pData);

// taskbar messages
public enum AppBarMessages
{
New = 0x00000000,
Remove = 0x00000001,
QueryPos = 0x00000002,
SetPos = 0x00000003,
GetState = 0x00000004,
GetTaskBarPos = 0x00000005,
Activate = 0x00000006,
GetAutoHideBar = 0x00000007,
SetAutoHideBar = 0x00000008,
WindowPosChanged = 0x00000009,
SetState = 0x0000000a
}

// possible taskbar states for AppBarMessages.SetState
public enum AppBarStates
{
AutoHide = 0x00000001,
AlwaysOnTop = 0x00000002
}

// RECT structure
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public UInt32 left;
public UInt32 top;
public UInt32 right;
public UInt32 bottom;
}

// APPBARDATA structure
[StructLayout(LayoutKind.Sequential)]
public struct APPBARDATA
{
public UInt32 cbSize;
public IntPtr hWnd;
public UInt32 uCallbackMessage;
public UInt32 uEdge;
public RECT rc;
public Int32 lParam;
}

// SetTaskbar helper function
static public void SetTaskbar(AppBarStates mode)
{
APPBARDATA msgData = new APPBARDATA();

// initialize structure
msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
msgData.hWnd = FindWindow("System_TrayWnd", null);
msgData.lParam = (Int32)(mode);

// send message
SHAppBarMessage((UInt32)AppBarMessages.SetState, ref msgData);
}

[STAThread]
static void Main(string[] args)
{
// auto-hide the taskbar
SetTaskbar(AppBarStates.AutoHide);
}
}
}

For more information please see the following document:

The Taskbar
http://msdn.microsoft.com/library/d...e/shell_int/shell_int_programming/taskbar.asp

Regards,

Gabriele
 
Back
Top