static void Maximize(IntPtr wHandle, string action) { if (action == "restore") { int index = 0; foreach (SavedWindow sw in savedWindows) { if (sw.handle == wHandle) break; ++index; } //restore style SetWindowLong(wHandle, -16, savedWindows[index].windowStyle); //restore position SetWindowPos(wHandle, (IntPtr)(0), savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Top, savedWindows[index].windowRect.Right - savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Bottom - savedWindows[index].windowRect.Top, (SetWindowPosFlags)0x0020); ShowWindow(wHandle, (ShowWindowCommands)5); MoveWindow(wHandle, savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Top, savedWindows[index].windowRect.Right - savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Bottom - savedWindows[index].windowRect.Top, true); savedWindows.RemoveAt(index); } else { //save position and style for restoring int wStyle = GetWindowLong(wHandle, -16); RECT rWind; GetWindowRect(wHandle, out rWind); SavedWindow w = new SavedWindow(); w.handle = wHandle; w.windowRect = rWind; w.windowStyle = wStyle; savedWindows.Add(w); if (action == "strip") { SetWindowLong(wHandle, -16, wStyle & ~(0x00040000 | 0x00C00000)); int LEFT = bounds.Left + BORDER_LEFT; int TOP = bounds.Top + BORDER_TOP; int RIGHT = bounds.Right - BORDER_RIGHT - BORDER_LEFT; int BOTTOM = bounds.Bottom - BORDER_BOTTOM - BORDER_TOP; SetWindowPos(wHandle, (IntPtr)(0), LEFT, TOP, RIGHT, BOTTOM, (SetWindowPosFlags)0x0020); ShowWindow(wHandle, (ShowWindowCommands)5); } else if (action == "resize") { RECT rClient; GetWindowRect(wHandle, out rWind); GetClientRect(wHandle, out rClient); int border_thickness = ((rWind.Right - rWind.Left) - rClient.Right) / 2; int titlebar_height = rWind.Bottom - rWind.Top - rClient.Bottom - border_thickness; int LEFT = -border_thickness; int TOP = -titlebar_height; int RIGHT = bounds.Right + (border_thickness * 2); int BOTTOM = bounds.Bottom - BORDER_BOTTOM + titlebar_height + border_thickness; ShowWindow(wHandle, (ShowWindowCommands)9); MoveWindow(wHandle, LEFT, TOP, RIGHT, BOTTOM, true); ShowWindow(wHandle, (ShowWindowCommands)5); } } }
static void Maximize(IntPtr wHandle, string action) { if (action == "restore") { int index = 0; foreach (SavedWindow sw in savedWindows) { if (sw.handle == wHandle) { break; } ++index; } //restore style SetWindowLong(wHandle, -16, savedWindows[index].windowStyle); //restore position SetWindowPos(wHandle, (IntPtr)(0), savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Top, savedWindows[index].windowRect.Right - savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Bottom - savedWindows[index].windowRect.Top, (SetWindowPosFlags)0x0020); ShowWindow(wHandle, (ShowWindowCommands)5); MoveWindow(wHandle, savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Top, savedWindows[index].windowRect.Right - savedWindows[index].windowRect.Left, savedWindows[index].windowRect.Bottom - savedWindows[index].windowRect.Top, true); savedWindows.RemoveAt(index); } else { //save position and style for restoring int wStyle = GetWindowLong(wHandle, -16); RECT rWind; GetWindowRect(wHandle, out rWind); SavedWindow w = new SavedWindow(); w.handle = wHandle; w.windowRect = rWind; w.windowStyle = wStyle; savedWindows.Add(w); if (action == "strip") { SetWindowLong(wHandle, -16, wStyle & ~(0x00040000 | 0x00C00000)); int LEFT = bounds.Left + BORDER_LEFT; int TOP = bounds.Top + BORDER_TOP; int RIGHT = bounds.Right - BORDER_RIGHT - BORDER_LEFT; int BOTTOM = bounds.Bottom - BORDER_BOTTOM - BORDER_TOP; SetWindowPos(wHandle, (IntPtr)(0), LEFT, TOP, RIGHT, BOTTOM, (SetWindowPosFlags)0x0020); ShowWindow(wHandle, (ShowWindowCommands)5); } else if (action == "resize") { RECT rClient; GetWindowRect(wHandle, out rWind); GetClientRect(wHandle, out rClient); int border_thickness = ((rWind.Right - rWind.Left) - rClient.Right) / 2; int titlebar_height = rWind.Bottom - rWind.Top - rClient.Bottom - border_thickness; int LEFT = -border_thickness; int TOP = -titlebar_height; int RIGHT = bounds.Right + (border_thickness * 2); int BOTTOM = bounds.Bottom - BORDER_BOTTOM + titlebar_height + border_thickness; ShowWindow(wHandle, (ShowWindowCommands)9); MoveWindow(wHandle, LEFT, TOP, RIGHT, BOTTOM, true); ShowWindow(wHandle, (ShowWindowCommands)5); } } }