可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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);