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(2000); 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
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/11389884.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
posted on 2019-08-21 17:10 jack_Meng 阅读(1379) 评论(0) 编辑 收藏 举报