分类: C/C++
2008-08-04 09:33:40
void CEmployerSeverDlg::CatchScreen() { // protect类型 只用于内部函数的调用, //截获屏幕位图信息和数据信息分别放在btm和lpdata CDC dc; dc.CreateDC("DISPLAY",NULL,NULL,NULL); CBitmap bm; int Width=GetSystemMetrics(SM_CXSCREEN); int Height=GetSystemMetrics(SM_CYSCREEN); bm.CreateCompatibleBitmap(&dc,Width,Height); CDC tdc; tdc.CreateCompatibleDC(&dc); CBitmap*pOld=tdc.SelectObject(&bm); tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY); tdc.SelectObject(pOld); bm.GetBitmap(&btm); size=btm.bmWidthBytes*btm.bmHeight; lpData=new char[size]; ///////////////////////////////////////////// BITMAPINFOHEADER bih; bih.biBitCount=btm.bmBitsPixel; bih.biClrImportant=0; bih.biClrUsed=0; bih.biCompression=0; bih.biHeight=btm.bmHeight; bih.biPlanes=1; bih.biSize=sizeof(BITMAPINFOHEADER); bih.biSizeImage=size; bih.biWidth=btm.bmWidth; bih.biXPelsPerMeter=0; bih.biYPelsPerMeter=0; /////////////////////////////////// GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS); }
void CBossSeeClientView::OnGetScreen() { //通过网络获得bitmap的信息填写lpdata // TODO: Add your command handler code here if(m_pRecBMPSocket==NULL) return; if(lpData!=NULL) {delete lpData;lpData=NULL;} char MSGTYPE1[30]="B"; int BTMInfoSize=24; char BTMInfoBuf[24]; m_pRecBMPSocket->Send(MSGTYPE1,30); int ret=m_pRecBMPSocket->Receive(BTMInfoBuf,sizeof(BITMAP)); if (ret!=24) { MessageBox("failed recive 24"); return;} BITMAP *BTMBUF=(BITMAP *)BTMInfoBuf; btm.bmBits=BTMBUF->bmBits; btm.bmBitsPixel=BTMBUF->bmBitsPixel; btm.bmHeight=BTMBUF->bmHeight; btm.bmPlanes=BTMBUF->bmPlanes; btm.bmType=BTMBUF->bmType; btm.bmWidth=BTMBUF->bmWidth; btm.bmWidthBytes=BTMBUF->bmWidthBytes; char MSGTYPE2[30]="D"; m_pRecBMPSocket->Send(MSGTYPE2,30); int size=btm.bmWidthBytes*btm.bmHeight; lpData=new char[size]; if(lpData==NULL) MessageBox("faile memery"); char *pch=lpData ; int nBytesRec=0; int nBytesThisTime; do{ //发送的内容较大采用循环发送完成为止 nBytesThisTime=m_pRecBMPSocket->Receive(pch,size-nBytesRec); nBytesRec =nBytesThisTime; pch =nBytesThisTime; }while(nBytesRecUpdateAllViews(NULL,NULL,NULL);//更新视图 ///////////////////////////////////// } void CClientView::OnDraw(CDC* pDC) {//显示接收到的位图信息 CDocument* pDoc = GetDocument(); // TODO: add draw code here if(lpData==NULL) return; BITMAP myBITMAP; myBITMAP.bmBits=btm.bmBits; myBITMAP.bmBitsPixel=btm.bmBitsPixel; myBITMAP.bmHeight=btm.bmHeight; myBITMAP.bmPlanes=btm.bmPlanes; myBITMAP.bmType=btm.bmType; myBITMAP.bmWidth=btm.bmWidth; myBITMAP.bmWidthBytes=btm.bmWidthBytes; BITMAPINFOHEADER bih; bih.biBitCount=myBITMAP.bmBitsPixel; bih.biClrImportant=0; bih.biClrUsed=0; bih.biCompression=0; bih.biHeight=myBITMAP.bmHeight; bih.biPlanes=1; bih.biSize=sizeof(BITMAPINFOHEADER); bih.biSizeImage=myBITMAP.bmWidthBytes*myBITMAP.bmHeight; bih.biWidth=myBITMAP.bmWidth; bih.biXPelsPerMeter=0; bih.biYPelsPerMeter=0; ///////////////////////// CBitmap tbitmap; if(tbitmap.CreateBitmapIndirect(&myBITMAP)==NULL) MessageBox("b mull"); if(tbitmap.m_hObject==NULL)MessageBox("NULL"); // CPaintDC tdc(this); CDC tmemdc; tmemdc.CreateCompatibleDC(pDC); SetDIBits(tmemdc.m_hDC,tbitmap,0,btm.bmHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS); CRect trect; GetClientRect(&trect); CBitmap* lpOldbit=tmemdc.SelectObject(&tbitmap); pDC->StretchBlt(0,0,trect.Width(),trect.Height(), &tmemdc,0,0,myBITMAP.bmWidth, myBITMAP.bmHeight,SRCCOPY); }