1
votes

I am new in working with MFC scrollview, I am displaying the large image in a function onPaint of my ScrollView class. here is the On initial update function following code

void CCenterImageView::OnInitialUpdate()
{
    CScrollView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class

    CSize sizeTotal;
    // TODO: calculate the total size of this view
    sizeTotal.cx = m_matImage.cols;
    sizeTotal.cy = m_matImage.rows;
    SetScrollSizes(MM_TEXT, sizeTotal,sizeTotal);

}

void CCenterImageView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: Add your message handler code here and/or call default

    CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);

    //Invalidate();
}

void CCenterImageView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: Add your message handler code here and/or call default

    CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
    UpdateData();
    //Invalidate();
}

void CCenterImageView::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    // Do not call CView::OnPaint() for painting messages

    if(m_CVvImageObj.GetImage())
    {       
        //this function blit the bitmap on the screen height and width are more than 1000 pixels
        m_CVvImageObj.Show(dc.GetSafeHdc(),0,0,m_CVvImageObj.Width(),m_CVvImageObj.Height());
    }


}

by using this http://www.functionx.com/visualc/views/scrollview.htm i can see the vertical and horizontal scroll but pressing them dont change anything on the view. Kindly guide me how can i move the scroll on user clicks and change the view?

2

2 Answers

1
votes

CScrollView acts as if you are painting on a large canvas, whose size you determine using SetScrollSizes. The size you set is normally the size of the entire image, most likely larger than the window in which it's displayed.

Then, when you handle OnDraw, you can either paint the entire image, as you have done, or you can paint only the part that is showing, which you can find out from GetClipBox. The latter is necessary for efficiency only, as CScrollView will clip the parts which aren't visible.

You don't need the OnXScroll handlers at all. You should remove them and let CScrollView handle the scrolling, if that's all you do in response to scroll.

There will be problems if your image dimensions are >=2^15, but that doesn't sound like your situation.

0
votes

Your code look suspicious (the 3th argument). However if it is related to the issue of scrolling above 32K, see knowledge base article 'PRB: CScrollView Scroll Range Limited to 32K' (article ID: 166473).