Finding the handle to a WPF window

前端 未结 4 1376
庸人自扰
庸人自扰 2020-11-30 00:19

Windows forms had a property win1.Handle which, if I recall, returns the handle of the main window handle?

Is there an equivalent way to get the handle of a WPF Wind

相关标签:
4条回答
  • 2020-11-30 00:44

    Well, instead of passing Application.Current.MainWindow, just pass a reference to whichever window it is you want: new WindowInteropHelper(this).Handle and so on.

    0 讨论(0)
  • 2020-11-30 00:47

    Just use your window with the WindowsInteropHelper class:

    // ... Window myWindow = get your Window instance...
    IntPtr windowHandle = new WindowInteropHelper(myWindow).Handle;
    

    Right now, you're asking for the Application's main window, of which there will always be one. You can use this same technique on any Window, however, provided it is a System.Windows.Window derived Window class.

    0 讨论(0)
  • 2020-11-30 00:47

    you can use :

    Process.GetCurrentProcess().MainWindowHandle
    
    0 讨论(0)
  • 2020-11-30 00:55

    If you want window handles for ALL of your application's Windows for some reason, you can use the Application.Windows property to get at all the Windows and then use WindowInteropHandler to get at their handles as you have already demonstrated.

    0 讨论(0)
提交回复
热议问题