为什么 GetSafeHwnd() 在 ActiveX 控件中返回零?

2022-01-12 00:00:00 activex c++ mfc visual-studio-2010

我开发了一个 MFC Activex 控件,它在运行时是无窗口且不可见的,而我假设 Activex 基本上是一个可以操作 Windows 句柄的控件,我使用 GetSafeHwnd() 来获取windows 句柄,但不幸的是,此方法在运行时返回零.也许我在创建我的 activex 时设置了错误的选项.我如何创建一个可以操作 Windows hanlde 的无窗口 Activex?

I have developed a MFC Activex control which is windowless and invisible in runtime, while i assumed that basically an activex is a control that would manipulate a windows handle, i have used GetSafeHwnd() to get windows handle, but unfortunately this method returns zero when it runs. maybe i had set wrong option when creating my activex. how i can create a windowless activex which could manipulate windows hanlde?

推荐答案

根据定义,无窗口 ActiveX 控件没有窗口,并且作为其父级的一部分呈现.如果您想在控件中使用 Windows 消息,您可以创建带有消息循环的工作线程,并在那里处理任何消息.要拥有消息循环,您不需要窗口,只需线程即可.该解决方案可以在无窗口控件或任何 COM 组件中实现.

By definition, windowless ActiveX control doesn't have a window, and rendered as part of its parent. If you want to work with Windows messages in the control, you can create worker thread with a message loop, and handle any messages there. To have message loop, you don't need a window, just thread. This solution can be implemented in windowless control or in any COM component.

或者,您可以通过更改其属性来使用窗口化 ActiveX 控件.

Alternatively, you can use windowed ActiveX control by changing its properties.

相关文章