C#启动计算器并设计算器为活动窗口

启动计算器,并获取焦点

using System;
using System.Runtime.InteropServices; namespace ConsoleApplication3
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
System.Diagnostics.Process myProcess = new
System.Diagnostics.Process();
myProcess.StartInfo.FileName = "calc";
myProcess.Start();
myProcess.WaitForInputIdle();
IntPtr hWnd = myProcess.MainWindowHandle;
Console.WriteLine(hWnd);
bool p = SetForegroundWindow(hWnd);
if(!p)
Console.WriteLine("Could not set focus");
}
[DllImport("user32.dll", CharSet=CharSet.Auto,SetLastError=true)] public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto,SetLastError=true)] public static extern IntPtr SetFocus(IntPtr hWnd);
}
}

出处:https://bytes.com/topic/c-sharp/answers/436986-process-setfocus

上一篇:[GE]手动截取当前活动窗口,并且按规则命名(1/2)


下一篇:MVC视图中的@Html.xxx(...)