{
// TODO: Add your command handler code here

HDC m_hscr;
int cx,cy;
HBITMAP m_oldbit1,m_oldbit2;
RECT m_rect;
int x,y;
// HBITMAP     m_hbit1,m_hbit2;
// HDC m_hdc1,m_hdc2; if( (m_hscr = ::CreateDC("DISPLAY",NULL,NULL,NULL)) == NULL ) //创建屏幕DC

return;
}

if( (m_hdc1 = ::CreateCompatibleDC(m_hscr) ) == NULL )       //创建兼容DC1
{
DeleteDC(m_hscr);
return;
} if( (m_hdc2 = ::CreateCompatibleDC(m_hscr)) == NULL )   //创建兼容DC2
{
DeleteDC(m_hscr);
DeleteDC(m_hdc2);
return;
} cx = ::GetDeviceCaps(m_hscr,HORZRES);                      //获取屏幕宽和高
cy = ::GetDeviceCaps(m_hscr,VERTRES); m_hbit1 = ::CreateCompatibleBitmap(m_hscr,cx,cy);          //创建兼容位图
m_hbit2 = ::CreateCompatibleBitmap(m_hscr,cx,cy); m_oldbit1 = (HBITMAP)SelectObject(m_hdc1,m_hbit1);    //选入位图
m_oldbit2 = (HBITMAP)SelectObject(m_hdc2,m_hbit2); ::BitBlt(m_hdc1,0,0,cx,cy,m_hscr,0,0,SRCCOPY);             //获取第一幅画面// Sleep(3000); ::BitBlt(m_hdc2,0,0,cx,cy,m_hscr,0,0,SRCCOPY);             //获取第二幅画面 m_rect.top = m_rect.left = m_rect.bottom = m_rect.right = -1;
BOOL fp=TRUE; DWORD ct1 = GetTickCount();                               //取得当前时间 for(x=0; x < cx; x++)
{
for(y=0; y <cy;y++)
{
if( ::GetPixel(m_hdc1,x,y) != ::GetPixel(m_hdc2,x,y) )   //比较像素
{
if( fp == TRUE)
{
m_rect.bottom = m_rect.top = y;                 //取得变化区域点获取左上点坐标
m_rect.right = m_rect.left = x;
fp = FALSE;
}
if( x < m_rect.left )                              //更新变化区域左上X坐标
m_rect.left = x;
if( x > m_rect.right )                             //更新变化区域右下X坐标
m_rect.right = x;
if( y > m_rect.bottom )                            //更新变化区域右下y坐标
m_rect.bottom = y;
}

}
} ct1 = GetTickCount() - ct1; CString str;
str.Format("Used time:%d",ct1);
MessageBox(str);


if( m_rect.top != -1 )                                       //取得变化区域图像
::BitBlt(m_hdc2,0,0,m_rect.right-m_rect.left,m_rect.bottom-m_rect.top,m_hscr,m_rect.left,m_rect.top,SRCCOPY);

else
TextOut(m_hdc2,10,20,"两位图是相同的",strlen("两位图是相同的"));


::BitBlt(GetDC()->GetSafeHdc(),0,0,cx,cy,m_hdc2,0,0,SRCCOPY);
SelectObject(m_hdc1,m_oldbit1);
SelectObject(m_hdc2,m_oldbit2); DeleteDC(m_hdc1);
DeleteDC(m_hdc2);
DeleteDC(m_hscr);
}