保存屏幕时为什么鼠标没有保存进去,该怎么处理

保存屏幕时为什么鼠标没有保存进去
我保存屏幕,生成一个位图,可是我打开看,里面没有鼠标,请问:这是为什么?怎么解决?
请看:
SetCursorPos(336,296);
Sleep(3000);
//获得整个屏幕的HDC
HDC hdc;
hdc=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
//获得屏幕的大小
int cx,cy;
cx=GetSystemMetrics(SM_CXSCREEN); //或 GetDeviceCap
cy=GetSystemMetrics(SM_CYSCREEN); //或 GetDeviceCap
//创建与窗口句柄兼容的内存设备句柄
HDC memhdc;
memhdc=CreateCompatibleDC(hdc);
  //创建与窗口句柄兼容的位图
HBITMAP hBitmap,holdBitmap;
  hBitmap=CreateCompatibleBitmap(hdc,cx,cy);

  //选入位图对象
  holdBitmap=(HBITMAP)SelectObject(memhdc,hBitmap);
//复制窗口内容到内存
  BitBlt(memhdc,0,0,cx,cy,hdc,0,0,SRCCOPY);
//将位图信息填充BITMAP结构字段
  BITMAP bitmap;
  GetObject(hBitmap,sizeof(BITMAP),&bitmap);

  DWORD size=bitmap.bmWidthBytes*bitmap.bmHeight;//整个位图的大小
  //从堆中分配指定大小的内存,并返回指向这块内存的指针,分配内存是将内存的内容初始化为全零,
HGLOBAL hMem =GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,size);
LPSTR lpData = (LPSTR)GlobalLock(hMem);

BITMAPINFOHEADER bih;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biWidth=bitmap.bmWidth;
  bih.biHeight=bitmap.bmHeight;
bih.biPlanes=1; //必须为1
bih.biBitCount=bitmap.bmBitsPixel;
bih.biCompression=0;
bih.biSizeImage=size;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
bih.biClrUsed=0;
bih.biClrImportant=0;

  GetDIBits(memhdc,hBitmap,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);

  BITMAPFILEHEADER bfh;
bfh.bfType=((WORD)('M'<< 8)|'B');
bfh.bfSize=54+size;
bfh.bfReserved1=bfh.bfReserved2=0;
bfh.bfOffBits=54;



  CFile bf;
if(bf.Open("D:\\wt.bmp",CFile::modeCreate|CFile::modeWrite))
{
bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData,size);
bf.Close();
}

  /*释放掉从堆中分配的内存,避免内存泄露*/
GlobalUnlock(hMem);
  GlobalFree(hMem);
//删除对象
//选入原来的位图对象
  hBitmap=(HBITMAP)SelectObject(memhdc,holdBitmap);
DeleteObject(hBitmap);
DeleteDC(memhdc);
DeleteDC(hdc);

------解决方案--------------------
1.
// We try to get the cursor's icon
HCURSOR CScreenRecordDlg::GetMouse(LPPOINT pt)
{// 
HCURSOR tmp=0;
CWnd *pwin=WindowFromPoint(*pt);
DWORD TidOrig=GetWindowThreadProcessId(pwin->m_hWnd,0);
DWORD Tid=GetCurrentThreadId();
if(TidOrig==Tid)
{// if same threads ;then use current
tmp=GetCursor();
}
else if(AttachThreadInput(Tid,TidOrig,TRUE))
{// if different threads; use the orignal 
tmp=GetCursor();
// we have to detach
AttachThreadInput(Tid,TidOrig,FALSE);
}
return tmp;
}
2.画的时候要:
// draw cursor
if(m_bHasMouse)// 一个标记表示要不要保存鼠标!
{
POINT pt;
GetCursorPos(&pt);//get position
HCURSOR hicon=GetMouse(&pt);
ICONINFO iconinfo;
ZeroMemory(&iconinfo,sizeof(ICONINFO));
GetIconInfo(hicon,&iconinfo);//need Hotspot
DrawIcon(hMemDC, pt.x-iconinfo.xHotspot, pt.y-iconinfo.yHotspot, hicon);
}

------解决方案--------------------
因为硬件指针的图形和主帧缓冲不在一起