我的滚动窗口大于3万像素的时候,当把滚动条移动到3万像素以后的位置,图像回到了0像素的地方。也就是3万多像素以后的东西显示不出来。
这个应该是和MFC中的使用原来16bit的滚动处理函数有关。
 希望高人给个解答

解决方案 »

  1.   

    You can use SetScrollRange to hide the scroll bar by setting nMinPos and nMaxPos to the same value. An application should not call the SetScrollRange function to hide a scroll bar while processing a scroll bar message. New applications should use the ShowScrollBar function to hide the scroll bar. If the call to SetScrollRange immediately follows a call to the SetScrollPos function, the bRedraw parameter in SetScrollPos must be zero to prevent the scroll bar from being drawn twice. The default range for a standard scroll bar is 0 through 100. The default range for a scroll bar control is empty (both the nMinPos and nMaxPos parameter values are zero). The difference between the values specified by the nMinPos and nMaxPos parameters must not be greater than the value of MAXLONG. Because the messages that indicate scroll bar position, WM_HSCROLL and WM_VSCROLL, are limited to 16 bits of position data, applications that rely solely on those messages for position data have a practical maximum value of 65,535 for the SetScrollRange function's nMaxPos parameter. However, because the SetScrollInfo, SetScrollPos, SetScrollRange, GetScrollInfo, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollInfo for a description of the technique. If the nBar parameter is SB_CTL and the window specified by the hWnd parameter is not a system scroll bar control, the system sends the SBM_SETRANGE message to the window to set scroll bar information. This allows SetScrollRange to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_SETRANGE message, the SetScrollRange function fails.
      

  2.   

    The GetScrollInfo function enables applications to use 32-bit scroll positions. Although the messages that indicate scroll-bar position, WM_HSCROLL and WM_VSCROLL, provide only 16 bits of position data, the functions SetScrollInfo and GetScrollInfo provide 32 bits of scroll-bar position data. Thus, an application can call GetScrollInfo while processing either the WM_HSCROLL or WM_VSCROLL messages to obtain 32-bit scroll-bar position data. To get the 32-bit position of the scroll box (thumb) during a SB_THUMBTRACK request code in a WM_HSCROLL or WM_VSCROLL message, call GetScrollInfo with the SIF_TRACKPOS value in the fMask member of the SCROLLINFO structure. The function returns the tracking position of the scroll box in the nTrackPos member of the SCROLLINFO structure. This allows you to get the position of the scroll box as the user moves it. The following sample code illustrates the technique.Hide ExampleSCROLLINFO si;
    case WM_HSCROLL:
        switch(LOWORD(wparam)) {
            case SB_THUMBTRACK:
              // Initialize SCROLLINFO structure
     
                ZeroMemory(&si, sizeof(si));
                si.cbSize = sizeof(si);
                si.fMask = SIF_TRACKPOS;
     
              // Call GetScrollInfo to get current tracking 
              //    position in si.nTrackPos
     
                if (!GetScrollInfo(hwnd, SB_HORZ, &si) )
                    return 1; // GetScrollInfo failed
                break;
            .
            .
            .
        }If the fnBar parameter is SB_CTL and the window specified by the hwnd parameter is not a system scroll bar control, the system sends the SBM_GETSCROLLINFO message to the window to obtain scroll bar information. This allows GetScrollInfo to operate on a custom control that mimics a scroll bar. If the window does not handle the SBM_GETSCROLLINFO message, the GetScrollInfo function fails. 
      

  3.   

    谢谢 您的解答。
    我的程序是用的MFC。
    如果我用32位的滚动窗口,是否意味着我不能再使用MFC给我提供的那套滚动处理机制。
    要我自己来响应滚动信息,作出处理。
      

  4.   

    这个问题其实很好处理
    把CScrollView里面的OnScroll函数重载一下就可以了
    假如你的类是CMyView
    那么重载OnScroll
    把下面的代码复制进去
    然后把GetScrollPos改成GetScrollInfo就可以了BOOL CScrollView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
    {
    // calc new x position
    int x = GetScrollPos(SB_HORZ);
    int xOrig = x; switch (LOBYTE(nScrollCode))
    {
    case SB_TOP:
    x = 0;
    break;
    case SB_BOTTOM:
    x = INT_MAX;
    break;
    case SB_LINEUP:
    x -= m_lineDev.cx;
    break;
    case SB_LINEDOWN:
    x += m_lineDev.cx;
    break;
    case SB_PAGEUP:
    x -= m_pageDev.cx;
    break;
    case SB_PAGEDOWN:
    x += m_pageDev.cx;
    break;
    case SB_THUMBTRACK:
    x = nPos;
    break;
    } // calc new y position
    int y = GetScrollPos(SB_VERT);
    int yOrig = y; switch (HIBYTE(nScrollCode))
    {
    case SB_TOP:
    y = 0;
    break;
    case SB_BOTTOM:
    y = INT_MAX;
    break;
    case SB_LINEUP:
    y -= m_lineDev.cy;
    break;
    case SB_LINEDOWN:
    y += m_lineDev.cy;
    break;
    case SB_PAGEUP:
    y -= m_pageDev.cy;
    break;
    case SB_PAGEDOWN:
    y += m_pageDev.cy;
    break;
    case SB_THUMBTRACK:
    y = nPos;
    break;
    } BOOL bResult = OnScrollBy(CSize(x - xOrig, y - yOrig), bDoScroll);
    if (bResult && bDoScroll)
    UpdateWindow(); return bResult;
    }
      

  5.   

    如:broccoli(草色入帘青)所说 修改以后 如果是用左右的箭头移动的话是可以了。
    但是 用滑块移动窗口还是 有原来的情况。
    是不是有别的消息函数没有重载。
    我重载的是水平scroll  OnHScroll
      

  6.   

    问题解决了,下面是我解决的方法。
    OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)中的nPos参数,在滑块拖动的时候传回滑块的位置,这个参数传回的是16bit数值。所以在这里需要用GetScrollInfo中获得的
    scroll.nTrackPos来替换。整个原代码如下: SCROLLINFO scroll;
    GetScrollInfo(SB_HORZ,&scroll);
    int x = scroll.nPos;
    nPos = scroll.nTrackPos;
    //int x=120;
    int xOrig = x; switch (nSBCode)
    {
    case SB_TOP:
    x = 0;
    break;
    case SB_BOTTOM:
    x = INT_MAX;
    break;
    case SB_LINEUP:
    x -= m_lineDev.cx;
    break;
    case SB_LINEDOWN:
    x += m_lineDev.cx;
    break;
    case SB_PAGEUP:
    x -= m_pageDev.cx;
    break;
    case SB_PAGEDOWN:
    x += m_pageDev.cx;
    break;
    case SB_THUMBTRACK:
    x = nPos;
    break;
    }
    BOOL bResult = OnScrollBy(CSize(x-xOrig, 0));
    // if (bResult )
    UpdateWindow();