Skip to content

Instantly share code, notes, and snippets.

@solariz
Created February 3, 2021 07:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solariz/7a84894bd6e50b551ff6c621339e55a4 to your computer and use it in GitHub Desktop.
Save solariz/7a84894bd6e50b551ff6c621339e55a4 to your computer and use it in GitHub Desktop.
tiny tool to move all Windows to the main Screen
/* tiny tool to move all Windows to the main Screen
* https://tcpip.wtf/en/rescreen-tool-to-move-all-windows-to-your-win-main-screen.htm
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace rescreen
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("rescreen - tiny window position mover.");
Console.WriteLine("more about me at: https://tcpip.wtf");
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
// only move Windows with a set title
if (!String.IsNullOrEmpty(process.MainWindowTitle) && !String.IsNullOrEmpty(process.ProcessName))
{
Console.WriteLine("+\tmoving: " + process.MainWindowTitle);
// Getting the Windows Handle
IntPtr id = process.MainWindowHandle;
// Getting dimensions of Window
RECT rct;
int width = 800; int height = 600;
if(GetWindowRect(id, out rct))
{
width = rct.Right - rct.Left;
height = rct.Bottom - rct.Top;
}
Program.MoveWindow(id, 100, 100, width, height, true);
}
}
}
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
}
}
@ikem-krueger
Copy link

Maybe you change the file extension to ".cs"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment