Click here to Skip to main content
13,140,591 members (47,776 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 7 Jun 2003

VB Events in C++

, 7 Jun 2003
Rate this:
Please Sign up or sign in to vote.
How to use events from Visual Basic ActiveX controls in C++

This article will take you through step-by-step using events from a VB ActiveX control...


Step 1: Setting up the Project

Start up Microsoft Visual C++ and start up a new MFC AppWizard(exe) project and call it vbEvents. Set the type to multiple documents. Keep clicking next until you get to step 6 of 6. In the listbox, click CVbEventsView and change the base class to CFormView, then click finished and then OK.

Step 2: Adding the ActiveX control part 1

In the menu bar, go to Project -> Add to Project -> Components and Controls. In the box click Registered ActiveX Controls and choose any control you want to add. For this example, we will use Microsoft FlexGrid Control, version 6.0. Click OK and only check the first box (we don't need the others for this example) Then click OK. Then close out of the Add components and controls window.

Step 2: Adding the ActiveX control part 2

Go to the resource view, then go to dialogs and open up IDD_VBEVENTS_FORM. Delete off the text box and add in the Microsoft Flexigrid control, resize it to the blue line in all directions. Press Ctrl-w to bring up the classwizard and go to the Member Variables tab. In the dropdown box, select CVbEventsView, click Add Variable and name it m_grid leaving everything else how it is, then click OK. You should be able to compile your project and see the ActiveX control in the window.

Step 3: Assigning an Event

Open the classwizzard, and click on the Message Maps tab. In the classname box, choose CVbEventsView, in object id, choose IDC_MSFLEXGRID1. Then in Messages, choose the event you want (in this case Click), then click OK.

In the CVbEventsView::OnClickMsflexgrid1() function, add


Then compile your code and watch the event when you click.

Step 4: Cleaning Up

At the top of vbEventsView.h and vbEventsView.h, add

#define CFormView CView

Delete from CVbEventsView.cpp, line 68.


Also you need to find this on line 35.

    : CView(CVbEventsView::IDD)

and remove

: CView(CVbEventsView::IDD)

Also, right click on CVbEventView and click add virtual function. Then click on Draw(), then add. Right click on CVbEventView and click add Windows message handler. In the list box, click CVbEventView and choose WM_CREATE, click add and edit.

In CVbEventView:OnCreate, add

RECT rect; = rect.left = 0;
rect.right=rect.bottom = 50;


Right click on CVbEventView and click add Windows message handler. In the list box, click CVbEventView and choose WM_SIZE, click add and edit. In CVbEventView:OnSize add,

m_grid.SetWindowPos(NULL,0,0,cx,cy,SWP_NOZORDER );

And there you go. This method can be modified for other Activex control or different events.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

New Zealand New Zealand
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralIt would be nice [modified] Pin
Pandele Florin3-Jul-06 5:41
memberPandele Florin3-Jul-06 5:41 
Question"VB Events in C++"??? Pin
Travis Smith27-Jul-05 10:08
memberTravis Smith27-Jul-05 10:08 
GeneralLindseyE Pin
LindseyE10-Jun-03 5:49
memberLindseyE10-Jun-03 5:49 
GeneralB-a-a-a-d Pin
Chopper8-Jun-03 22:47
memberChopper8-Jun-03 22:47 
GeneralRe: B-a-a-a-d Pin
Mikel8-Jun-03 23:28
memberMikel8-Jun-03 23:28 
GeneralRe: B-a-a-a-d Pin
Chopper8-Jun-03 23:36
memberChopper8-Jun-03 23:36 
GeneralRe: B-a-a-a-d Pin
Mikel9-Jun-03 23:33
memberMikel9-Jun-03 23:33 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 8 Jun 2003
Article Copyright 2003 by Mikel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid