Get the WPF Window handle

using System;
using System.Windows;

using System.Windows.Interop; // WindowInteropHelper


namespace WindowsApplication1
{
    ///
    /// Interaction logic for Window1.xaml
    ///


    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            try
            {
                InitializeComponent();
                this.SourceInitialized += new EventHandler(Window1_SourceInitialized);
            }
            catch(Exception exp)
            {
                string str = exp.Message;
            }

        }

        void Window1_SourceInitialized(object sender, EventArgs e)
        {
            WindowInteropHelper helper = new WindowInteropHelper(this);
            IntPtr ptr = helper.Handle;
        }

        //private void ClickBtn(object sender, EventArgs e)
        //{
        //}
    }
}

你可能感兴趣的:(Get the WPF Window handle)