Click here to Skip to main content
15,889,281 members
Articles / Desktop Programming / ATL
Article

Date and Time Activex Control (Written VC++ ) for VB Applications

Rate me:
Please Sign up or sign in to vote.
1.50/5 (7 votes)
16 May 2007CPOL1 min read 36.6K   839   17   2
Date and Time Activex Control for VB Applications

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHi! Pin
yafan17-May-07 18:43
yafan17-May-07 18:43 
GeneralRe: Hi! [modified] Pin
RAJKUMARV17-May-07 19:39
RAJKUMARV17-May-07 19:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.