Mfc 水平滚动图像

Mfc 水平滚动图像,mfc,Mfc,我想使用滚动条滚动图像,但当我在OnHScroll方法中使用scrollwindow()函数时,它只会滚动对话框中的按钮,而不会滚动图像。 我使用了bitblt和stretchblt函数来使用设备上下文放大图像。我认为通过使用dc信息我们可以滚动图像,但我不知道我该怎么做 OnHScroll函数的代码如下所示: void CImgVeiwer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pcrollBar) { // TODO: Add you

我想使用滚动条滚动图像,但当我在OnHScroll方法中使用scrollwindow()函数时,它只会滚动对话框中的按钮,而不会滚动图像。 我使用了bitblt和stretchblt函数来使用设备上下文放大图像。我认为通过使用dc信息我们可以滚动图像,但我不知道我该怎么做

OnHScroll函数的代码如下所示:

void CImgVeiwer::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pcrollBar)
{
// TODO: Add your message handler code here and/or call default
    int minpos;
   int maxpos;

   GetScrollRange(SB_HORZ, &minpos, &maxpos); 
  maxpos = GetScrollLimit(SB_HORZ);
  CurPos =  GetScrollPos(SB_HORZ);
switch (nSBCode)
{
 case SB_LEFT:      // Scroll to far left.
  CurPos = minpos;
  break;

  case SB_RIGHT:      // Scroll to far right.
  CurPos = maxpos;
  break;

   case SB_ENDSCROLL:   // End scroll. 
  break;

  case SB_LINELEFT:      // Scroll left. 
  if (CurPos > minpos)
     CurPos--;
  break;

  case SB_LINERIGHT:   // Scroll right. 
  if (CurPos < maxpos)
     CurPos++;
  break;

  case SB_PAGELEFT:    // Scroll one page left.
   {
    // Get the page size. 
    SCROLLINFO   info;
    GetScrollInfo(SB_HORZ, &info, SIF_ALL);

     if (CurPos > minpos)
      CurPos = max(minpos, CurPos - (int) info.nPage);
   }
    break;

   case SB_PAGERIGHT:      // Scroll one page right.
   {
    // Get the page size. 
     SCROLLINFO   info;
    GetScrollInfo(SB_HORZ, &info, SIF_ALL);

    if (CurPos < maxpos)
       CurPos = min(maxpos, CurPos + (int) info.nPage);
}
   break;
   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
      CurPos = nPos;      // of the scroll box at the end of the drag operation. 
      break;

   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
      CurPos = nPos;     // position that the scroll box has been dragged to. 
     break;
  }

// Set the new position of the thumb (scroll box).
m_HsrollFlag = TRUE;
SetScrollPos(SB_HORZ,CurPos);
ScrollWindow(-CurPos,0,0,0);
Invalidate();
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
void CImgVeiwer::OnHScroll(UINT nSBCode、UINT npo、CScrollBar*pcrollBar)
{
//TODO:在此处添加消息处理程序代码和/或调用默认值
int minpos;
int-maxpos;
GetScrollRange(SB_HORZ、minpos和maxpos);
maxpos=GetScrollLimit(SB_HORZ);
CurPos=GetScrollPos(SB_HORZ);
交换机(nSBCode)
{
case SB_LEFT://滚动到最左边。
CurPos=minpos;
打破
case SB_RIGHT://滚动至最右侧。
CurPos=maxpos;
打破
case SB_ENDSCROLL://结束滚动。
打破
case SB_LINELEFT://向左滚动。
如果(CurPos>minpos)
CurPos--;
打破
case SB_LINERIGHT://向右滚动。
if(CurPosminpos)
CurPos=max(minpos,CurPos-(int)info.nPage);
}
打破
case SB_PAGERIGHT://向右滚动一页。
{
//获取页面大小。
滚动信息;
GetScrollInfo(SB_HORZ和info,SIF_ALL);
if(CurPos
}

提前感谢

通过调用Invalidate()可以重新绘制整个对话框。所以ScrollWindow调用被浪费了:您在随后的WM_绘制中过度绘制了它。通常,您会使用ScrollWindow滚动图像的可见部分,然后在WM_PAINT中,您只需要绘制图像滚动留下的未覆盖边缘


您应该为ScrollWindow提供一个lpRect参数,也可以提供lpClipRect。这将指定您要滚动的区域,并且如果子窗口(如按钮)位于图像外部,也会阻止它们滚动。

最后,我找到了水平滚动图像的解决方案。 在上面给定的代码中,删除该语句 滚动窗口(-CurPos,0,0,0)

并在OnPaint()方法中添加以下语句,m_nWidth和nHeight是要滚动的图像的宽度和高度

   dc.StretchBlt(ZERO - CurPos,FIFTY ,m_nWidth +1000,
            nHeight+ 1000,
            &memDC,ZERO,ZERO,m_nWidth,
            m_nHeight,SRCCOPY);

在传递lpRect、lpClipRect参数时,它将滚动图像以及对话框中显示的按钮。我应该如何在OnPaint Mehtome中重新绘制图像需要更多详细信息。图像是如何显示的?(它是在单独的控件中,还是在对话框背景中绘制,还是在OnPaint中绘制?)。