程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 屏幕截圖並保存

屏幕截圖並保存

編輯:.NET實例教程

void   SaveBmp(HBITMAP   hbmp,   LPCTSTR   sIconFileName)   
{  
  if(hbmp==NULL   ||   sIconFileName==NULL)  
  return;  
  //warning:   this   code   snippet   is   not   bullet   proof.  
  //do   error   check   by   yourself   [masterz]  
  PICTDESC   picdesc;  
  picdesc.cbSizeofstruct   =   sizeof(PICTDESC);  
  picdesc.picType   =   PICTYPE_BITMAP   ;          
  picdesc.bmp.hpal   =   NULL;  
  picdesc.bmp.hbitmap   =   hbmp;  
  IPicture*   pPicture=NULL;  
  OleCreatePictureIndirect(&picdesc,   IID_IPicture,   TRUE,(VOID**)&pPicture);  
  LPSTREAM   pStream;  
  CreateStreamOnHGlobal(NULL,TRUE,&pStream);  
  LONG   size;  
  HRESULT   hr=pPicture->SaveAsFile(pStream,TRUE,&size);  
  char   pathbuf[1024];  
  strcpy(pathbuf,sIconFileName);  
  CFile   iconfile;  
  iconfile.Open(pathbuf,   CFile::modeCreate|CFile::modeWrite);  
  LARGE_INTEGER   li;  
  li.HighPart   =0;  
  li.LowPart   =0;  
  ULARGE_INTEGER   ulnewpos;  
  pStream->Seek(   li,STREAM_SEEK_SET,&ulnewpos);  
  ULONG   uReadCount   =   1;  
  while(uReadCount>0)  
  {  
   
  pStream->Read(pathbuf,sizeof(pathbuf),&uReadCount);  
  if(uReadCount>0)  
  iconfile.Write(pathbuf,uReadCount);  
  }  
  pStream->Release();  
  iconfile.Close();   
}   
    
void   CsaveviewView::OnSavevIEw()   
{  
  CClIEntDC   dc(this);  
  CDC &

$False$

nbsp; dcmem;  
  dcmem.CreateCompatibleDC(&dc);  
  CBitmap   bmp;  
  CRect   rc;  
  GetClIEntRect(&rc);  
  bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());  
  dcmem.SelectObject(&bmp);  
  dcmem.BitBlt(0,0,rc.Width(),rc.Height(),&dc,0,0,SRCCOPY);  
  SaveBmp(bmp,"c:\\a.bmp");   
 }  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved