Scrolling ActiveX control

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!


Who is Participating?
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.
MattWMAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.