Project Name : First (Created using MFC ActiveX Control Wizard)
In FirstCtl.cpp
#include "stdafx.h"
#include "First.h"
#include "FirstCtl.h"
#include "FirstPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CFirstCtrl, COleControl)
// Message map
BEGIN_MESSAGE_MAP(CFirstCtrl, COleControl)
//{{AFX_MSG_MAP(CFirstCtrl)
// NOTE - ClassWizard will add and remove message map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
// Dispatch map
BEGIN_DISPATCH_MAP(CFirstCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CFirstCtrl)
// NOTE - ClassWizard will add and remove dispatch map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CFirstCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox,
VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
// Event map
BEGIN_EVENT_MAP(CFirstCtrl, COleControl)
//{{AFX_EVENT_MAP(CFirstCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
// Property pages
BEGIN_PROPPAGEIDS(CFirstCtrl, 1)
PROPPAGEID(CFirstPropPage::guid)
END_PROPPAGEIDS(CFirstCtrl)
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CFirstCtrl, "FIRST.FirstCtrl.1",
0xde3cc48a, 0x2239, 0x47a4, 0x93, 0x8d, 0xac, 0xac, 0x10, 0x7c, 0xb2,
0xbf)
// Type library ID and version
IMPLEMENT_OLETYPELIB(CFirstCtrl, _tlid, _wVerMajor, _wVerMinor)
// Interface IDs
const IID BASED_CODE IID_DFirst =
{ 0x47e15924, 0x2001, 0x45b0, { 0xa6, 0x5e, 0x10, 0x7a, 0x70, 0xc,
0xd4, 0x78 } };
const IID BASED_CODE IID_DFirstEvents =
{ 0xd408c4dd, 0x88e, 0x4421, { 0xb9, 0xf0, 0xa1, 0x9a, 0x65, 0x3e,
0x9c, 0x34 } };
// Control type information
static const DWORD BASED_CODE _dwFirstOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CFirstCtrl, IDS_FIRST, _dwFirstOleMisc)
// CFirstCtrl::CFirstCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CFirstCtrl
BOOL CFirstCtrl::CFirstCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_FIRST,
IDB_FIRST,
afxRegApartmentThreading,
_dwFirstOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
// CFirstCtrl::CFirstCtrl - Constructor
CFirstCtrl::CFirstCtrl()
{
InitializeIIDs(&IID_DFirst, &IID_DFirstEvents);
// CFirstCtrl::~CFirstCtrl - Destructor
CFirstCtrl::~CFirstCtrl()
{ }
// CFirstCtrl::OnDraw - Drawing function
void CFirstCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds,
CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
pdc->Rectangle(rcBounds);
}
// CFirstCtrl::DoPropExchange - Persistence support
void CFirstCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
}
// CFirstCtrl::OnResetState - Reset control to default state
void CFirstCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// CFirstCtrl::AboutBox - Display an "About" box to the user
void CFirstCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_FIRST);
dlgAbout.DoModal();
}
Project Name : ActivexCtrlOwn (SDI)
Class Name : CDlg.cpp
Dialog Design:
First.ocx inserted using following step.
1. Project-> Add to project -> Components and controls-> Registered ActiveX
Control-> First.ocx->Insert->Ok->Close.
2. Drag and Drop the OCX.
In ActiveXCtrlOwnView.cpp
// ActiveXCtrlOwnView.cpp : implementation of the CActiveXCtrlOwnView class
//
#include "stdafx.h"
#include "ActiveXCtrlOwn.h"
#include "ActiveXCtrlOwnDoc.h"
#include "ActiveXCtrlOwnView.h"
#include "Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CActiveXCtrlOwnView
IMPLEMENT_DYNCREATE(CActiveXCtrlOwnView, CView)
BEGIN_MESSAGE_MAP(CActiveXCtrlOwnView, CView)
//{{AFX_MSG_MAP(CActiveXCtrlOwnView)
// NOTE - the ClassWizard will add and remove mapping macros
here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
// CActiveXCtrlOwnView construction/destruction
CActiveXCtrlOwnView::CActiveXCtrlOwnView()
{ }
CActiveXCtrlOwnView::~CActiveXCtrlOwnView()
{ }
BOOL CActiveXCtrlOwnView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
// CActiveXCtrlOwnView drawing
void CActiveXCtrlOwnView::OnDraw(CDC* pDC)
{
CActiveXCtrlOwnDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDlg dlg;
dlg.DoModal();
}
// CActiveXCtrlOwnView printing
BOOL CActiveXCtrlOwnView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
void CActiveXCtrlOwnView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{ }
void CActiveXCtrlOwnView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{ }
// CActiveXCtrlOwnView diagnostics
#ifdef _DEBUG
void CActiveXCtrlOwnView::AssertValid() const
{
CView::AssertValid();
}
void CActiveXCtrlOwnView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CActiveXCtrlOwnDoc* CActiveXCtrlOwnView::GetDocument() // non-debug version
is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CActiveXCtrlOwnDoc)));
return (CActiveXCtrlOwnDoc*)m_pDocument;
}
#endif //_DEBUG
OUTPUT