你可以用 [DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(
string lpClassName,
string lpWindowName
);
来获得窗体句柄,然后直接用C#的process类获得所有进程的句柄和ID然后比对就可以了
[DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]
private static extern int GetWindowThreadProcessId(IntPtr hwnd, out int pid);
试试看这个行不行