如何将Windows窗体嵌入非托管ATL GUI? [英] How to embed Windows Form in unmanaged ATL GUI?

查看:221
本文介绍了如何将Windows窗体嵌入非托管ATL GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体用户控件,使COM可见。现在我想将该控件嵌入到ATL对话框GUI中。

I have a Windows form user control that is made COM visible. Now I want to embed that control into an ATL dialog GUI.

ATL项目(非托管C ++)只能获取winform的progID并动态创建和嵌入

The ATL project (unmanaged C++) shall only get the progID of the winform and dynamically create and embed it at runtime.

这是可能的,如果是这样,

Is this possible and if so, how do I do it?

推荐答案

我想出了一种方法让它工作。

以下代码使用一个名为m_Control的CWnd,它通过一个小小的文档版本的CreateControl托管一个winform。似乎工作正常到目前为止。如果任何人看到任何缺陷,请评论或回复。

I figured out a way to get it to work.
The following code is using a CWnd called m_Control that is made to host a winform via a little documented version of CreateControl. Seems to work fine so far. If anyone sees any drawbacks, please comment or respond.

AfxEnableControlContainer();
Microsoft::VisualC::MFC::CControlCreationInfoEx i;
i.Init(System::Type::GetTypeFromProgID(gcnew System::String(sProgID)),
       CControlCreationInfo::ReflectionType);
i.m_clsid = CLSID_WinFormsControl;
POINT pt;
pt.x = pt.y = 0;
SIZE sz;
sz.cx = sz.cy = 100;
m_Control.CreateControl(i, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
                        &pt, &sz, CWnd::FromHandle(m_hWnd), ID_CONTROL);

这篇关于如何将Windows窗体嵌入非托管ATL GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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