これは直接行うことはできないようです。しかし、node.jsからちょっとしたヘルパープログラムを始めると、難しくありません。私は、次のような機能を持つ小さなC#コンソールアプリケーションを作っnodejs docs
:
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
その後、私はSystem.Windows.Forms.Screen.AllScreens
反復処理とProcess
私の実行を開始するあなたはでexecFile()
表情でそれを開始することができます。 Process
から私はMainWindowHandle
を取得しました。それで、あなたが望むスクリーンにウィンドウを設定することが可能です。
static void Main(string[] args)
{
if (args.Length == 1 && args[0].Equals("h"))
{
Console.Out.WriteLine("Command: [displayName] [executable] [arguments for executable]");
return;
}
if (args.Length < 2)
{
Console.Out.WriteLine("arguments not correct. Should be: [displayName] [executable1] [arguments for executable]");
return;
}
foreach (var screen in Screen.AllScreens)
{
Console.Out.WriteLine(screen.DeviceName);
if (screen.DeviceName.Equals(args[0]))
{
var process = new Process();
process.StartInfo.FileName = args[1];
string[] arguments = args.Skip(2) as string[];
if (arguments != null) process.StartInfo.Arguments = string.Join(" ", arguments);
process.Start();
var hwnd = process.MainWindowHandle;
Console.Out.WriteLine("while get process.MainWindowHandle");
while (!process.HasExited)
{
process.Refresh();
if (process.MainWindowHandle.ToInt32() != 0)
{
hwnd = process.MainWindowHandle;
break;
}
}
Console.Out.WriteLine("windowHandle: " + hwnd);
MoveWindow(hwnd, screen.WorkingArea.X, screen.WorkingArea.Y, screen.WorkingArea.Width, screen.WorkingArea.Height, true);
ShowWindow(hwnd, SwMaximize);
SetForegroundWindow(hwnd);
// Waits here for the process to exit.
process.WaitForExit();
return;
}
}
Console.Out.WriteLine("screen not found: " + args[0]);
}
}