回答
有从Windows命令提示符定位一个窗口没有直接的方法。您基本上有以下选项:
使用GUI自动化工具,例如, AutoHotkey它允许您脚本窗口操作。 AutoHotkey例如提供WinMove命令:
Run, calc.exe WinWait, Calculator WinMove, 0, 0 ; Move the window found by WinWait to the upper-left corner of the screen.
使用PowerShell,例如与WASP snapin(http://wasp.codeplex.com/)。
用C/C++/.NET编写一个简短的程序,将活动窗口定位在主屏幕的位置0,0处。
一个非常基本的程序在C#中,这需要一个窗口标题为参数可能看起来像:
using System;
using System.Runtime.InteropServices;
class Program
{
public const int SWP_NOSIZE = 0x0001;
public const int SWP_NOZORDER = 0x0004;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
static void Main(string[] args)
{
IntPtr handle = FindWindow(null, args[0]);
SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
}
使用start
命令。
cmd box type help start
。
例如:start /MAX "xxx.bat"
这将启动窗口最大化。 OP想要的是一个窗口对齐屏幕的左上角。 – 2009-12-09 09:15:36
对于cmd(蝙蝠),当最大化时,窗口将被捕捉到左上角。 – Francis 2009-12-09 10:27:58
cmd也将通过此命令最大化地启动。 – 2009-12-09 10:31:32
这是一个有点混乱,但我认为这是可以做到。
您需要安装两个程序:
AutoIt的
Winsplit革命
创建一个AutoIt脚本到:
1.打开你想要的程序或批处理文件
2.等待,直到该程序打开
3.将程序激活窗口
4.调用ctrl + alt + 7,“发送(”^!7“)”(Winsplit Revolution快捷方式将程序发送到左上角)
5.结束脚本
如果我有时间后,我会尝试编写脚本
我给你这个答案。但我会用你和弗朗西斯的方法。我的主脚本也调用了几个.bat文件和可执行文件。 AutoHotKey方法看起来更容易;不是我以前使用过AutoHotKey。 +1知识:) – user226973 2009-12-10 02:04:44