回答
有從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