Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to add Scrolling to an ActiveX object ?

Posted on 1998-02-16
2
Medium Priority
?
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
javan earned 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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