MFC截取桌面背景图

来源:互联网 发布:mysql三大范式 编辑:程序博客网 时间:2024/05/16 06:16
 

在OnPaint()函数里面添加如下代码:

CWnd*  wnd = GetDesktopWindow();  
  1.     CWindowDC cdc(wnd);  
  2.     int width = GetSystemMetrics(SM_CXSCREEN);  
  3.     int heigth = GetSystemMetrics(SM_CYSCREEN);  
  4.     CRect rect;  
  5.     GetClientRect(&rect);  
  6.     CDC memdc;  
  7.     memdc.CreateCompatibleDC(&cdc);  
  8.     btmp.CreateCompatibleBitmap(&cdc, width, heigth);  
  9.   
  10.     memdc.SelectObject(&btmp);  
  11.     CClientDC dc(this);  
  12.     memdc.BitBlt(0,0, rect.Width(), rect.Height(), &cdc, 0, 0, SRCCOPY);  
  13.     dc.BitBlt(0,0, rect.Width(), rect.Height(), &memdc, 0, 0, SRCCOPY);//这个之前调用  
  14.     memdc.DeleteDC();  
  15.     btmp.Detach();    
  16.       

原创粉丝点击