Force BuildWindowCore member of a HwndHost derived class to be called

发布于 2022-09-06 11:02:03 字数 477 浏览 28 评论 0

I use a class derived from HwndHost to host a Win32 window. It is in turn used within a user control. That user control doesn't get shown (Visibility) unless the internal Win32 window gets successfully created. However, the BuildWindowCore method doesn't appear to be called unless the HwndHost window is visible, so I have a chicken & egg situation.

If a HwndHost derived class is not visible, is there another way to get it's BuildWindowCore method called?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2022-09-13 11:02:03

Well, a month has passed with no answers. Looks like I've stumped everyone including myself.

So, the answer as of .NET 4.0 is "No, there is no way to force BuildWindowCore to be called before the framework is ready to call it."

掩于岁月 2022-09-13 11:02:03

You can create your Win32 window yourself and just use HwndHost as a wrapper like in the example below.

ref class MyHost : HwndHost 
{
private:
   HWND  m_hWnd;
public:
   MyHost(HWND hWnd)
   {
      m_hWnd = hWnd;
   }
protected: 
  virtual HandleRef BuildWindowCore(HandleRef hwndParent) override 
  {
     // Simply re-parent the window
     SetParent(m_hWnd, (HWND) hwndParent.Handle.ToPointer());
     return HandleRef(this, (IntPtr) m_hWnd);
  } 

  virtual void DestroyWindowCore(HandleRef hwnd) override
  {
     ::DestroyWindow(m_hWnd);
  }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文