private void RegisterBar() { APPBARDATA abd = new APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = this.Handle; if (!fBarRegistered) { uCallBack = RegisterWindowMessage("AppBarMessage"); abd.uCallbackMessage = uCallBack; uint ret = SHAppBarMessage((int)ABMsg.ABM_NEW, ref abd); fBarRegistered = true; ABSetPos(); } else { SHAppBarMessage((int)ABMsg.ABM_REMOVE, ref abd); fBarRegistered = false; } }
private void ABSetPos() { APPBARDATA abd = new APPBARDATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = this.Handle; abd.uEdge = this.DefaultEdge; 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; } else { abd.rc.right = SystemInformation.PrimaryMonitorSize.Width; abd.rc.left = abd.rc.right - Size.Width; } } else { abd.rc.left = 0; abd.rc.right = SystemInformation.PrimaryMonitorSize.Width; if (abd.uEdge == (int)ABEdge.ABE_TOP) { abd.rc.top = 0; abd.rc.bottom = Size.Height; } else { abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height; abd.rc.top = abd.rc.bottom - Size.Height; } } // Query the system for an approved size and position. SHAppBarMessage((int)ABMsg.ABM_QUERYPOS, ref abd); // Adjust the rectangle, depending on the edge to which the // appbar is anchored. 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; } // Pass the final bounding rectangle to the system. SHAppBarMessage((int)ABMsg.ABM_SETPOS, ref abd); // Move and size the appbar so that it conforms to the // bounding rectangle passed to the system. MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true); }
static extern uint SHAppBarMessage(int dwMessage, ref APPBARDATA pData);