程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> 一段屏幕抓圖超簡版代碼

一段屏幕抓圖超簡版代碼

編輯:關於C++

//---------------------------------------------------------------------------
bool __fastcall TMainForm::GetScreen(Graphics::TBitmap * mybmp, bool DrawCur)
{
   int curx,cury;
   HDC dc;
   TCanvas * mycan;
   TRect r;
   TPoint drawpos;
   TIcon * mycursor;
   HWND hld;
   DWORD threadid;
   TPoint mp;
   TIconInfo *pIconinfo;
//  mybmp=new Graphics::TBitmap();
   mycan=new TCanvas();
   dc=GetWindowDC(0);
   try
   {
     mycan->Handle=dc;
     r=Rect(0,0,Screen->Width,Screen->Height);
     mybmp->Width=r.Right;
     mybmp->Height=r.Bottom;
     mybmp->Canvas->CopyRect(r,mycan,r);
   }
   catch(...)
   {
     ReleaseDC(0,dc);
     return false;
   }
   ReleaseDC(0,dc);
   mycan->Handle=0;
   delete mycan;
   return true;
}
void __fastcall TMainForm::StartBtnClick(TObject *Sender)
{
   if(!connected)
   {
     SSocket->Port=PortEdit->Text.ToIntDef(8887);
     SSocket->Active=true;
     connected=true;
     StartBtn->Caption="停止";
   }
   else
   {
     SSocket->Active=false;
     connected=false;
     StartBtn->Caption="啟動";
   }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExitBtnClick(TObject *Sender)
{
   if(connect)
     SSocket->Active=false;
   Close();  
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SSocketClientRead(TObject *Sender,
    TCustomWinSocket *Socket)
{
   AnsiString s,s1;
   Graphics::TBitmap * mybmp;
//  TJPEGImage *jp = new TJPEGImage();
   TJPEGImage * myjpg;
   s=Socket->ReceiveText();
   if(s=="cap")
   {
     try{
       MyStream=new TMemoryStream();
       mybmp=new Graphics::TBitmap();
       myjpg=new TJPEGImage();
       GetScreen(mybmp,false);
       myjpg->Assign(mybmp);
       myjpg->CompressionQuality=QualityEdit->Text.ToIntDef(10);
       myjpg->SaveToStream(MyStream);
       myjpg->SaveToFile("c:\\123.jpg");
     }
     __finally
     {
       delete myjpg;
       delete mybmp;
     }
     MyStream->Position=0;
     s1=IntToStr(MyStream->Size);
     Socket->SendText(s1);
   }
   if(s=="ready")
   {
     MyStream->Position=0;
     Socket->SendStream(MyStream);
   }
}
//---------------------------------------------------------------------------

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