private void BeginMovingWindow(IntPtr hWnd) { Debug.Assert(dropBar == null); uint style = WinAPI.GetWindowLong(hWnd, WinAPI.GWL_STYLE); bool canBeMaximized = ((style & WinAPI.WS_MAXIMIZEBOX) == WinAPI.WS_MAXIMIZEBOX) || ((style & WinAPI.WS_SIZEBOX) == WinAPI.WS_SIZEBOX); if (canBeMaximized) { DropBar.WindowPosType windowPos = (Screen.FromHandle(hWnd).Primary ? DropBar.WindowPosType.OnTop : DropBar.WindowPosType.OnBottom); dropBar = new DropBar(windowPos); dropBar.Show(); } }
private void EndMovingWindow(IntPtr hWnd, Rectangle wndStartPos) { if (dropBar == null) { return; } switch (dropBar.Selection) { case DropBar.SelectionType.ToTop: case DropBar.SelectionType.ToTopLeft: case DropBar.SelectionType.ToTopRight: //Keep same margin than it have on bottom screen: wndStartPos.Y = Screen.AllScreens[0].Bounds.Y + wndStartPos.Top - Screen.AllScreens[1].Bounds.Top; break; case DropBar.SelectionType.ToBottom: case DropBar.SelectionType.ToBottomLeft: case DropBar.SelectionType.ToBottomRight: //Set no margin for bottom screen because bottom screen is too small: wndStartPos.Y = Screen.AllScreens[1].Bounds.Y; break; } switch (dropBar.Selection) { case DropBar.SelectionType.ToTop: case DropBar.SelectionType.OnTop: MaximizeWindowToScreen(hWnd, Screen.AllScreens[0], wndStartPos); break; case DropBar.SelectionType.ToTopLeft: case DropBar.SelectionType.OnTopLeft: ExpandWindowToHalfScreen(hWnd, Screen.AllScreens[0], true); break; case DropBar.SelectionType.ToTopRight: case DropBar.SelectionType.OnTopRight: ExpandWindowToHalfScreen(hWnd, Screen.AllScreens[0], false); break; case DropBar.SelectionType.ToBottom: case DropBar.SelectionType.OnBottom: MaximizeWindowToScreen(hWnd, Screen.AllScreens[1], wndStartPos); break; case DropBar.SelectionType.ToBottomLeft: case DropBar.SelectionType.OnBottomLeft: ExpandWindowToHalfScreen(hWnd, Screen.AllScreens[1], true); break; case DropBar.SelectionType.ToBottomRight: case DropBar.SelectionType.OnBottomRight: ExpandWindowToHalfScreen(hWnd, Screen.AllScreens[1], false); break; case DropBar.SelectionType.Expand: ExpandWindowToBothScreens(hWnd); break; } dropBar.Close(); dropBar = null; }