Wrapping MFC Classes into OCX
Alexander Gavrilov -- Alexander_Gavrilov@esicorp.com Friday, November 15, 1996 Environment: Win 95, NT 4.0, VC++ 4.2b Does anyone out there have any experience wrapping an MFC Class, for example listbox into OCX. I have read "OLE Controls: Subclassing a Windows Control" article on MSDN, but the only thing it shows is how to subclass a Windows control. I have an MFC extension class, which is derived from CWnd, that I want to put in OCX. What I need to be able to do is to call member functions of the extension class. My idea was to instantiate the extension class myself and assign its window to the COleControl window, which is created whenever you subclass the control. Is this a right way to go? Any ideas would be appreciated.
Kevin Tarn -- kevin@earth.pln.com.tw Tuesday, November 19, 1996 >Environment: Win 95, NT 4.0, VC++ 4.2b > Does anyone out there have any experience wrapping an MFC Class, for > example listbox into OCX. I have read "OLE Controls: Subclassing a > Windows Control" article on MSDN, but the only thing it shows is how > to subclass a Windows control. I have an MFC extension class, which is > derived from CWnd, that I want to put in OCX. What I need to be able > to do is to call member functions of the extension class. My idea was > to instantiate the extension class myself and assign its window to the > COleControl window, which is created whenever you subclass the > control. Is this a right way to go? Any ideas would be appreciated. Two ways you can go ahead : 1. Transfer your extension control class's drawing codes to COleControl::OnDraw function, and implement necessary message functions in COleControl by calling your extention control class. Also, you must transfer your public member functions and variables in the extention class to methods and properties in the ole control. If this approach is critical pain for you, you can chose the second approach. 2. To encapsulate your extention control class to the new Ole Control which has a goody that all ole container can use it. int CMyOleControl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (COleControl::OnCreate(lpCreateStruct) == -1) return -1; if (!m_extCtrl.Create(this, ID_EXTENTION_CONTROL)) return -1; m_extCtrl.ShowWindow(SW_SHOW); return 0; } void CMyOleControl::OnSize(UINT nType, int cx, int cy) { COleControl::OnSize(nType, cx, cy); switch (nType) { case SIZE_MAXIMIZED: case SIZE_RESTORED: m_extCtrl.MoveWindow(0, 0, cx, cy); break; default: break; } } You should empty the COleControl::OnDraw default skeleton created by ControlWizard. Kevin Tarn kevin@pln.com.tw
Peter.Walker@ubs.com Monday, November 18, 1996 Steps to get going... 1)Embed member pointer of CWnd Derivative in CXXXCtrl Class 2)New the member in CXXXCtrl::CXXXCtrl 3)Override CXXXCtrl::OnCreate (LPCREATESTRUCT lpCreateStruct) to create specifed window if (!m_pGridWnd->Create(WS_VISIBLE|WS_CHILD,EmptyRect,this, IDC_GRID_CONTROL)) { TRACE(_T("Could not create grid\n")); return -1; } 4)Override CGTSGridCtrl::OnSize.. COleControl::OnSize(nType, cx, cy); ASSERT_VALID(m_pGridWnd); m_pGridWnd->MoveWindow(0,0,cx,cy); 5)Encapsulate any methods or properties via OLE Automation 6)Provide OLE Events for your events and callbacks. Peter Walker (Peter Walker@ubs.com) ______________________________ Reply Separator _________________________________ Subject: PUBLIC: Wrapping MFC Classes into OCX Author: owner-mfc-l (owner-mfc-l@majordomo.netcom.com) at zhux Date: 11/15/96 10:21 PM Environment: Win 95, NT 4.0, VC++ 4.2b Does anyone out there have any experience wrapping an MFC Class, for example listbox into OCX. I have read "OLE Controls: Subclassing a Windows Control" article on MSDN, but the only thing it shows is how to subclass a Windows control. I have an MFC extension class, which is derived from CWnd, that I want to put in OCX. What I need to be able to do is to call member functions of the extension class. My idea was to instantiate the extension class myself and assign its window to the COleControl window, which is created whenever you subclass the control. Is this a right way to go? Any ideas would be appreciated.
| Вернуться в корень Архива |