• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

Handling page down/up keystrokes for scrollbars

Hi,

I have a CView derived class in my MDI app. I'm handling scrolling in the window like:

void CMyView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    switch (nSBCode) {
        case SB_PAGEDOWN:  
            ...
            break;

        etc...
    }
}

It looks like the vscroll handler isn't getting called when I press page down on the keyboard, do I have to do something to enable that? The page up/down works fine if I go through the scrollbar context menu.

Thanks
0
minnirok
Asked:
minnirok
  • 3
  • 2
1 Solution
 
mahesh1402Commented:
instead if SB_PAGEDOWN on your vscroll handler SB_PAGELEFT / SB_PAGERIGHT gets invoked ? try it.

Try to handle

void CMyView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    switch (nSBCode) {
        case SB_PAGERIGHT:  
            ...
            break;

        etc...
    }
}

-MAHESH
0
 
mahesh1402Commented:
if its not handling keys you may try like  :

void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
 CPoint p(GetScrollPosition());

 switch (nChar)
{
 case VK_NEXT:
  p.y += PAGE_SIZE_YOU_DEFINED;
  break;
 case VK_PRIOR:
  p.y -= PAGE_SIZE_YOU_DEFINED;
  break;
 // Other cases, analogue to this (VK_HOME, VK_END...)
 }
 ScrollToPosition(p);
 CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

-MAHESH
0
 
mahesh1402Commented:
OR Simply On handler of WM_KEYDOWN:

void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
 switch (nChar)
{
               case VK_NEXT:           // PageDown key
                SendMessage(WM_VSCROLL,SB_PAGEDOWN,...);
                break;

              case VK_PRIOR:  // PageUp kwy
                SendMessage(WM_VSCROLL,SB_PAGEUP,.....);
                break;

              // Other cases VK_HOME, VK_END...
 }

 CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

-MAHESH
0
Industry Leaders: 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!

 
AlexFMCommented:
When Page Down is pressed, view class gets WM_VSCROLL message with SN_PAGEDOWN code and null scrollbar pointer.
Is your class derived from CView or CScrollView? Is scrollbar creatwed manually in your code?
0
 
minnirokAuthor Commented:
It is derived from CView. The scrollbar is created manually, I think? I call SetScrollInfo(), SetScrollRange() myself.
0
 
AlexFMCommented:
In this case last post of mahesh1402 is what you need.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now