Click here to Skip to main content
12,955,891 members (66,047 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 25 Jan 2004

Tabbed ActiveX control

, 25 Jan 2004
Rate this:
Please Sign up or sign in to vote.
A simple MFC ActiveX control with tabs.

Sample Image - tabbedatx.gif


This article is about creating a simple tabbed ActiveX control. The function of the control is very simple, it adds two numbers and displays their results in another tab.

We'll create an MFC ActiveX control with the following functions exposed.

  • void SetFirstNumber(LONG Num1)
  • void SetSecondNumber(LONG Num2)
  • void AddAndShow()

You will find the things very simple if you have worked in MFC. The user interface is simply a CPropertySheet containing two CPropertyPages. So, let us start following the steps below.

  1. First of all, create a new MFC ActiveX control project. Give it the name "SimpleAdditionAtx". Click the control settings tab and select "STATIC" in the combo under the text "Create control based on" and click finish. The wizard has created the following classes: CSimpleAdditionAtxApp, CSimpleAdditionAtxCtrl and CSimpleAdditionAtxPropPage.
  2. Next, switch to the resource view and add two dialog resources, one will be used for input and the other will be used for displaying the output. Add required controls in them. For the current situation, we need two edit boxes and one button for the input page, as you can see in the screenshot of our control. You can add as many Pages as you want depending upon your requirements.
  3. Now, create the classes for the two dialogs by right clicking on the dialogs one by one and selecting "Add class". Set proper names for the classes. I chose CInputPage and CResulsPage. And select CPropertyPage as the base class for both dialogs, then click Finish.
  4. Next, create the following members in CSimpleAdditionAtxCtrl class.
    • CPropertySheet* m_pSheet;
    • CInputPage m_InputPage;
    • CResultsPage m_ResultsPage;
  5. Now, select the class CSimpleAdditionAtxCtrl and select properties.. select the "Messages" button in the properties and add a method for WM_CREATE message. The wizard will add the OnCreate method in the class.
  6. Now, we add the following code in the OnCreate method:
    /*This Creates a new property Sheet on the 
    heap which will hold the the PropertyPages*/  
    m_pSheet=new CPropertySheet("hello");
    /*Adds the PropertyPage to the PropertySheet*/
    /* Creates PropertySheet structure in memory
     as a child window of our control*/

    The above code will first create an object of Property Sheet, add pages to it and then actually create the CPropertySheet structure in memory and after that adjusts the position of the CPropertySheet to the top left corner of our control. And finally, it shows it.

  7. Since we have created the CPropertySheet on heap, we've to deallocate the memory also. So, we also have to handle the WM_DESTROY message by adding a method corresponding to it, just like we did it in Step 5. Add the following code in the OnDestroy method:
      delete m_pSheet;
  8. Now, add event handler for the button we created on the input page dialog in step 2. And also add value member variables for the two edit boxes. And we add the following code in the handler of the button:
    LONG result=m_FirstNumber+ m_SecondNumber;
    CPropertySheet* pParentSheet=(CPropertySheet*)GetParent();
    CResultsPage* pPage=(CResultsPage*)pParentSheet->GetPage(1);

    m_FirstNumber and m_SecondNumber are the member variables for the two edit controls. DisplayResult is a method you need to add in the CResultPage to display results.....

  9. Now, we are ready to expose methods. For this, switch to class view and expand the node SimpleAdditionAtxLib. Now, you will see two more nodes:
    • _DSimpleAdditionAtx and
    • _DSimpleAdditionAtxEvents

    The first one is where we'll add our methods, the second is for adding the events. We'll simply add methods by right clicking on the first node and selecting "Add method". Now, we add the following methods one by one:

    • void SetFirstNumber(LONG Num1)
    • void SetSecondNumber(LONG Num2)
    • void AddAndShow()
  10. Now, we need to provide implementation for these methods. The wizard will have already created default implementation in the class CSimpleAdditionAtxCtrl. Our implementation of these methods is simple.
    void CSimpleAdditionAtxCtrl::SetFirstNumber(LONG Num1) {
        CEdit* pEdit1=(CEdit*)m_InputPage.GetDlgItem(IDC_EDIT1);
        char buff[10]; wsprintf(buff,"%d",Num1);
    void CSimpleAdditionAtxCtrl::AddAndShow(void) {
  11. Now, our control is ready for build. Then test in the ActiveX control test container. For this, go to Tools-> ActiveX control test container.


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

Muhammad Ahmed
Software Developer (Senior) ITRS Group plc, London, UK
Pakistan Pakistan
I have done masters in networks and e-business centred computing from The University of Reading, UK, Carlos III de Madrid, Spain and Aristotle University of Thessaloniki. Presently working in a London based software company as a senior software engineer. I like programming in C++, Java and C#, besides software development I spend my spare time in photography and music.

find me on facebook here!/profile.php?id=764610012

You may also be interested in...


Comments and Discussions

GeneralWorking only with ActiveX Control Test Container and not with your own clients Pin
Habeeballah Hasnoddin6-Feb-10 6:04
memberHabeeballah Hasnoddin6-Feb-10 6:04 
GeneralCreating an ActiveX control that has a menu Pin
Vemduc11-Sep-06 8:41
memberVemduc11-Sep-06 8:41 
Generalexcellent Pin
liuxine10-Apr-06 20:12
memberliuxine10-Apr-06 20:12 
GeneralAhmed...please help me with my problem Pin
ashvarma198228-Mar-05 0:55
memberashvarma198228-Mar-05 0:55 
GeneralNeed help Pin
IrishaS24-Mar-05 23:14
memberIrishaS24-Mar-05 23:14 
GeneralRe: Need help Pin
Subash.k11-Jun-08 5:56
memberSubash.k11-Jun-08 5:56 
GeneralGood work Pin
pc_dev28-Dec-04 18:24
memberpc_dev28-Dec-04 18:24 
GeneralPossible with Visual C++! Pin
Angshuman29-Jan-04 18:06
memberAngshuman29-Jan-04 18:06 
GeneralRe: Possible with Visual C++! Pin
Muhammad Ahmed29-Jan-04 19:05
memberMuhammad Ahmed29-Jan-04 19:05 
GeneralWell Done! Pin
Aisha Ikram28-Jan-04 20:31
memberAisha Ikram28-Jan-04 20:31 
GeneralRe: Well Done! Pin
Muhammad Ahmed28-Jan-04 20:43
memberMuhammad Ahmed28-Jan-04 20:43 
GeneralRe: Well Done! Pin
Aisha Ikram28-Jan-04 23:55
memberAisha Ikram28-Jan-04 23:55 
GeneralGood but... Pin
Snyp26-Jan-04 15:04
memberSnyp26-Jan-04 15:04 
GeneralRe: Good but... Pin
Muhammad Ahmed26-Jan-04 22:43
memberMuhammad Ahmed26-Jan-04 22:43 

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
Web02 | 2.8.170525.1 | Last Updated 26 Jan 2004
Article Copyright 2004 by Muhammad Ahmed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid