2014-01-13 2 views
-1

스크롤 막대를 사용하여 이미지를 스크롤하고 싶습니다.하지만 OnHScroll 메서드에서 scrollwindow() 함수를 사용하면 이미지가 아닌 대화 상자에있는 버튼 만 스크롤합니다. bitblt 및 stretchblt 함수를 사용하여 장치 컨텍스트를 사용하여 이미지를 확대했습니다. DC 정보를 사용하여 이미지를 스크롤 할 수는 있지만 이미지를 스크롤 할 수는 없습니다. 코드 OnHScroll 기능의가로로 이미지 스크롤

은 아래와 같습니다 : 사전

답변

0

에서

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를 제공해야합니다. 이렇게하면 스크롤하려는 영역을 지정하고 이미지 외부에있는 경우 버튼과 같은 하위 창의 스크롤을 방지 할 수 있습니다.

+0

lpRect, lpClipRect 매개 변수를 전달할 때 대화 상자에있는 단추와 함께 스크롤되는 이미지입니다. – user3148898

+0

어떻게 OnPaint에서 이미지를 다시 칠해야합니까? – user3148898

+0

자세한 내용은 필요합니다. 이미지는 어떻게 표시됩니까? (별도의 컨트롤에 있거나 대화 상자 배경에 그려지거나 OnPaint로 그렸습니다?) 이미지 위에 버튼이 있습니까? –

1

마지막으로 이미지를 가로로 스크롤 할 수있는 솔루션이 있습니다. 위의 코드에서 문을 제거하십시오 ScrollWindow (-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); 
관련 문제