Click here to Skip to main content
Licence CPOL
First Posted 16 May 2007
Views 18,783
Downloads 540
Bookmarked 16 times

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

By | 16 May 2007 | Article
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)

About the Author

RAJKUMARV

Engineer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralHi! Pinmemberyafan18:43 17 May '07  
GeneralRe: Hi! [modified] PinmemberS.V.RAJKUMAR19:39 17 May '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 17 May 2007
Article Copyright 2007 by RAJKUMARV
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid