Introduction
Hai, This is on for the Beginners in ActiveX Control. It is created in VC++ 6.0
and it can be taken as ActiveX tutorial.
Background
More programmers are tried to explin the concept of Activex Control.
This program will help you to clearly understand OCX creation and Usage in VC++.
IN VC++:
Step : 1 File -> New -> MFC Activex Control Wizard
Step2 : Give the Project name as you desire.
Step 3 : Click OK and Choose the control subclass type is STAIC in the Drop List Box
Step 4: Give the Name of the Subclass
Step 5: Click Finish
Step 6 : Add the Message Handler the prjnamectrl class in prjnamectrl.cpp
1. WM_PAINT - Add the follwing Coding on that
void CShapeCtrl::OnPaint()
{ SetTimer(1,100,0);
CPaintDC dc(this); // device context for painting
// Do not call COleControl::OnPaint() for painting messages
}
2. WM_TIMER - Add the Follwing Coding in that
CDC *cd;
void CShapeCtrl::OnTimer(UINT nIDEvent)
{
if(nIDEvent==1)
{ SYSTEMTIME st;CString cs;
CRect g;g.top=0;g.left=0;g.right=200;g.bottom=18;
CBrush cb;cb.CreateSolidBrush(RGB(192,192,192));
CRgn crg;crg.CreateRectRgn(0,0,200,18);
cd=GetDC(0);
GetLocalTime(&st);
cs.Format("Date :%d-%d-%d Time:%d:%d:%d",st.wDay,st.wMonth,st.wYear,
st.wHour,st.wMinute,st.wSecond);
cd->FillRect(g,&cb);
cd->SetBkMode(TRANSPARENT);
SetWindowRgn(crg,1);
cd->SetBoundsRect(g,1);
cd->SetTextColor(RGB(0,0,250));
cd->TextOut(0,0,cs,cs.GetLength());
ReleaseDC(cd);
}
COleControl::OnTimer(nIDEvent);
}
Step 7: Make the Changes in Resource and then Compile and Run
Step 8: In Deug/ Release Folder you might get prjname.ocx
In VB:
Step1 : Create a New project as Simple Application
Step2 : Right Click the Component tab click Components
Step3 : Goto the Components and Browsae the OCX as you Created previously.
Step 4: Apply and OK
Step5 : Drag and Drop the Component into your form
Step6: it woks !
History
Keep a running update of any changes or improvements you've made here.