屏幕捕获程序.奇怪的现象,谁能解释.
对话框CGetDisplayDlg上,有一个按钮Button1.下面的代码很让人不解.看注释.当然实现下面的功能有更直接的方法.
//捕获屏幕的位图,并显示在对话框客户区上
void CGetDisplayDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//step1得到屏幕位图句柄hbmp
HDC hdcScreen,hdcMem;
HBITMAP hbmp;
hdcScreen=CreateDC("DISPLAY",NULL,NULL,NULL);
hdcMem=::CreateCompatibleDC(hdcScreen);
int cx,cy;
cx=::GetSystemMetrics(SM_CXSCREEN);
cy=::GetSystemMetrics(SM_CYSCREEN);
hbmp=::CreateCompatibleBitmap(hdcScreen,cx,cy);
//位图句柄hbmp已经得到了.要下面的两条语句有什么用???
SelectObject(hdcMem,hbmp); //不能少
BitBlt(hdcMem,0,0,cx,cy,hdcScreen,0,0,SRCCOPY); //这条语句也不能少
//下面两条语句不能移到common处,画完了一起删除hdcScreen,hdcMem不一样吗?
DeleteDC(hdcScreen);
DeleteDC(hdcMem);
//step2在对话框客户区显示位图
HDC hdc,hdcMem1;
hdc=::GetDC(m_hWnd);
hdcMem1=::CreateCompatibleDC(hdc);
SelectObject(hdcMem1,hbmp);
CRect rect;
GetClientRect(&rect);
BitBlt(hdc,0,0,rect.right,rect.bottom,hdcMem1,0,0,SRCCOPY);
DeleteObject(hbmp);
DeleteDC(hdcMem1);
::ReleaseDC(m_hWnd,hdc);
//common
}