에서
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);
}
감사를 무효화를 호출하면()는 전체 대화 상자가 다시 칠하는 원인이된다. 그래서 ScrollWindow 호출은 낭비됩니다 : 당신은 후속 WM_PAINT에서 그것을 과도하게 작성하고 있습니다. 일반적으로 ScrollWindow를 사용하여 이미지의 보이는 부분을 스크롤 한 다음 WM_PAINT에서 이미지 스크롤에 의해 남겨진 가장자리를 페인트하면됩니다.
lpRect 매개 변수를 ScrollWindow에 제공하고 lpClipRect를 제공해야합니다. 이렇게하면 스크롤하려는 영역을 지정하고 이미지 외부에있는 경우 버튼과 같은 하위 창의 스크롤을 방지 할 수 있습니다.
lpRect, lpClipRect 매개 변수를 전달할 때 대화 상자에있는 단추와 함께 스크롤되는 이미지입니다. – user3148898
어떻게 OnPaint에서 이미지를 다시 칠해야합니까? – user3148898
자세한 내용은 필요합니다. 이미지는 어떻게 표시됩니까? (별도의 컨트롤에 있거나 대화 상자 배경에 그려지거나 OnPaint로 그렸습니다?) 이미지 위에 버튼이 있습니까? –