public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
Timer timer=new Timer();
public Form1()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 200;
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
IntPtr hwnd = FindWindow("NotePad", "NotePad");
IntPtr ActiveHandle = GetActiveWindow();
if (hwnd==ActiveHandle)
{
timer.Stop();
MessageBox.Show("NotePad on top");
}
}
}