使用VC生成的缺省工程,生成了一个以CScrollView为基类的视图,并设置如下
void CScanLineView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate(); CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 40000;
SetScrollSizes( MM_TEXT, sizeTotal);
}
运行后发现,使用鼠标拖拽滚动条上的滑钮,在到达终点时,系统又自动将滑钮位置置于0位置处。
但使用滚动条上的左右上下按钮,到终点时,没有出现此问题!
请问该如何解决?

解决方案 »

  1.   

    “使用SetScrollBarInfo()新函数吧”
    在VC98和VC2005中都没有找到此函数!
    请问如何使用,给个例子吧!
      

  2.   

    “使用SetScrollBarInfo()新函数吧”
    在VC98和VC2005中都没有找到此函数!
    请问如何使用,给个例子吧!
      

  3.   

    应该是SetScrollInfo()和GetScrollInfo()Example: form MSDN
    HDC hdc; 
    PAINTSTRUCT ps; 
    TEXTMETRIC tm; 
    SCROLLINFO si; 
     
    // These variables are required to display text. 
    static int xClient;     // width of client area 
    static int yClient;     // height of client area 
    static int xClientMax;  // maximum width of client area 
     
    static int xChar;       // horizontal scrolling unit 
    static int yChar;       // vertical scrolling unit 
    static int xUpper;      // average width of uppercase letters 
     
    static int xPos;        // current horizontal scrolling position 
    static int yPos;        // current vertical scrolling position 
     
    int i;                  // loop counter 
    int x, y;               // horizontal and vertical coordinates
     
    int FirstLine;          // first line in the invalidated area 
    int LastLine;           // last line in the invalidated area 
     
    // Create an array of lines to display. 
    #define LINES 28 
    static TCHAR *abc[] = { 
           TEXT("anteater"),  TEXT("bear"),      TEXT("cougar"), 
           TEXT("dingo"),     TEXT("elephant"),  TEXT("frog"), 
           TEXT("gazelle"),   TEXT("hyena"),     TEXT("iguana"), 
           TEXT("jackal"),    TEXT("kangaroo"),  TEXT("llama"), 
           TEXT("moose"),     TEXT("newt"),      TEXT("octopus"), 
           TEXT("penguin"),   TEXT("quail"),     TEXT("rat"), 
           TEXT("squid"),     TEXT("tortoise"),  TEXT("urus"), 
           TEXT("vole"),      TEXT("walrus"),    TEXT("xylophone"), 
           TEXT("yak"),       TEXT("zebra"),
           TEXT("This line contains words, but no character. Go figure."),
           TEXT("")
         }; 
     
    switch (uMsg) 

        case WM_CREATE : 
            // Get the handle to the client area's device context. 
            hdc = GetDC (hwnd); 
     
            // Extract font dimensions from the text metrics. 
            GetTextMetrics (hdc, &tm); 
            xChar = tm.tmAveCharWidth; 
            xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * xChar/2; 
            yChar = tm.tmHeight + tm.tmExternalLeading; 
     
            // Free the device context. 
            ReleaseDC (hwnd, hdc); 
     
            // Set an arbitrary maximum width for client area. 
            // (xClientMax is the sum of the widths of 48 average 
            // lowercase letters and 12 uppercase letters.) 
            xClientMax = 48 * xChar + 12 * xUpper; 
     
            return 0; 
     
        case WM_SIZE: 
     
            // Retrieve the dimensions of the client area. 
            yClient = HIWORD (lParam); 
            xClient = LOWORD (lParam); 
     
            // Set the vertical scrolling range and page size
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_RANGE | SIF_PAGE; 
            si.nMin   = 0; 
            si.nMax   = LINES - 1; 
            si.nPage  = yClient / yChar;         SetScrollInfo(hwnd, SB_VERT, &si, TRUE); 
     
            // Set the horizontal scrolling range and page size. 
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_RANGE | SIF_PAGE; 
            si.nMin   = 0; 
            si.nMax   = 2 + xClientMax / xChar; 
            si.nPage  = xClient / xChar;         SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); 
     
            return 0;     case WM_HSCROLL:
             // Get all the vertial scroll bar information
             si.cbSize = sizeof (si);
             si.fMask  = SIF_ALL;         // Save the position for comparison later on
             GetScrollInfo (hwnd, SB_HORZ, &si);
             xPos = si.nPos;         switch (LOWORD (wParam))
             {
             // user clicked left arrow
             case SB_LINELEFT: 
                  si.nPos -= 1;
                  break;
                  
             // user clicked right arrow
             case SB_LINERIGHT: 
                  si.nPos += 1;
                  break;
                  
             // user clicked shaft left of the scroll box
             case SB_PAGELEFT:
                  si.nPos -= si.nPage;
                  break;
                  
             // user clicked shaft right of the scroll box
             case SB_PAGERIGHT:
                  si.nPos += si.nPage;
                  break;
                  
             // user dragged the scroll box
             case SB_THUMBTRACK: 
                  si.nPos = si.nTrackPos;
                  break;
                  
             default :
                  break;
             }         // Set the position and then retrieve it.  Due to adjustments
             //   by Windows it may not be the same as the value set.
             si.fMask = SIF_POS;
             SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
             GetScrollInfo (hwnd, SB_HORZ, &si);
             
             // If the position has changed, scroll the window 
             if (si.nPos != xPos)
             {
              ScrollWindow(hwnd, xChar * (xPos - si.nPos), 0, NULL, NULL);
             }
             return 0;         
        case WM_VSCROLL:
             // Get all the vertial scroll bar information
             si.cbSize = sizeof (si);
             si.fMask  = SIF_ALL;
             GetScrollInfo (hwnd, SB_VERT, &si);         // Save the position for comparison later on
             yPos = si.nPos;         switch (LOWORD (wParam))
             {
             // user clicked the HOME keyboard key
             case SB_TOP:
                  si.nPos = si.nMin;
                  break;
                  
             // user clicked the END keyboard key
             case SB_BOTTOM:
                  si.nPos = si.nMax;
                  break;
                  
             // user clicked the top arrow
             case SB_LINEUP:
                  si.nPos -= 1;
                  break;
                  
             // user clicked the bottom arrow
             case SB_LINEDOWN:
                  si.nPos += 1;
                  break;
                  
             // user clicked the shaft above the scroll box
             case SB_PAGEUP:
                  si.nPos -= si.nPage;
                  break;
                  
             // user clicked the shaft below the scroll box
             case SB_PAGEDOWN:
                  si.nPos += si.nPage;
                  break;
                  
             // user dragged the scroll box
             case SB_THUMBTRACK:
                  si.nPos = si.nTrackPos;
                  break;
                  
             default:
                  break; 
             }         // Set the position and then retrieve it.  Due to adjustments
             //   by Windows it may not be the same as the value set.
             si.fMask = SIF_POS;
             SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
             GetScrollInfo (hwnd, SB_VERT, &si);         // If the position has changed, scroll window and update it
             if (si.nPos != yPos)
             {                    
              ScrollWindow(hwnd, 0, yChar * (yPos - si.nPos), NULL, NULL);
              UpdateWindow (hwnd);
             }
             return 0;
                 case WM_PAINT :
             // Prepare the window for painting
             hdc = BeginPaint (hwnd, &ps);         // Get vertical scroll bar position
             si.cbSize = sizeof (si);
             si.fMask  = SIF_POS;
             GetScrollInfo (hwnd, SB_VERT, &si);
             yPos = si.nPos;         // Get horizontal scroll bar position
             GetScrollInfo (hwnd, SB_HORZ, &si);
             xPos = si.nPos;         // Find painting limits
             FirstLine = max (0, yPos + ps.rcPaint.top / yChar);
             LastLine = min (LINES - 1, yPos + ps.rcPaint.bottom / yChar);
             
             for (i = FirstLine; i <= LastLine; i++)
             {
                  x = xChar * (1 - xPos);
                  y = yChar * (i - yPos);
                  
                  TextOut (hdc, x, y, abc[i], lstrlen(abc[i]));
             }         // Indicate that painting is finished
             EndPaint (hwnd, &ps);
             return 0;
             
        case WM_DESTROY :
             PostQuitMessage (0);
             return 0;
        }
        return DefWindowProc (hwnd, uMsg, wParam, lParam);
    }
      

  4.   

    应该是SetScrollInfo()和GetScrollInfo()Example: form MSDN
    HDC hdc; 
    PAINTSTRUCT ps; 
    TEXTMETRIC tm; 
    SCROLLINFO si; 
     
    // These variables are required to display text. 
    static int xClient;     // width of client area 
    static int yClient;     // height of client area 
    static int xClientMax;  // maximum width of client area 
     
    static int xChar;       // horizontal scrolling unit 
    static int yChar;       // vertical scrolling unit 
    static int xUpper;      // average width of uppercase letters 
     
    static int xPos;        // current horizontal scrolling position 
    static int yPos;        // current vertical scrolling position 
     
    int i;                  // loop counter 
    int x, y;               // horizontal and vertical coordinates
     
    int FirstLine;          // first line in the invalidated area 
    int LastLine;           // last line in the invalidated area 
     
    // Create an array of lines to display. 
    #define LINES 28 
    static TCHAR *abc[] = { 
           TEXT("anteater"),  TEXT("bear"),      TEXT("cougar"), 
           TEXT("dingo"),     TEXT("elephant"),  TEXT("frog"), 
           TEXT("gazelle"),   TEXT("hyena"),     TEXT("iguana"), 
           TEXT("jackal"),    TEXT("kangaroo"),  TEXT("llama"), 
           TEXT("moose"),     TEXT("newt"),      TEXT("octopus"), 
           TEXT("penguin"),   TEXT("quail"),     TEXT("rat"), 
           TEXT("squid"),     TEXT("tortoise"),  TEXT("urus"), 
           TEXT("vole"),      TEXT("walrus"),    TEXT("xylophone"), 
           TEXT("yak"),       TEXT("zebra"),
           TEXT("This line contains words, but no character. Go figure."),
           TEXT("")
         }; 
     
    switch (uMsg) 

        case WM_CREATE : 
            // Get the handle to the client area's device context. 
            hdc = GetDC (hwnd); 
     
            // Extract font dimensions from the text metrics. 
            GetTextMetrics (hdc, &tm); 
            xChar = tm.tmAveCharWidth; 
            xUpper = (tm.tmPitchAndFamily & 1 ? 3 : 2) * xChar/2; 
            yChar = tm.tmHeight + tm.tmExternalLeading; 
     
            // Free the device context. 
            ReleaseDC (hwnd, hdc); 
     
            // Set an arbitrary maximum width for client area. 
            // (xClientMax is the sum of the widths of 48 average 
            // lowercase letters and 12 uppercase letters.) 
            xClientMax = 48 * xChar + 12 * xUpper; 
     
            return 0; 
     
        case WM_SIZE: 
     
            // Retrieve the dimensions of the client area. 
            yClient = HIWORD (lParam); 
            xClient = LOWORD (lParam); 
     
            // Set the vertical scrolling range and page size
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_RANGE | SIF_PAGE; 
            si.nMin   = 0; 
            si.nMax   = LINES - 1; 
            si.nPage  = yClient / yChar;         SetScrollInfo(hwnd, SB_VERT, &si, TRUE); 
     
            // Set the horizontal scrolling range and page size. 
            si.cbSize = sizeof(si); 
            si.fMask  = SIF_RANGE | SIF_PAGE; 
            si.nMin   = 0; 
            si.nMax   = 2 + xClientMax / xChar; 
            si.nPage  = xClient / xChar;         SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); 
     
            return 0;     case WM_HSCROLL:
             // Get all the vertial scroll bar information
             si.cbSize = sizeof (si);
             si.fMask  = SIF_ALL;         // Save the position for comparison later on
             GetScrollInfo (hwnd, SB_HORZ, &si);
             xPos = si.nPos;         switch (LOWORD (wParam))
             {
             // user clicked left arrow
             case SB_LINELEFT: 
                  si.nPos -= 1;
                  break;
                  
             // user clicked right arrow
             case SB_LINERIGHT: 
                  si.nPos += 1;
                  break;
                  
             // user clicked shaft left of the scroll box
             case SB_PAGELEFT:
                  si.nPos -= si.nPage;
                  break;
                  
             // user clicked shaft right of the scroll box
             case SB_PAGERIGHT:
                  si.nPos += si.nPage;
                  break;
                  
             // user dragged the scroll box
             case SB_THUMBTRACK: 
                  si.nPos = si.nTrackPos;
                  break;
                  
             default :
                  break;
             }         // Set the position and then retrieve it.  Due to adjustments
             //   by Windows it may not be the same as the value set.
             si.fMask = SIF_POS;
             SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
             GetScrollInfo (hwnd, SB_HORZ, &si);
             
             // If the position has changed, scroll the window 
             if (si.nPos != xPos)
             {
              ScrollWindow(hwnd, xChar * (xPos - si.nPos), 0, NULL, NULL);
             }
             return 0;         
        case WM_VSCROLL:
             // Get all the vertial scroll bar information
             si.cbSize = sizeof (si);
             si.fMask  = SIF_ALL;
             GetScrollInfo (hwnd, SB_VERT, &si);         // Save the position for comparison later on
             yPos = si.nPos;         switch (LOWORD (wParam))
             {
             // user clicked the HOME keyboard key
             case SB_TOP:
                  si.nPos = si.nMin;
                  break;
                  
             // user clicked the END keyboard key
             case SB_BOTTOM:
                  si.nPos = si.nMax;
                  break;
                  
             // user clicked the top arrow
             case SB_LINEUP:
                  si.nPos -= 1;
                  break;
                  
             // user clicked the bottom arrow
             case SB_LINEDOWN:
                  si.nPos += 1;
                  break;
                  
             // user clicked the shaft above the scroll box
             case SB_PAGEUP:
                  si.nPos -= si.nPage;
                  break;
                  
             // user clicked the shaft below the scroll box
             case SB_PAGEDOWN:
                  si.nPos += si.nPage;
                  break;
                  
             // user dragged the scroll box
             case SB_THUMBTRACK:
                  si.nPos = si.nTrackPos;
                  break;
                  
             default:
                  break; 
             }         // Set the position and then retrieve it.  Due to adjustments
             //   by Windows it may not be the same as the value set.
             si.fMask = SIF_POS;
             SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
             GetScrollInfo (hwnd, SB_VERT, &si);         // If the position has changed, scroll window and update it
             if (si.nPos != yPos)
             {                    
              ScrollWindow(hwnd, 0, yChar * (yPos - si.nPos), NULL, NULL);
              UpdateWindow (hwnd);
             }
             return 0;
                 case WM_PAINT :
             // Prepare the window for painting
             hdc = BeginPaint (hwnd, &ps);         // Get vertical scroll bar position
             si.cbSize = sizeof (si);
             si.fMask  = SIF_POS;
             GetScrollInfo (hwnd, SB_VERT, &si);
             yPos = si.nPos;         // Get horizontal scroll bar position
             GetScrollInfo (hwnd, SB_HORZ, &si);
             xPos = si.nPos;         // Find painting limits
             FirstLine = max (0, yPos + ps.rcPaint.top / yChar);
             LastLine = min (LINES - 1, yPos + ps.rcPaint.bottom / yChar);
             
             for (i = FirstLine; i <= LastLine; i++)
             {
                  x = xChar * (1 - xPos);
                  y = yChar * (i - yPos);
                  
                  TextOut (hdc, x, y, abc[i], lstrlen(abc[i]));
             }         // Indicate that painting is finished
             EndPaint (hwnd, &ps);
             return 0;
             
        case WM_DESTROY :
             PostQuitMessage (0);
             return 0;
        }
        return DefWindowProc (hwnd, uMsg, wParam, lParam);
    }
      

  5.   

    找到一个小于65536大小的方法,如下
    if( nSBCode == SB_THUMBTRACK )
    {
    if( nPos > 32767)
    {
    nPos = 65536 + (int)nPos;
    }
    }
    CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
    暂时是一个解决方法吧!