如何带到前面 [英] How to bring to front
本文介绍了如何带到前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为一个游戏指挥官工作以使命令变得更容易
但我无法弄清楚如何将游戏带到前面而不重新启动它
我正在使用c#
我尝试了什么:
流程= Process.Start(@D:\ Games \SteamLibary \steamapps\common\ARK\ShooterGame\BINaries \Win64 \Shootergame.exe);
句柄= process.MainWindowHandle;
SetForegroundWindow(handle);
I'm working on a commander for games to make commands easier
but i can't figure out how to bring the game to the front without restarting it
I'm using c#
What I have tried:
process = Process.Start(@"D:\Games\SteamLibary\steamapps\common\ARK\ShooterGame\Binaries\Win64\Shootergame.exe");
handle = process.MainWindowHandle;
SetForegroundWindow(handle);
推荐答案
你需要像这样导入这个函数:
You need to import this function like this:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
process = Process.Start(@"D:\Games\SteamLibary\steamapps\common\ARK\ShooterGame\Binaries\Win64\Shootergame.exe");
handle = process.MainWindowHandle;
SetForegroundWindow(handle);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
使用< a href =https://docs.microsoft.com/en-gb/dotnet/api/system.diagnostics.process.getprocessesbyname> Process.GetProcessesByName [ ^ ]检索具有指定名称的正在运行的进程的列表。
Use Process.GetProcessesByName[^] to retrieve a list of the running processes with the specified name.
Process theProcess;
Process[] processes = Process.GetProcessesByName("shootergame");
if (processes.Length == 0)
{
// The game is not running:
theProcess = Process.Start(@"...");
}
else
{
theProcess = processes[0];
}
handle = theProcess.MainWindowHandle;
SetForegroundWindow(handle);
这篇关于如何带到前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文