The drawings are getting erased when the dialog is dragged or other drawing applied afterwards
I need all the drawings to stay permanently so, i can continue to draw in dialog depanding on user's response...
A working code sample is appreciated
////////////////////////////////////////////////////////
BOOL CFlickerFreeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
BITMAP bm;
CClientDC dc(this);
m_picture.topleft.x = 0;m_picture.topleft.y = 0;
m_offs.cx = 0;m_offs.cy = 0;
m_CanvasDC->CreateCompatibleDC(&dc);
m_PicDC->CreateCompatibleDC(&dc);
m_BkgBitmap->LoadBitmap(IDB_BG);
m_BkgBitmap->GetBitmap(&bm);
m_hBkg = bm.bmHeight;
m_wBkg = bm.bmWidth;
m_Bitmap->LoadBitmap(IDB_PIC);
m_Bitmap->GetBitmap(&bm);
m_picture.height = bm.bmHeight;
m_picture.width = bm.bmWidth;
return TRUE; // return TRUE unless you set the focus to a control
}
void CFlickerFreeDlg::OnPaint()
{
CPaintDC dc(this);
OnDraw(&dc);
}
HCURSOR CFlickerFreeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFlickerFreeDlg::OnDestroy()
{
delete m_CanvasBitmap;
delete m_Bitmap;
delete m_BkgBitmap;
delete m_CanvasDC;
delete m_PicDC;
}
void CFlickerFreeDlg::OnDraw(CDC* pDC)
{
CBitmap* pOldBmp1;
CBitmap* pOldBmp2;
CRect cr;
//selects canvas
pOldBmp1 = m_CanvasDC->SelectObject(m_CanvasBitmap);
//selects background, blits into canvas
pOldBmp2 = m_PicDC->SelectObject(m_BkgBitmap);
m_CanvasDC->BitBlt(0, 0, m_wBkg, m_hBkg, m_PicDC, 0, 0, SRCCOPY);
//selects small pic, blits into canvas
m_PicDC->SelectObject(m_Bitmap);
m_CanvasDC->BitBlt(m_picture.topleft.x,
m_picture.topleft.y,
m_picture.width,
m_picture.height,
m_PicDC,
0, 0, SRCCOPY);
//blits canvas on screen.Well only part of it - the "dirty rectangle" part.
pDC->GetClipBox(cr);
pDC->BitBlt(cr.left, cr.top, cr.right, cr.bottom, m_CanvasDC, cr.left, cr.top, SRCCOPY);
//deselects all the bitmaps
m_CanvasDC->SelectObject(pOldBmp1);
m_PicDC->SelectObject(pOldBmp2);
}
void CFlickerFreeDlg::OnSize(UINT nType, int cx, int cy)
{
ASSERT(!(m_CanvasBitmap == NULL));
delete m_CanvasBitmap;
m_CanvasBitmap = new CBitmap;
CClientDC dc(this);
m_CanvasBitmap->CreateCompatibleBitmap(&dc, cx, cy);
CDialog::OnSize(nType, cx, cy);
}
BOOL CFlickerFreeDlg::OnEraseBkgnd(CDC* pDC)
{
return false;
}
CRect CFlickerFreeDlg::CalcDirtyRect(int pic_w, int pic_h, CPoint p1, CPoint p2)
{
CSize PicSize(pic_w,pic_h);
CRect r1(p1,PicSize);
CRect r2(p2,PicSize);
return r1 | r2;
}
void CFlickerFreeDlg::Animate(int count)
{
bAnimate = TRUE;
for (int i = 0; i < 40; i ++)
{
CRect DirtyRc;
DirtyRc.left = 0 + i*5;
DirtyRc.right = DirtyRc.left + m_picture.width;
DirtyRc.top = 0 + i*5;
DirtyRc.bottom = DirtyRc.top + m_picture.height;
// m_picture.topleft = point - m_offs;
m_picture.topleft.x = i*5;
m_picture.topleft.y = i*5;
if(i > (40 - count))
{
InvalidateRect(DirtyRc,1);
}else if( i <= (40 - count) )
{
InvalidateRect(NULL,1);
}
UpdateWindow();
Sleep(10);
}
bAnimate = FALSE;
}
void CFlickerFreeDlg::OnButton1()
{
Animate(9);
}
/////////////////////////////////////////////////////////