title: Getting the handle of window in C#
body: <p>I have the following class declared:</p>
  
  <pre><code>public partial class MainWindow : Window
  </code></pre>
  
  <p>And I need to get the actual handle of the window once the window has one.
  How can I do that and where should I put the query function.</p>
  
  <p>What I tried so far was:</p>
  
  <pre><code>IntPtr hwnd = new WindowInteropHelper(this).Handle;
  </code></pre>
  
  <p>But the handle I get back is 0, which might be because it was planted in OnInitialized - maybe the window is not ready yet at that stage.
  And, yes - it is connected via WPF, thank you for pointing it out!</p>
  
  <p>Thanks</p>