title: How can I tell my application window is the foreground window
body: <p>I have the following problem: I want to be able to tell if my application window is the foreground window in Windows. I am using C#, .Net Framework 3.5 on Windows XP.</p>
  
  <p>I actually can think of two ways to do what I am after</p>
  
  <ol>
  <li>Use pinvoke, <code>GetForeGroundWindow</code> and compare the returned hWnd to the hWnd of my form</li>
  <li>Check if <code>Form.ActiveForm</code> is <code>null</code> or an object reference</li>
  </ol>
  
  <p>Method 1 seems OK, but I would rather not use pinvoke unless I have to. I am not entirely sure about method 2 although it seems to work OK.</p>
  
  <p>Which method should I use, is there any other way?</p>