private int VerticalTile() { int tileCnt = 0; int column = (int)(Math.Ceiling((decimal)((Items.Count - 1) / 7.0f)) + 1); int[] row = new int[column]; int cnt = Items.Count; int col = column; for (int i = 0; i < row.Length; ++i) { row[i] = (int)(Math.Floor((decimal)(cnt / col))); cnt -= row[i]; --col; } int n = 0; int width, height; IntPtr Handle; WinAPI.DSIZE scale = GHManager.Scale; Rectangle workRect = GHManager.WorkingArea; workRect = new Rectangle( (int)(workRect.Left / scale.cx), (int)(workRect.Top / scale.cy), (int)(workRect.Width / scale.cx), (int)(workRect.Height / scale.cy) ); height = (workRect.Height / column); for (int i = 0; i < column; ++i) { width = (workRect.Width / row[i]); for (int j = 0; j < row[i]; ++j) { Handle = (IntPtr)Items[n].Handle; if (GHProcess.IsMinimize(Handle)) { GHProcess.Normalize(Handle); } WinAPI.GetWindowRect(Handle, out WinAPI.RECT rect1); DwmAPI.GetWindowRect(Handle, out Rectangle rect2); int dif = rect2.Left - rect1.left; Items[n].PrevRect = new Rectangle(rect1.left, rect1.top, rect1.right - rect1.left, rect1.bottom - rect1.top); WinAPI.SetWindowPos(Handle, new IntPtr(-1), width * j - dif + workRect.Left, height * i + workRect.Top, width + dif * 2, height + dif, WinAPI.SWP_SHOWWINDOW); WinAPI.SetWindowPos(Handle, new IntPtr(-2), 0, 0, 0, 0, WinAPI.SWP_NOMOVE | WinAPI.SWP_NOSIZE | WinAPI.SWP_SHOWWINDOW); ++n; tileCnt++; } } return(tileCnt); }
/// <summary> /// メニューの ウィンドウを並べる をクリックした時のイベント /// </summary> private void MenuItem_AutoTile2_Click(object sender, EventArgs e) { int tileCnt = 0; if (Items.Count == 1) { if (GHProcess.IsMinimize((IntPtr)Items.First().Handle)) { return; } DwmAPI.GetWindowRect((IntPtr)Items[0].Handle, out Rectangle rect); Items[0].PrevRect = rect; GHProcess.Maximize((IntPtr)Items[0].Handle); tileCnt++; } else { tileCnt = VerticalTile(); } if (tileCnt > 0) { IsTiledWindows = true; } }