1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
-
- using System.Runtime.InteropServices;
- const int GWL_STYLE = -16;
- const int WS_BORDER = 0x00800000;
- const int WS_CAPTION = 0x00C00000;
- const int WS_THICKFRAME = 0x00040000;
- const int SW_SHOWNORMAL = 1;
- if (args.Length < 5)
- {
- Console.WriteLine("用法: WndTricker <窗口标题> <x坐标> <y坐标> <宽度> <高度>");
- return;
- }
- string windowTitle = args[0];
- if (!int.TryParse(args[1], out int x) ||
- !int.TryParse(args[2], out int y) ||
- !int.TryParse(args[3], out int width) ||
- !int.TryParse(args[4], out int height))
- {
- Console.WriteLine("参数无效,请确保 x, y, 宽度和高度是整数");
- return;
- }
- IntPtr hWnd = FindWindow(null, windowTitle);
- if (hWnd == IntPtr.Zero)
- {
- Console.WriteLine("窗口未找到");
- return;
- }
- int currentStyle = GetWindowLong(hWnd, GWL_STYLE);
- SetWindowLong(hWnd, GWL_STYLE, currentStyle & ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME));
- SetWindowPos(hWnd, IntPtr.Zero, x, y, width, height, 0);
- ShowWindow(hWnd, SW_SHOWNORMAL);
- Console.WriteLine($"窗口已去掉边框并移动到 ({x}, {y}),大小已设置为 {width}x{height}");
- return;
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll")]
- static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
- [DllImport("user32.dll")]
- static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
- [DllImport("user32.dll")]
- static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- [DllImport("user32.dll")]
- static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|