• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

捕捉屏幕的时候包含鼠标

c++ 搞代码 3年前 (2018-08-07) 104次浏览 已收录 0个评论

默认情况下屏幕捕捉下来的内容不包含鼠标的,但是可以把鼠标画到捉下来的图像里面

LPBITMAPINFOHEADER captureScreenFrame(int left,int top,int width, int height,int tempDisableRect)
{
#ifndef _DIRECTX_captureScreenFrame
HDC hScreenDC = ::GetDC(NULL);
#else
theApp.DirectXInit();
#endif

http://www.gaodaima.com/?p=65476捕捉屏幕的时候包含鼠标

//if flashing rect
if (flashingRect && !tempDisableRect) {

  if (autopan) {    
      
   pFrame->SetUpRegion(left,top,width,height,1);    
   DrawFlashingRect( TRUE , 1);   

  }
  else  
   DrawFlashingRect( TRUE , 0);

}

#ifndef _DIRECTX_captureScreenFrame
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);     
HBITMAP hbm;

    hbm = CreateCompatibleBitmap(hScreenDC, width, height);
HBITMAP oldbm = (HBITMAP) SelectObject(hMemDC, hbm);  
BitBlt(hMemDC, 0, 0, width, height, hScreenDC, left, top, SRCCOPY);   
#else
theApp.DirectXCapture(left, top,width, height);
HDC hMemDC = NULL;
theApp.DirectXGetDC(hMemDC);
#endif

//Get Cursor Pos
POINT xPoint;
GetCursorPos( &xPoint );
HCURSOR hcur= FetchCursorHandle();
xPoint.x-=left;
xPoint.y-=top;

//Draw the HighLight
if (g_highlightcursor==1) {

  POINT highlightPoint;   

  highlightPoint.x = xPoint.x -64 ;
  highlightPoint.y = xPoint.y -64 ;  
  
  InsertHighLight( hMemDC, highlightPoint.x, highlightPoint.y);

}

//Draw the Cursor
if (g_recordcursor==1) {

  
  ICONINFO iconinfo ;
  BOOL ret;
  ret = GetIconInfo( hcur,  &iconinfo );
  if (ret) {

   xPoint.x -= iconinfo.xHotspot;
   xPoint.y -= iconinfo.yHotspot;

   //need to delete the hbmMask and hbmColor bitmaps
   //otherwise the program will crash after a while after running out of resource
   if (iconinfo.hbmMask) DeleteObject(iconinfo.hbmMask);
   if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);

  }  
  
  
  ::DrawIcon( hMemDC,  xPoint.x,  xPoint.y, hcur);        

}
//CString strText=COleDateTime::GetCurrentTime().Format();
//CRect rc(0,0,640,480);
    //DrawText(hMemDC,strText,-1,&rc,DT_LEFT);
#ifndef _DIRECTX_captureScreenFrame  
SelectObject(hMemDC,oldbm);     
LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, bits));
//LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, 24));
#else
theApp.DirectXReleaseDC(hMemDC);
LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(theApp.DirectXGetCaptureBitmap(bits));
#endif
if (pBM_HEADER == NULL) {
   
  //MessageBox(NULL,"Error reading a frame!","Error",MB_OK | MB_ICONEXCLAMATION);     
  AfxMessageBox(IDS_CAPTURE_FAIL);
  AfxPostQuitMessage(0);
  //exit(1);
}    
#ifndef _DIRECTX_captureScreenFrame  
DeleteObject(hbm);   
DeleteDC(hMemDC);
#endif
//if flashing rect
if (flashingRect && !tempDisableRect) {
  
  if (autopan) {
   DrawFlashingRect(FALSE , 1);
  }
  else
   DrawFlashingRect(FALSE , 0);

}
#ifndef _DIRECTX_captureScreenFrame  
ReleaseDC(NULL,hScreenDC) ;
#else
theApp.DirectXUninit();
#endif
return pBM_HEADER;    
}

欢迎大家阅读《捕捉屏幕的时候包含鼠标》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址