WPF では Window クラスにウィンドウハンドルを取得するためのプロパティが無いけど*1、取得する方法はちゃんと提供されている。System.Window.Interop.WindowInteropHelper クラスを使えばいい。
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } // ウィンドウハンドルを取得 public IntPtr Handle { get { var helper = new System.Windows.Interop.WindowInteropHelper(this); return helper.Handle; } } }
ウィンドウハンドルを必要とするコードを書かないのが一番良いんだけど、開発するアプリの仕様上、どうしても必要なときがあるんだよね…。シェルの API を呼び出すときとか。
*1:WinForm にはあるけどね。