如何获得Window实例的hWnd? [英] How to get the hWnd of Window instance?
本文介绍了如何获得Window实例的hWnd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的WPF应用程序有多个窗口,我需要能够得到每个Window实例的hWnd,这样我可以在Win32 API调用中使用它们。
My WPF application has more than one window, I need to be able to get the hWnd of each Window instance so that I can use them in Win32 API calls.
我想做些什么例子:
Window myCurrentWindow = Window.GetWindow(this);
IntPtr myhWnd = myCurrentWindow.hWnd; // Except this property doesn't exist.
什么是做到这一点的最好方法是什么?
What's the best way to do this?
推荐答案
WindowInteropHelper
是你的朋友。它有一个接受窗口
参数的构造函数,和处理返回其窗口句柄
属性。
WindowInteropHelper
is your friend. It has a constructor that accepts a Window
parameter, and a Handle
property that returns its window handle.
Window window = Window.GetWindow(this);
var wih = new WindowInteropHelper(window);
IntPtr hWnd = wih.Handle;
这篇关于如何获得Window实例的hWnd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文