2016-10-10 26 views
1

私はCScrollView(CViewから継承)で画像を描画します。ビューフォームがズームインまたはズームアウトの場合は画像のスケールが再計算されます。mouseweelてC++ CScrollView、イメージをスクロールする方法は?

//*.h 
CPictureHolder pic; 

//*.cpp 
void CMyAppView::OnPaint() 
{ 
    CPaintDC dc(this); 
    CBitmap bmp; 
    BITMAP b; 
    HBITMAP hbitmap; 
    CRect rect; 
    auto bmp_iter = theApp.FullBmpMap.find(m_iCurrentImage); 

    if (bmp_iter == theApp.FullBmpMap.end()) return; 

    hbitmap = bmp_iter->second; 
    bmp.Attach((*bmp_iter).second); 
    bmp.GetObject(sizeof(BITMAP), &b); 

    GetClientRect(&rect); 
    scaleRect = rect; 
    OriginalWidth = b.bmWidth; 
    OriginalHeight = b.bmHeight; 
    if (rect.Height() <= b.bmHeight) 
     scaleRect.right = rect.left + ((b.bmWidth*rect.Height())/b.bmHeight); 
    else if (rect.Height() > b.bmHeight) 
    { 
     scaleRect.right = b.bmWidth; 
     scaleRect.bottom = b.bmHeight; 
    } 
    scaleRect.right = scaleRect.right + scale_koef_g; 
    scaleRect.bottom = scaleRect.bottom + scale_koef_v; 

    pic.CreateFromBitmap(hbitmap); 
    pic.Render(&dc, scaleRect, rect); 

    (*bmp_iter).second.Detach(); 
    (*bmp_iter).second.Attach(bmp); 
    bmp.Detach(); 

    int isclWidth = scaleRect.Width(); 
    int isclHeight = scaleRect.Height(); 
    int irHeight = rect.Height(); 
    int irWidth = rect.Width(); 

    if ((isclWidth> irWidth)||(isclHeight > irHeight)) 
    { 
     SetScrollSizes(MM_TEXT, CSize(isclWidth, isclHeight)); 
    } 
} 

ズームオプション:

BOOL CCardioAppView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{ 
    CPaintDC dc(this); 
    CRect rect, scaleRect; 

    GetClientRect(rect); 
    if (zDelta > 0)//up 
     scale_counter++; 
    else //down 
     scale_counter--; 

    if (scale_counter < 0) scale_counter = 0; 

    scale_koef_g = OriginalWidth*0.2*scale_counter; 
    scale_koef_v = OriginalHeight*0.2*scale_counter; 

    Invalidate(TRUE); 

    return CScrollView::OnMouseWheel(nFlags, zDelta, pt); 
} 

ズームとscroolsが働いているが、私は、私はこれだスクロールてるとき:

enter image description here

私のコードに追加する必要があるものは何ですか?

+2

OnDrawをオーバーライドする、のOnPaintをオーバーライドしないでくださいをしないようにしてください。 – Jonathan

+0

OnDrawは呼び出されません。 OnPaintを呼び出すためにInvalidateを使用しました。しかし、OnDrawの場合はうまくいきません。 OnDrawに電話するには? –

+0

OnDrawの署名は 'OnDraw(CDC * pDC)'ですか? – sergiol

答えて

0

CScrollView::OnMouseWheel(nFlags, zDelta, pt); 

を実行し、代わりに

return FALSE; 
+0

同じ結果 –

関連する問題