Scrolling ActiveX control

Posted on 2004-11-02
Last Modified: 2013-11-20
Hi experts

I’m relatively new to C++ and I’m taking my first tentative steps in to ActiveX. Using the App Wizard in Visual, I have created an MFC ActiveX Control called ‘TestAX’.

The only modification I have made to it, is in the ‘CTestAXCtrl’ class I have changed the default OnDraw function so that the background rectangle and ellipse are drawn twice as big as the control itself. Shown below.

void CTestAXCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
      if (!pdc)

      // TODO: Replace the following code with your own drawing code.
      pdc->FillRect(rcBounds * 2, rush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
      pdc->Ellipse(rcBounds * 2);

My question is: how difficult is it to add scroll bars to the control so that the whole ellipse can be viewed. The direct base class ‘COleControl’ has a ‘ScrollWindow()’ function but if I call this in the constructor of CTestAXCtrl I get a runtime error. Same gose for the ‘ShowScrollBar()’ in the indirect base class ‘CWnd’.

Am I barking up completely the wrong tree? Its just I can’t seem to find any simple examples of this anywhere!


Question by:MattWM
    LVL 11

    Accepted Solution

    These functions will work fine, but the confusion is in thinking the class constructor has a window.  The window is not created until long after the object is constructed, so you cannot call any window functions from the constructor.

    What you need to do is watch the Create function, which should be overriddden. When the Create function completes successfully, then the window manipulations functions will work because a window handle will have been created.

    Hope this helps.

    Author Comment

    Thanks Kurt

    Just as a quick test I used the two scroll functions in the OnDraw function and they appeared just as they should. Perhaps not an ideal place but it got me moving again.

    I’ll probable have plenty more questions as I move on. So keep a look out.

    Thanks again


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now