API:GetForegroundWindow获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口
------------------------
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();int iHnd=GetForegroundWindow();这个iHnd就是当前活动窗口的句柄了
------------------------
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();int iHnd=GetForegroundWindow();这个iHnd就是当前活动窗口的句柄了
GetForegroundWindow(); 使用 foreach (Process thisproc in Process.GetProcessesByName("WINWORD")) //进程名字
{
if( thisproc.MainWindowHandle.ToInt32()==GetForegroundWindow().ToInt32()
//你的代码 }