public static void ActivateAppBar(IntPtr hWnd) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; SHAppBarMessage(ABM_ACTIVATE, ref abd); }
public static void WindowPosChanged(IntPtr hWnd) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; SHAppBarMessage(ABM_WINDOWPOSCHANGED, ref abd); }
public static void UnregisterAppBar(IntPtr hWnd) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; SHAppBarMessage(ABM_REMOVE, ref abd); }
public static Rectangle SetPos(IntPtr hWnd, QueryPosResult pos) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; abd.uEdge = pos.edge; abd.rc.top = pos.rc.Top; abd.rc.bottom = pos.rc.Bottom; abd.rc.left = pos.rc.Left; abd.rc.right = pos.rc.Right; // Pass the final bounding rectangle to the system. SHAppBarMessage(ABM_SETPOS, ref abd); MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, true); return(new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top)); }
public static bool RegisterAppBar(IntPtr hWnd, int callback) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; abd.uCallbackMessage = callback; int retVal = SHAppBarMessage(ABM_NEW, ref abd); if (retVal == 0) { //registration failed return(false); } return(true); }
public static extern UIntPtr SHAppBarMessage(int dwMessage, ref APP_BAR_DATA abd);
/// <summary> /// Sizes and Moves the AppBar to a screen edge. /// </summary> internal static void DockAppBar(IntPtr hWnd, int edge, Size idealSize) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; abd.uEdge = edge; Size monitorSize = Screen.FromHandle(hWnd).Bounds.Size; if (edge == ABE_LEFT || edge == ABE_RIGHT) { abd.rc.top = 0; abd.rc.bottom = monitorSize.Height; if (edge == ABE_LEFT) { abd.rc.right = idealSize.Width; } else { abd.rc.right = monitorSize.Width; abd.rc.left = abd.rc.right - idealSize.Width; } } else { abd.rc.left = 0; abd.rc.right = monitorSize.Width; if (edge == ABE_TOP) { abd.rc.bottom = idealSize.Height; } else { abd.rc.bottom = monitorSize.Height; abd.rc.top = abd.rc.bottom - idealSize.Height; } } // Query the system for an approved size and position. SHAppBarMessage(ABM_QUERYPOS, ref abd); // Adjust the rectangle, depending on the edge to which the // appbar is anchored. switch (edge) { case ABE_LEFT: abd.rc.right = abd.rc.left + idealSize.Width; break; case ABE_RIGHT: abd.rc.left = abd.rc.right - idealSize.Width; break; case ABE_TOP: abd.rc.bottom = abd.rc.top + idealSize.Height; break; case ABE_BOTTOM: abd.rc.top = abd.rc.bottom - idealSize.Height; break; } // Pass the final bounding rectangle to the system. SHAppBarMessage(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); }
private static extern int SHAppBarMessage(int dwMessage, ref APP_BAR_DATA abd);
/// <summary> /// Unregisters the AppBar. /// </summary> internal static void UnregisterAppBar(IntPtr hWnd) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; SHAppBarMessage(ABM_REMOVE, ref abd); }
/// <summary> /// Registers the AppBar and assigns the appropriate callback message value. /// </summary> internal static bool RegisterAppBar(IntPtr hWnd, int uCallbackMessage) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; abd.uCallbackMessage = uCallbackMessage; int retVal = SHAppBarMessage(ABM_NEW, ref abd); if (retVal == 0) { //registration failed return false; } return true; }
public static QueryPosResult QueryPos(IntPtr hWnd, Point idealLocation, Size idealSize) { APP_BAR_DATA abd = new APP_BAR_DATA(); abd.cbSize = Marshal.SizeOf(abd); abd.hWnd = hWnd; // saved the proposed rectangle Rectangle R = new Rectangle(idealLocation, idealSize); abd.rc.left = R.Left; abd.rc.right = R.Right; // then figure out which screen that rectangle would be on Screen S = Screen.FromRectangle(R); // make it full height abd.rc.top = S.WorkingArea.Top; abd.rc.bottom = S.WorkingArea.Bottom; if (S.Bounds.Left != 0) // multiple monitors { R.Offset(-S.Bounds.Left, 0); } // see whether we are on the left or right side of the screen int centerX = (R.Left + R.Right) >> 1; int centerScreen = S.Bounds.Width >> 1; if (centerX < 0) // multiple monitors { if (Math.Abs(centerX) < centerScreen) { abd.uEdge = ABE_RIGHT; } else { abd.uEdge = ABE_LEFT; } } else if (centerX > centerScreen) { abd.uEdge = ABE_RIGHT; } else { abd.uEdge = ABE_LEFT; } // once we've decided on an edge, align the rect cleanly to that edge switch (abd.uEdge) { case ABE_LEFT: abd.rc.left = S.WorkingArea.Left; abd.rc.right = abd.rc.left + idealSize.Width; break; case ABE_RIGHT: abd.rc.right = S.WorkingArea.Right; abd.rc.left = abd.rc.right - idealSize.Width; break; } // Query the system for an approved size and position. SHAppBarMessage(ABM_QUERYPOS, ref abd); QueryPosResult ret = new QueryPosResult(); ret.edge = abd.uEdge; ret.rc = new Rectangle(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top); // return the approved position return(ret); }