/** * <summary> * 左は1ウィンドウ、右は複数ウィンドウ * </summary> */ public override void CalcuratePosition(int windowCount, int monitorTop, int monitorBottom, int monitorLeft, int monitorRight) { if (windowCount == 0) { return; } // 定義すべきウィンドウ位置の最大数は、 // 右側の複数ウィンドウ+1(左側)だが // 右側はウィンドウ数によって可変 var countOfWindowOfRightColumn = this.maxCountOfWindowOfRightColumn; if (windowCount - 1 < countOfWindowOfRightColumn) { countOfWindowOfRightColumn = windowCount - 1; } // 左側列の定義 var monitorWidth = monitorRight - monitorLeft; var monitorHeight = monitorBottom - monitorTop; var windowWidthOfLeftColumn = (int)Math.Floor(monitorWidth * this.percentOfLeftColumn); this.windowRects.Add(new WindowRect( /* top = */ monitorTop, /* bottom = */ monitorBottom, /* left = */ monitorLeft, /* right = */ monitorLeft + windowWidthOfLeftColumn )); if (countOfWindowOfRightColumn == 0) { // 右側列にウィンドウがなければここで計算終了 return; } // 右側列の定義 var windowWidthOfRightColumn = monitorWidth - windowWidthOfLeftColumn; var windowHeightOfRightColumn = monitorHeight / countOfWindowOfRightColumn; var windowTop = monitorTop; var windowLeft = monitorLeft + windowWidthOfLeftColumn; var windowRight = windowLeft + windowWidthOfRightColumn; for (int i = 0; i < countOfWindowOfRightColumn; i++) { var windowBottom = windowTop + windowHeightOfRightColumn; var newWindowRect = new WindowRect( /* top = */ windowTop, /* bottom = */ windowBottom, /* left = */ windowLeft, /* right = */ windowRight ); var newWindowRectString = newWindowRect.ToString(); Logger.WriteLine($"WindowTilerDividerBugn.CalcuratePosition : {newWindowRectString}"); this.windowRects.Add(newWindowRect); windowTop = windowBottom; } }
/** * <summary> * windowRect が monitorRect からはみ出ていなければ True * </summary> */ protected bool IsWindowInMonitorRect(WindowRect monitorRect, WindowRect windowRect) { return(monitorRect.left <= windowRect.left && monitorRect.top <= windowRect.top && monitorRect.right >= windowRect.right && monitorRect.bottom >= windowRect.bottom ); }
/** * <summary> * src と dest のウィンドウの位置を入れ替える * </summary> */ public void ChangeWindowPosition(WindowInfoWithHandle srcWindowInfoWithHandle, WindowInfoWithHandle destWindowInfoWithHandle) { if (this.windowTilingType == WindowTilingType.None) { return; } WindowRect srcWindowRect = srcWindowInfoWithHandle.GetCurrentWindowRect(); WindowRect destWindowRect = destWindowInfoWithHandle.GetCurrentWindowRect(); this.MoveWindow(srcWindowInfoWithHandle, destWindowRect); this.MoveWindow(destWindowInfoWithHandle, srcWindowRect); }
/** * <summary> * 指定されたWindowInfoWithHandleをWindowRectの位置に移動する * ただしWindowInfoWithHandle.positionXXAdjustmentで位置を補正して隙間ができないようにする * </summary> */ public void MoveWindow(WindowInfoWithHandle windowInfoWithHandle, WindowRect windowRect) { var hWnd = windowInfoWithHandle.windowHandle; var windowRectString = windowRect.ToString(); Logger.WriteLine($"WindowManager.MoveWindow : hWnd={hWnd} To {windowRectString}"); // 最大化、最小化Windowの場合は元のウィンドウにする // if ( IsZoomed(hWnd) || IsIconic(hWnd)) if (IsZoomed(hWnd)) { ShowWindow(hWnd, /* SW_RESTORE = */ 9); } MoveWindow(hWnd, windowRect.GetX() + windowInfoWithHandle.positionLeftAdjustment, windowRect.GetY() + windowInfoWithHandle.positionTopAdjustment, windowRect.GetWidth() + windowInfoWithHandle.positionWidthAdjustment, windowRect.GetHeight() + windowInfoWithHandle.positionHeightAdjustment, /* bRepaint = */ 1); }
/** * <summary> * MDI形式に並べるためにウィンドウ位置を計算する * 左上から右下へ shiftWidht, shiftHeight 分ずつずらしながら求める * マージンをはみ出ないようにする。はみでる場合は * </summary> */ public override void CalcuratePosition(int windowCount, int monitorTop, int monitorBottom, int monitorLeft, int monitorRight) { var monitorWidth = monitorRight - monitorLeft; var monitorHeight = monitorBottom - monitorTop; var windowWidth = (int)Math.Floor(monitorWidth * this.percentOfWidthOfWindow); var windowHeight = (int)Math.Floor(monitorHeight * this.percentOfHeightOfWindow); var marginedMonitorTop = monitorTop + this.marginTopToMonitor; var marginedMonitorBottom = monitorBottom - this.marginBottomToMonitor; var marginedMonitorLeft = monitorLeft + this.marginLeftToMonitor; var marginedMonitorRight = monitorRight - this.marginRightToMonitor; WindowRect marginedMonitorRect = new WindowRect( marginedMonitorTop, marginedMonitorBottom, marginedMonitorLeft, marginedMonitorRight ); var windowTop = marginedMonitorTop; var windowLeft = marginedMonitorLeft; var shiftWidthCount = 0; for (int i = 0; i < windowCount; i++) { var newWindowRect = new WindowRect( /* top = */ windowTop, /* bottom = */ windowTop + windowHeight, /* left = */ windowLeft, /* right = */ windowLeft + windowWidth ); if (!this.IsWindowInMonitorRect(marginedMonitorRect, newWindowRect)) { // もしモニターからはみ出る場合は位置を調整して再計算する // 縦にはみ出る場合は縦位置をトップに戻し、横位置は初期位置+shiftWidth*shiftWidthCount分ずらす // 横にはみ出る場合は縦位置、横位置ともに初期位置に戻す var windowRight = newWindowRect.right; if (marginedMonitorRect.bottom < newWindowRect.bottom) { shiftWidthCount++; windowTop = marginedMonitorTop; windowLeft = marginedMonitorLeft + this.shiftWidthToNextWindow * shiftWidthCount; windowRight = windowLeft + windowWidth; } if (marginedMonitorRect.right < windowRight) { windowTop = marginedMonitorTop; windowLeft = marginedMonitorLeft; windowRight = windowLeft + windowWidth; } newWindowRect = new WindowRect( /* top = */ windowTop, /* bottom = */ windowTop + windowHeight, /* left = */ windowLeft, /* right = */ windowRight ); } Logger.WriteLine(newWindowRect.ToString()); this.windowRects.Add(newWindowRect); windowTop += this.shiftHeightToNextWindow; windowLeft += this.shiftWidthToNextWindow; } }