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::OnInit Dialog();
BITMAP bm;
CClientDC dc(this);
m_picture.tople ft.x = 0;m_picture.top left.y = 0;
m_offs.cx = 0;m_offs.cy = 0;
m_CanvasDC->CreateCompatib leDC(&dc);
m_PicDC->CreateCompatib leDC(&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.heigh t = 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 ::OnQueryDragIc on()
{
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_pictu re.topleft.x,
m_picture.tople ft.y,
m_picture.width ,
m_picture.heigh t,
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(p OldBmp1);
m_PicDC->SelectObject(p OldBmp2);
}
void CFlickerFreeDlg ::OnSize(UINT nType, int cx, int cy)
{
ASSERT(!(m_Canv asBitmap == NULL));
delete m_CanvasBitmap;
m_CanvasBitmap = new CBitmap;
CClientDC dc(this);
m_CanvasBitmap->CreateCompatib leBitmap(&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,p ic_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.heigh t;
// m_picture.tople ft = point - m_offs;
m_picture.tople ft.x = i*5;
m_picture.tople ft.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);
}
/////////////////////////////////////////////////////////
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::OnInit Dialog();
BITMAP bm;
CClientDC dc(this);
m_picture.tople ft.x = 0;m_picture.top left.y = 0;
m_offs.cx = 0;m_offs.cy = 0;
m_CanvasDC->CreateCompatib leDC(&dc);
m_PicDC->CreateCompatib leDC(&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.heigh t = 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 ::OnQueryDragIc on()
{
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_pictu re.topleft.x,
m_picture.tople ft.y,
m_picture.width ,
m_picture.heigh t,
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(p OldBmp1);
m_PicDC->SelectObject(p OldBmp2);
}
void CFlickerFreeDlg ::OnSize(UINT nType, int cx, int cy)
{
ASSERT(!(m_Canv asBitmap == NULL));
delete m_CanvasBitmap;
m_CanvasBitmap = new CBitmap;
CClientDC dc(this);
m_CanvasBitmap->CreateCompatib leBitmap(&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,p ic_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.heigh t;
// m_picture.tople ft = point - m_offs;
m_picture.tople ft.x = i*5;
m_picture.tople ft.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);
}
/////////////////////////////////////////////////////////