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

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

问题描述

我有一个使 COM 可见的 Windows 窗体用户控件.现在我想将该控件嵌入到 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);

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

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