Solved

How to add Scrolling to an ActiveX object ?

Posted on 1998-02-16
2
328 Views
Last Modified: 2013-11-20
Hello !

Could you provide me with a sample program that uses scrolling feature in an ActiveX object client area ?

Alternatively, you could direct me as to sites that explains the use of scrolling in ActiveX objects.

Appreciate very much for your prompt answer and co-operation. Thank you.
0
Comment
Question by:pyeo
2 Comments
 

Accepted Solution

by:
javan earned 50 total points
ID: 1316270
I'm assuming that you are starting with a stock ActiveX control wizard application.  If that is the case, the following should work for you.

The scroll bar control is a gimme since this is a CWnd derived class.  In some place in your code, you will need to turn the scroll bar on.  This place will depend on your app.  You may only need the scroll bar sometimes.  It can be turned on or off. For this example, override OnCreate and place the following code there

int CScrollCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (COleControl::OnCreate(lpCreateStruct) == -1)
            return -1;
      
        //Turns the Vertical scrollbar on.
      ShowScrollBar(SB_VERT, true);
      EnableScrollBarCtrl(SB_VERT, true);
      SetScrollRange(SB_VERT, 0, m_nMaxScrollPosition);

      //The following part is not necessary but is nice.  It
        //makes it so the scroll thumb is proportionally sized
        //for the number of steps.  Few steps == bigger thumb.
      SCROLLINFO info;
      GetScrollInfo(SB_VERT, &info, SIF_PAGE);
                  
      info.fMask = SIF_PAGE;
      info.nPage = 1;
      SetScrollInfo(SB_VERT, &info);
      SetScrollPos(SB_HORZ, m_nScrollPosition);

      return 0;
}

Note the use of two variables.  I am looking at the client area as though it were several pages.  m_nScrollPosition specifies which page I am currently on.  m_nMaxScrollPosition specifies the maximum number of positions that I can have.  That is needed for initializing the scrollbar control with how many positions it can have.  Otherwise, you don't get much feedback when you click an arrow.

Next: Override WM_VSCROLL  (or HSCROLL if you doing horizontal)

void CScrollCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
  switch(nSBCode) {
    case SB_BOTTOM:                              
      break;
    case SB_TOP:
      break;
    case SB_PAGEDOWN:      //pressed in space
    case SB_LINEDOWN:      //down arrow button
                  //don't go past the bottom
      if(m_nScrollPosition <= m_nMaxScrollPosition) {
         m_nScrollPosition++;

           //update the m_nScrollPosition
         SetScrollPos(SB_VERT, m_nScrollPosition);
      }
      break;
    case SB_PAGEUP:
    case SB_LINEUP:
      if(m_nScrollPosition > 0) {
           m_nScrollPosition--;

         //update the m_nScrollPosition
         SetScrollPos(SB_VERT, m_nScrollPosition);
      }
      break;
    case SB_ENDSCROLL:      //we have completed our scrolling task
      break;
    case SB_THUMBPOSITION:      //moving the thumb
      break;
    case SB_THUMBTRACK:            //clicked on the thumb
      m_nScrollPosition = nPos;
      SetScrollPos(SB_VERT, m_nScrollPosition);
      break;
    default:                        
      break;
  }
      
  //Update the control for the new position
  InvalidateControl();
      
  COleControl::OnVScroll(nSBCode, nPos, pScrollBar);
}

Each case corresponds to user interaction with the scrollbar.  The documentation goes into more specifics on that.  I am handling the arrow and page down(clicking in space) the same way here for simplicity.  Note that each case updates the current m_nScrollPosition and then invalidates the control so it will redraw itself.

Finally, in the OnDraw code, what is displayed needs to change.
void CScrollCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
      CBrush br;

      switch(m_nScrollPosition) {
            case 0:
                  br.CreateSolidBrush(RGB(255,0,0));
                  break;
            case 1:
                  br.CreateSolidBrush(RGB(0,255,0));
                  break;
            case 2:
                  br.CreateSolidBrush(RGB(0,0,255));
                  break;
            case 3:
                  br.CreateSolidBrush(RGB(255,0,255));
                  break;
            default:
                  br.CreateSolidBrush(RGB(0,0,0));
      }
      
      pdc->FillRect(rcBounds, &br);
      pdc->Ellipse(rcBounds);
}

In this example, I am just changing the color behing the elipse based on the page I am on.  You will need to do your own app specific work to make sure the page always shows the correct stuff.

That's about it.  If you want the whole project mailed to you, please give me an address to mail it to.  
0
 

Author Comment

by:pyeo
ID: 1316271
Hi Javan,

Your answer is sufficient for me to provide scroll feature for the ActiveX object. Once again thankyou very much for your assistance.

Peter
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 78
maxBlock challenge 30 127
FizzBuzz challenge 9 80
How to convert MFC::CString to UTF8 wchar_t* 10 200
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

10 Experts available now in Live!

Get 1:1 Help Now