VC 中位图的显示

来源:互联网 发布:软件测试过程管理 pdf 编辑:程序博客网 时间:2024/05/22 12:26

RECT   rect;     GetClientRect(hwnd,&rect);  
  HDC   hdcmem,hdc;  
            HBITMAP   hbitmap,hbitmapOld;  
   
  hdc=GetDC(hwnd);    
  hdcmem=CreateCompatibleDC(hdc);  
  hbitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BACKGROUND));  
          //GetObject(MAKEINTRESOURCE(IDB_BACKGROUND),sizeof(HBITMAP),hbitmap);  
          hbitmapOld=(HBITMAP)SelectObject(hdcmem,hbitmap);  
         
        //StretchBlt(hdc,0,0,500,500,hdcmem,0,0,470,420,SRCCOPY);  
    BitBlt(hdc,button[num].rect.left,button[num].rect.top,  
  75,50,hdcmem,button[num].rect.left,button[num].rect.top,SRCCOPY);  
  DeleteObject(hbitmap);  
  DeleteDC(hdcmem);  
  ReleaseDC(hwnd,hdc);  
          DeleteDC(hdc);
////////////////////////////////////////////////////////////////////////////////////////
void CCaptureDlg::SaveBmp()
{
 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);
 BITMAP btm;
 bm.GetBitmap(&btm);
 DWORD size=btm.bmWidthBytes*btm.bmHeight;
 LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,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);
// bm.GetBitmapBits(size,lpData); //エヒコッハヤレエヲタ・-5-5ト」ハスオト16ホサノォマツサ盖ヨムユノォサ・メ
//////////////////////////////
 static int filecount=0;
 CString name;
 name.Format("pict%04d.bmp",filecount++);
 name=m_Path+name;
 BITMAPFILEHEADER bfh;
 bfh.bfReserved1=bfh.bfReserved2=0;
 bfh.bfType=((WORD)('M'<< 8)|'B');
 bfh.bfSize=54+size;
 bfh.bfOffBits=54;
 CFile bf;
 if(bf.Open(name,CFile::modeCreate|CFile::modeWrite)){
  bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
  bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
  bf.WriteHuge(lpData,size);
  bf.Close();
  nCount++;
 }
 GlobalFreePtr(lpData);
 if(nCount==1)
  m_Number.Format("%d picture captured.",nCount);
 else
  m_Number.Format("%d pictures captured.",nCount);
 UpdateData(FALSE);
}

原创粉丝点击