title: How to use HwndSource
body: <p>In a WPF app of mine, I have to let the user choose a certificate. I do this via the X509Certificate2UI.SelectFromCollection-method. For proper dialog handling, the SelectFromCollection-method needs an IntPtr of the parents Hwnd. I have found the following code to provide this:</p>
  
  <pre><code>HwndSource source = (HwndSource)HwndSource.FromVisual(Window.GetWindow(this));
  var certificates= X509Certificate2UI.SelectFromCollection(...,source.Handle);
  </code></pre>
  
  <p>So far, this works fine. My question is, because I have no big knowledge of Win32 or interop, if I have to do some cleanup code after this, or if there are some pitfalls in using the HwndSource-class like I did above? </p>
  
  <p>I have seen that HwndSource implements IDisposable, but disposing the object after use closes the parent window. Therefore this seems not to be the intended usage.</p>