使用MFC对.Net Windows进行子类化 [英] Subclassing .Net Windows with MFC

查看:66
本文介绍了使用MFC对.Net Windows进行子类化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用OpenGL和DirectX的3D渲染组件(它可以配置它使用的引擎)。 Win32 dll公开了一个C ++接口,客户端传入了一个他们希望由库呈现的HWND(托管或非托管)。我们通过使用MFC函数SubclassWindow来实现这一点,从而对窗口进行子类化并处理我们需要的所有消息(鼠标移动,调整大小等)。这很有效,直到我们尝试处理.Net控件的子类窗口的WM_PAINT消息。处理WM_PAINT消息会导致应用程序的其余部分无法正确绘制(子类窗口的行为与预期一致)。我们通过在接口上放置一个draw函数并在每次.Net控件触发其Paint事件时调用它来解决这个问题。


我知道这个有点偏离墙壁,不太可能得到任何回应。有没有其他人遇到类似的行为,并找到了更好的解决方法?让渲染组件创建窗口并让.Net应用程序托管窗口可能会更好(并解决问题),有人知道怎么做吗?

I have created a 3D rendering component that uses both OpenGL and DirectX (it is configurable as to which engine it uses). The Win32 dll exposes a C++ interface and clients pass in an HWND (managed or unmanaged) that they would like to be rendered by the library. We achieve this by using the MFC function, SubclassWindow, to subclass the window and handle all of the messages that we need to (mouse movements, resize etc.). This works well until we attempt to handle the WM_PAINT message of the subclassed window of a .Net Control. Handling the WM_PAINT message results in the rest of the application not painting itself correctly (the subclassed window behaves as expected). We have got around the problem by putting a draw function on the interface and calling this every time the .Net control fires its Paint event.


I know that this is a slightly off the wall and unlikely to get any responses. Has anybody else encountered similar behaviour and found a better workaround? It might be better (and resolve the problem) to have the rendering component create the windows and have the .Net application host the windows, does anybody know how to do this?

推荐答案

您好,

这是否发生在所有.NET Windows窗体控件上,或者只有部分问题出现。根据我的理解,.NET控件可能与Win32控件不同。例如,ControlStyles.UserPaint指定控件是自己绘制的,或者操作系统是这样做的。由于.NET控件是在子类化窗口之后绘制的,因此ASP.NET控件覆盖了WM_PAINT消息(子类窗口)中的绘制内容。您可以尝试禁用.NET控件的ControlStyles.UserPaint以查看是否仍有问题。

更多信息
http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx

谢谢,
张荣春
Hello,

Does this happen to all .NET Windows Form Controls, or only some of them have the problem. As per my understanding, .NET control might paint different from Win32 controls. For example, ControlStyles.UserPaint specifies that the control is paint by itself or the operating system does so. Since the in .NET control is painting after the subclassed window, your paint stuff in WM_PAINT message(subclassed window) is covered by the .NET control's. You can try to disable the ControlStyles.UserPaint of the .NET control to see if you still have the problem.

More information
http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx

Thanks,
Rong-Chun Zhang


这篇关于使用MFC对.Net Windows进行子类化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆