Как настроить автоматическое скрытие панели приложений в языке C# winform
Hi everyone, please, I know that there is a way how to set my applicatication desktop toolbar to autohide, but unfortunatelly I dont know how to use it properly. Can you someone give me an example please? I'm programming appBar in C# WinForm. Thank you very much
What I have tried:
There is a code, which I'm using for registering the AppBar.
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}
private enum ABMsg : int
{
ABM_NEW = 0,
ABM_REMOVE,
ABM_QUERYPOS,
ABM_SETPOS,
ABM_GETSTATE,
ABM_GETTASKBARPOS,
ABM_ACTIVATE,
ABM_GETAUTOHIDEBAR,
ABM_SETAUTOHIDEBAR,
ABM_WINDOWPOSCHANGED,
ABM_SETSTATE
}
private enum ABNotify : int
{
ABN_STATECHANGE = 0,
ABN_POSCHANGED,
ABN_FULLSCREENAPP,
ABN_WINDOWARRANGE
}
private enum ABEdge : int
{
ABE_LEFT = 0,
ABE_TOP,
ABE_RIGHT,
ABE_BOTTOM
}
private bool isBarRegistered = false;
private int uCallBack;
[DllImport("SHELL32", CallingConvention = CallingConvention.StdCall)]
private static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);
[DllImport("USER32")]
private static extern int GetSystemMetrics(int Index);
[DllImport("User32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern int RegisterWindowMessage(string msg);
private void RegisterBar(bool dvojty)
{
APPBARDATA abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(abd);
abd.hWnd = this.Handle;
if (!isBarRegistered)
{
if (Properties.Settings.Default.Strana.ToLower() == "ano")
{
this.Width = minSirka;
this.Height = Screen.FromPoint(this.Location).WorkingArea.Height;
}
else
{
this.Width = Screen.FromPoint(this.Location).WorkingArea.Width;
this.Height = minVyska;
}
uCallBack = RegisterWindowMessage("AppBarMessage");
abd.uCallbackMessage = uCallBack;
uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd);
isBarRegistered = true;
ABSetPos(hrana);
}
else
{
toolBar = new Rectangle(0, 0, 0, 0);
SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd);
isBarRegistered = false;
//this.TopMost = true;
}
}
private void ABSetPos(string edge)
{
APPBARDATA abd = new APPBARDATA();
//SHAppBarMessage((int)ABMsg.ABM_SETAUTOHIDEBAR, ref abd);
abd.cbSize = Marshal.SizeOf(abd);
abd.hWnd = this.Handle;
if (edge == "" || edge == "top")
{
abd.uEdge = (int)ABEdge.ABE_TOP;
}
else if (edge == "right")
{
abd.uEdge = (int)ABEdge.ABE_RIGHT;
}
else if (edge == "left")
{
abd.uEdge = (int)ABEdge.ABE_LEFT;
}
else if (edge == "bottom")
{
abd.uEdge = (int)ABEdge.ABE_BOTTOM;
}
else
{
abd.uEdge = (int)ABEdge.ABE_TOP;
}
if (abd.uEdge == (int)ABEdge.ABE_LEFT || abd.uEdge == (int)ABEdge.ABE_RIGHT)
{
abd.rc.top = 0;
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height;
if (abd.uEdge == (int)ABEdge.ABE_LEFT)
{
abd.rc.left = 0;
abd.rc.right = Size.Width;
okraj = "left";
}
else
{
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width;
abd.rc.left = abd.rc.right - Size.Width;
okraj = "right";
}
}
else
{
abd.rc.left = Screen.FromControl(this).WorkingArea.Left;
abd.rc.right = Screen.FromControl(this).WorkingArea.Right;
if (abd.uEdge == (int)ABEdge.ABE_TOP)
{
abd.rc.top = Screen.FromControl(this).WorkingArea.Top;
abd.rc.bottom = Size.Height;
okraj = "top";
}
else
{
abd.rc.bottom = Screen.FromControl(this).WorkingArea.Bottom;
abd.rc.top = abd.rc.bottom - Size.Height;
okraj = "bottom";
}
}
SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd);
switch (abd.uEdge)
{
case (int)ABEdge.ABE_LEFT:
abd.rc.right = abd.rc.left + Size.Width;
break;
case (int)ABEdge.ABE_RIGHT:
abd.rc.left = abd.rc.right - Size.Width;
break;
case (int)ABEdge.ABE_TOP:
abd.rc.bottom = abd.rc.top + Size.Height;
break;
case (int)ABEdge.ABE_BOTTOM:
abd.rc.top = abd.rc.bottom - Size.Height;
break;
}
this.Top -= 1;
SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd);
MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, Size.Width, Size.Height, true);
toolBar = new Rectangle(abd.rc.left, abd.rc.top, Size.Width, Size.Height);
left = this.Left;
top = this.Top;
}