Loading a WPF Window without showing it

前端 未结 12 825
独厮守ぢ
独厮守ぢ 2020-12-12 16:14

I create a global hot key to show a window by PInvoking RegisterHotKey(). But to do this I need that window\'s HWND, which doesn\'t exist until the

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 16:41

    I had already posted an answer to that question, but I just found a better solution.

    If you just need to make sure that the HWND is created, without actually showing the window, you can do this:

        public void InitHwnd()
        {
            var helper = new WindowInteropHelper(this);
            helper.EnsureHandle();
        }
    

    (actually the EnsureHandle method wasn't available when the question was posted, it was introduced in .NET 4.0)

提交回复
热议问题