ScrollView is flickering on resizing

  • Thread starter Thread starter sgrm123
  • Start date Start date
S

sgrm123

Guest
Hi,

In my dialog I am displaying scrollable bitmap using scrollview. the scrollview dont have any controls.

On resizing the dialog, view is getting resized that view is flickering.

how to avoid it.

This is my scrollview derived class code

/////////////////////////////////////////////////////////////////////////////
// CImageScrollView

#include "stdafx.h"
#include "ImageScrollView.h"
#include "MetaBmpUtility\\DIBUtil.h"
IMPLEMENT_DYNCREATE(CImageScrollView, CScrollView)

CImageScrollView::CImageScrollView()
{
m_bInitialSize = FALSE;
}

CImageScrollView::~CImageScrollView()
{
}


BEGIN_MESSAGE_MAP(CImageScrollView, CScrollView)
//{{AFX_MSG_MAP(CImageScrollView)
ON_WM_MOUSEACTIVATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CImageScrollView drawing

void CImageScrollView::OnDraw(CDC* pDC)
{
// TODO: add draw code here


if(m_hImage == NULL)
return;

CDC dcMemory;
dcMemory.CreateCompatibleDC( pDC);

CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC,m_nWd,m_nHt);

CRect rectBmp;
rectBmp.SetRect(0,0,m_nWd,m_nHt);

CRect rectClient;
this->GetClientRect(&rectClient);
int nWdClient = rectClient.Width();
int nHtClient = rectClient.Height();

CBitmap * pOldBitmap = (CBitmap *)dcMemory.SelectObject(&bitmap);

CEzDIBUtilities dib;
dib.PaintDIBforBmpFileCreation(&dcMemory, &rectBmp, (HDIB)m_hImage,&rectBmp);

/*int nWd = (m_nWd > nWdClient) ? nWdClient : m_nWd;
int nHt = (m_nHt > nHtClient) ? nHtClient : m_nHt;*/

int nWd = m_nWd;
int nHt = m_nHt;
//for high quality resizing
SetStretchBltMode(pDC->GetSafeHdc(), HALFTONE );
SetBrushOrgEx(pDC->GetSafeHdc(), 0, 0, NULL );

//pDC->StretchBlt(0, 0, nWd, nHt, &dcMemory, 0, 0, m_nWd, m_nHt, SRCCOPY);
pDC->BitBlt(0, 0, nWd, nHt, &dcMemory, 0, 0, SRCCOPY);

dcMemory.SelectObject( pOldBitmap );

bitmap.DeleteObject();
dcMemory.DeleteDC();

}


/////////////////////////////////////////////////////////////////////////////
// CImageScrollView diagnostics

#ifdef _DEBUG
void CImageScrollView::AssertValid() const
{
CScrollView::AssertValid();
}

void CImageScrollView::Dump(CDumpContext& dc)
{
CScrollView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CImageScrollView message handlers

void CImageScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = m_nWd;
sizeTotal.cy = m_nHt;
SetScrollSizes(MM_TEXT, sizeTotal);
m_bInitialSize = TRUE;
}

void CImageScrollView::InitImg(HGLOBAL hImage)
{
m_hImage = hImage;

m_nWd = m_nHt = 0;
if(m_hImage != NULL)
{
CEzDIBUtilities dib;
m_nWd = dib.DibWidth((HDIB)m_hImage);
m_nHt = dib.DibHeight((HDIB)m_hImage);
}

Invalidate();
};

COLORREF CImageScrollView::GetSelectedColor()
{
POINT point;
GetCursorPos(&point);
ScreenToClient(&point);

CDC *pDC = GetDC();
return (pDC->GetPixel(point));
}

int CImageScrollView::OnMouseActivate( CWnd* /*pDesktopWnd*/,UINT /*nHitTest*/,UINT /*message*/ )
{
return MA_ACTIVATE;
}

void CImageScrollView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
//////////////////////////////////////////////////////////////////////////
// Before we can use OnPrepareDC, we must call SetScrollSize before. So,
// this flag is used to check whether we already call SetScrollSize.
if (m_bInitialSize == FALSE)
{
return;
}
//////////////////////////////////////////////////////////////////////////

// TODO: Add your message handler code here
Invalidate(0);
}

BOOL CImageScrollView::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}


BOOL CImageScrollView::PreCreateWindow(CREATESTRUCT& cs)
{

cs.style |= WS_CLIPCHILDREN;

return CView::PreCreateWindow(cs);
}

Continue reading...
 
Back
Top