<b>一段屏幕抓图超简版代码</b>[VC/C++编程]
本文“<b>一段屏幕抓图超简版代码</b>[VC/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);
}
}
//---------------------------------------------------------------------------
以上是“<b>一段屏幕抓图超简版代码</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |