Solved

How to add Scrolling to an ActiveX object ?

Posted on 1998-02-16
2
322 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

18 Experts available now in Live!

Get 1:1 Help Now