How to embed Windows Form in unmanaged ATL GUI?

痴心易碎 提交于 2019-12-02 12:35:04

问题


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

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?


回答1:


I am not sure about ATL but this can be done easily in MFC using CWinFormsView and CWinFormsControl classes.

I think there is no bulitin support to host a WinForm Control in an ATL Window but I think you can do it by simple getting the HWND of your winform control and setting your ATL control as its parent. This might be a tough road though.

This seems to be a similar type of thing. I havent tested it myself though.

Link




回答2:


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);


来源:https://stackoverflow.com/questions/642082/how-to-embed-windows-form-in-unmanaged-atl-gui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!