c# - 如何将重点放在流程上?
问题描述
我有一个名为 _program 的 System.Diagnostics.Process 变量。
我知道不是每个进程都有用户界面,所以它永远不会有焦点(我认为)。
但是,假设这个进程有一个接口,是否可以设置焦点呢?也许我需要使用 Process.StandardInput?
解决方案
使用 PInvoke 调用原生函数来设置前台窗口:
using System.Runtime.InteropServices;
DllImport("User32.dll")]
private static extern Int32 SetForegroundWindow(int hWnd);
void YourMethod()
{
Process p = ... //However you create your process
SetForegroundWindow(p.MainWindowHandle); //Set this process's main window as the foreground window
}
推荐阅读
- laravel - Laravel:队列工作失败 pcntl_signal() 以确保安全
- linux - 如何使用 ed 在最后一次模式匹配后添加文本
- javascript - Vuex:在挂载的钩子中返回吸气剂
- java - 如何手动发送起始位?
- c# - 如何使用已在 Azure 中注册的应用程序使用实体框架数据库优先方法连接到 Azure SQL DB
- lua - 如何在最新版本的 LuaJit 中发送 HTTP 请求,现在什么库实际工作?
- kubernetes - nginx入口控制器忽略css和js文件 - 谷歌kuberenetes引擎
- c++ - C++ - 重写虚函数和多态性
- c++ - 为旧的 Linux 环境编译 C++ 应用程序
- prolog - 这个函数是尾递归的吗?为什么大列表会失败?