一段屏幕抓圖超簡版代碼 |
|
axsoft
版主 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
一段屏幕抓圖超簡版代碼 資料來源: ChinaBCB.com //---------------------------------------------------------------------------
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);
}
}
//---------------------------------------------------------------------------
[code] 網路志工聯盟----Visita網站http://www.vista.org.tw
---[ 發問前請先找找舊文章 ]---
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |