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)
{
// 本文转自 C++Builder 研究 -
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);
}
}
//---------------------------------------------------------------------------
阅读(1200) | 评论(0) | 转发(0) |