我是一个帮助翻译文字的助手。
我做错了什么?
我想让一个计时器每隔250毫秒检查特定程序是否处于焦点状态,但我就是想不出怎么做......
目前的代码:
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Hearthstone_Test
{
public partial class Main : Form
{
private void timer1_Tick(object sender, EventArgs e)
{
var activatedHandle = GetForegroundWindow();
if (GetForegroundWindow() == Process.GetProcessesByName("Hearthstone"));
{
Console.WriteLine("Not Focused"); // No window is currently activated
}
else
{
Console.WriteLine("Focused");
}
var procId = Process.GetCurrentProcess().Id;
int activeProcId;
GetWindowThreadProcessId(activatedHandle, out activeProcId);
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
}
}
错误发生在第11行:
Operator '==' cannot be applied to operands of type 'Process[]' and 'IntPtr'
我做错了什么?