记得以前玩过一个游戏,就是有一把枪,可以向桌面射击,从而毁坏桌面(当然只是效果而已)。
今天在CODEGURU上看到了一个小程序,和这个差不多,可以到达这个效果。
这个程序就在程序初始化的时候把一个对话框全屏,让它覆盖整个桌面,这个对话框是透明的,然后在这个桌面上
绘图,大概就是这么个意思。
首先用::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,
0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
将对话框设置成全屏,然后在你建立的对话框类中添加2个函数,capturedesktop(),displaydesktop(),一个是抓取桌面CDC各种信息,一个是显示要画的图片。
void CTest11Dlg::CaptureDesktop()
{
CDC *pDesktopDC = CDC::FromHandle(::GetDCEx(NULL, NULL, 0));//get desktopDC
int Maxcx = GetSystemMetrics(SM_CXSCREEN);
int Maxcy = GetSystemMetrics(SM_CYSCREEN);
m_pProcDC = new CDC;
m_pProcDC->CreateCompatibleDC(pDesktopDC);//m_pProcDC point to dc ,dc is compatible pdesktopDC
m_pBMP = new CBitmap;
m_pBMP->CreateCompatibleBitmap(pDesktopDC, Maxcx, Maxcy);//create bitmap compatible pdesktopDC
m_pProcDC->SelectObject(m_pBMP);
m_pProcDC->BitBlt(0, 0, Maxcx, Maxcy, pDesktopDC, 0, 0, SRCCOPY);
m_pShotDC = new CDC;
m_pShotDC->CreateCompatibleDC(pDesktopDC);
m_pShotBmp = new CBitmap;
m_pShotBmp->LoadBitmap(IDB_SHOOT);
m_pShotDC->SelectObject(m_pShotBmp);
}
void CShootDlg::DisplayDesktop()
{
int screenMaxX = GetSystemMetrics(SM_CXSCREEN);
int screenMaxY = GetSystemMetrics(SM_CYSCREEN);
// =======================================================================
// Get the dialogs DC
// =======================================================================
CDC *pDC = GetDC();
// =======================================================================
// display bmp
// =======================================================================
pDC->BitBlt (0, 0, screenMaxX, screenMaxY, m_pProcDC, 0, 0, SRCCOPY );
ReleaseDC(pDC);
}
void CTest11Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC = GetDC();
pDC->BitBlt(point.x, point.y, 48, 48, m_pShotDC, 0 , 0, SRCAND);
ReleaseDC(pDC);
CDialog::OnLButtonDown(nFlags, point);
源代码在http://www.codeguru.com/cpp/g-m/multimedia/desktopeffects/article.php/c4719/
今天在CODEGURU上看到了一个小程序,和这个差不多,可以到达这个效果。
这个程序就在程序初始化的时候把一个对话框全屏,让它覆盖整个桌面,这个对话框是透明的,然后在这个桌面上
绘图,大概就是这么个意思。
首先用::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,
0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), SWP_SHOWWINDOW);
将对话框设置成全屏,然后在你建立的对话框类中添加2个函数,capturedesktop(),displaydesktop(),一个是抓取桌面CDC各种信息,一个是显示要画的图片。
void CTest11Dlg::CaptureDesktop()
{
CDC *pDesktopDC = CDC::FromHandle(::GetDCEx(NULL, NULL, 0));//get desktopDC
int Maxcx = GetSystemMetrics(SM_CXSCREEN);
int Maxcy = GetSystemMetrics(SM_CYSCREEN);
m_pProcDC = new CDC;
m_pProcDC->CreateCompatibleDC(pDesktopDC);//m_pProcDC point to dc ,dc is compatible pdesktopDC
m_pBMP = new CBitmap;
m_pBMP->CreateCompatibleBitmap(pDesktopDC, Maxcx, Maxcy);//create bitmap compatible pdesktopDC
m_pProcDC->SelectObject(m_pBMP);
m_pProcDC->BitBlt(0, 0, Maxcx, Maxcy, pDesktopDC, 0, 0, SRCCOPY);
m_pShotDC = new CDC;
m_pShotDC->CreateCompatibleDC(pDesktopDC);
m_pShotBmp = new CBitmap;
m_pShotBmp->LoadBitmap(IDB_SHOOT);
m_pShotDC->SelectObject(m_pShotBmp);
}
void CShootDlg::DisplayDesktop()
{
int screenMaxX = GetSystemMetrics(SM_CXSCREEN);
int screenMaxY = GetSystemMetrics(SM_CYSCREEN);
// =======================================================================
// Get the dialogs DC
// =======================================================================
CDC *pDC = GetDC();
// =======================================================================
// display bmp
// =======================================================================
pDC->BitBlt (0, 0, screenMaxX, screenMaxY, m_pProcDC, 0, 0, SRCCOPY );
ReleaseDC(pDC);
}
void CTest11Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC = GetDC();
pDC->BitBlt(point.x, point.y, 48, 48, m_pShotDC, 0 , 0, SRCAND);
ReleaseDC(pDC);
CDialog::OnLButtonDown(nFlags, point);
源代码在http://www.codeguru.com/cpp/g-m/multimedia/desktopeffects/article.php/c4719/