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_FinalCanvasDC->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;
}
void CFlickerFreeDlg::OnPaint()
{
CPaintDC dc(this);
OnDraw(&dc);
}
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.The "dirty rectangle" part only.
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)
{
for (int i = 0; i < 40; i ++)
{
bAnimate = TRUE;
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.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();
}
bAnimate = FALSE;
UpdateWindow();
Sleep(100);
}
}
void CFlickerFreeDlg::OnButton1()
{
Animate(9);
}
void CFlickerFreeDlg::OnButton2()
{
Animate(19);
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE