KeyexeDlg.cpp ( File view )

  • By chengyuqiong 2014-05-08
  • View(s):17
  • Download(s):1
  • Point(s): 1
			// KeyexeDlg.cpp : implementation file
//
//	Disclaimer
//	----------
//	THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
//	ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
//	DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
//	RISK OF USING THIS SOFTWARE.
//
//	Terms of use
//	------------
//	THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
//	IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
//	ARE GENTLY ASKED TO SEND ONE LICENCED COPY OF YOUR APPLICATION(S)
//	TO THE AUTHOR. IF YOU WANT TO PAY SOME MONEY INSTEAD, CONTACT ME BY
//	EMAIL. YOU ARE REQUESTED TO CONTACT ME BEFORE USING THIS SOFTWARE
//	IN YOUR SHAREWARE/COMMERCIAL APPLICATION.
//
//	Contact info:
//	Site: http://bizkerala.hypermart.net
//	Email: anoopt@gmx.net
//----------------------------------------------------------------------------------
//
//	Usage Instructions: See Readme.txt for Both 'Keyexe' & 'Keydll3' projects.
//
//----------------------------------------------------------------------------------
#include "stdafx.h"
#include "Keyexe.h"
#include "KeyexeDlg.h"
#include "Keydll3.h"//Include this for functions in the DLL.
//#include "..\Keydll3\Keydll3.h"//Include this for functions in the DLL.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define WM_KEYSTROKE (WM_USER + 755)//This message is recieved when key is down/up
#define WM_NC (WM_USER+1001)

#define SOCKET_PORT htons(0xE917);//7016
//#define SOCKET_PORT 59670

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

SOCKET ServerSock;
SOCKET connectSock;
struct sockaddr_in dstclient_addr;
char recv_message_server[256] = {
0
};
char      send_message[256] = {
0
};

HANDLE hThread;
DWORD ThreadID;
volatile BOOL ThreadRun = false;

const char* WINDOWNHANDLERNAME = "gjz.control.pc";
void socketMoveMouse(int direction,int step);
void analyseCommand(char *message);

//server
BOOL InItServerSock()
{

	//Variable Define
	int Status;
	WORD wMajorVersion,wMinorVersion;
	WORD wVersionReqd;
	WSADATA lpmyWSAData;
	
	//InI Winsock
	wMajorVersion = 1;
	wMinorVersion = 2;
	wVersionReqd = MAKEWORD(wMajorVersion,wMinorVersion);

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

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

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

	char name[255]; 
	PHOSTENT hostinfo; 
	if( gethostname (name, sizeof(name)) == 0) 
	{
 
		if((hostinfo = gethostbyname(name)) != NULL) 
		{
 
			CString local_IP_address; 
			local_IP_address = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); 
			u_short port = ((dstclient_addr.sin_port & 0xFF00)>>8) | ((dstclient_addr.sin_port & 0x00FF)<<8);

			CString temp;
			temp.Format("请连接这个IP地址:\n%s:%d",local_IP_address, port);
			SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, temp);
		
} 
	
}

    return TRUE;

}

BOOL waiteAccept()
{

	//ACCEPT
	int len = sizeof(dstclient_addr);
	connectSock = accept(ServerSock,(struct sockaddr far *)&dstclient_addr,&len);
	if (connectSock < 0)
	{

		closesocket(connectSock);
		return FALSE;
	
}

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

	return TRUE;

}

DWORD WINAPI threadFunc(LPVOID threadNum)
{

	int length;	
	CString temp;

	if(!InItServerSock())
		return 0;
	if(!waiteAccept())
		return 0;
	
	//等待连接的时候,连接可能被取消。
	if(ThreadRun)
	{

		//int   nPort_Client; 
		//sockaddr   *remoteSockAddr = (struct sockaddr far *)&dstclient_addr ; 
        //getpeername(connectSock, &sockaddr, &nPort_Client); 

		CString temp;
		temp.Format("%s:%d\n已经连接上!", inet_ntoa(dstclient_addr.sin_addr), dstclient_addr.sin_port);//remoteSockAddr->sa_data
		SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, temp);
	
}
	else
	{

		SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, "请启动服务!");
		return 0;
	
}

	//send(NewSock,(char*)&FALG,sizeof(FALG)+1,MSG_OOB);		
	while(ThreadRun)
	{

		//length = recv(connectSock,(char*)recv_message,sizeof(recv_message)+1,0);
		length = recv(connectSock,(char*)recv_message_server,sizeof(recv_message_server),0);
		if( length>0)
		{

			//MessageBox(0, recv_message, "接收到的信息", MB_OK);		
			temp.Format("接收到的信息:\n%s",recv_message_server);
			SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, temp);

			analyseCommand(recv_message_server);
			memset(recv_message_server, 0, sizeof(recv_message_server));
		
}
	
}

	return 0;

}

DWORD clientThreadID;
SOCKET    clientSock;
char      server_address[50] = {
0
};
char      recv_message_client[256] = {
0
};
struct    sockaddr_in server_ip;
BOOL clientThreadRun = false;
//client
BOOL InItClientSock()
{

	//Define Variable
	WORD wVersionrequested;
	WSADATA wsaData;

	wVersionrequested = MAKEWORD(2,0);
	
	//Start Sock
	int err = WSAStartup(wVersionrequested,&wsaData);
	if (err == -1)
	{

		MessageBox(0,"WSAStartup err", "error",MB_OK);
		return FALSE;
	
}
	return TRUE;

}
BOOL ConnectSock()
{

	SOCKET clientSockConnect;
	u_short port;

	//Ini Sock
	clientSock = socket(AF_INET,SOCK_STREAM,0);
	if (ServerSock < 0)
	{

			MessageBox(0,"scoker err",
				 "err",MB_OK);
			return FALSE;
	
}

	char *strPort = strstr(server_address, ":");

	if( (strPort!=NULL) && (strlen(strPort)>2) )
	{

		port = atoi(strPort+1);
		if(port==0)
		{

			MessageBox(0, "IP端口不对, 参考例子:192.168.12.134:8981", "提示", MB_OK);
			return FALSE;
		
}
		memset(strPort, 0, sizeof(strPort));
	
}
	else
	{

		MessageBox(0, "IP地址不对, 参考例子:192.168.12.134:8981", "提示", MB_OK);
		return FALSE;
	
}

	//Connect
	server_ip.sin_family = AF_INET;
	server_ip.sin_port = ((port&0xff00)>>8)|((port&0x00ff)<<8);
	server_ip.sin_addr.S_un.S_addr = inet_addr(server_address);

	clientSockConnect = connect(clientSock,(struct sockaddr*)&server_ip,sizeof(server_ip));
	if (clientSockConnect!=0)
	{

		CString temp;
		temp.Format("系统拒绝连接,可能是输入IP地址或端口不对:\n%s:%d", server_address, server_ip.sin_port);
		SetDlgItemText( FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, temp);
		MessageBox(0, "系统拒绝连接,可能是输入IP地址或端口不对 ", "提示", MB_OK);
		return FALSE;
	
}
	return TRUE;

}

DWORD WINAPI clientThreadFunc(LPVOID threadNum)
{

	int length;	
	CString temp;

	if(!InItClientSock())
		return 0;
	if(!ConnectSock())
		return 0;
	
	//等待连接的时候,连接可能被取消。
	if(clientThreadRun)
		SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, "已经连接上!");
	else
	{

		SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, "请启动服务!");
		return 0;
	
}

	//send(NewSock,(char*)&FALG,sizeof(FALG)+1,MSG_OOB);		
	while(clientThreadRun)
	{

		if( (length = recv(clientSock,(char*)recv_message_client,sizeof(recv_message_client),0))>0)
		{

			//MessageBox(0, recv_message, "接收到的信息", MB_OK);		
			temp.Format("接收到的信息:\n%s",recv_message_client);
			SetDlgItemText(FindWindow(NULL, WINDOWNHANDLERNAME), IDC_STATIC_IP, temp);

			analyseCommand(recv_message_client);
			memset(recv_message_client, 0, sizeof(recv_message_client));
		
}
		temp.Format("接收到的信息:\n%s",recv_message_client);
	
}

	return 0;

}

void mouseMove(char *message)
{

	char *strPoint = strstr(message, ";");

	if( strPoint!=NULL )
	{

		int pointY = atoi(strPoint+1);		
		memset(strPoint, 0, sizeof(strPoint));
		int pointX = atoi(message);

		POINT lpPoint ;
		GetCursorPos(&lpPoint);
		SetCursorPos(lpPoint.x + pointX, lpPoint.y + pointY);
	
}
	else
	{

		MessageBox(0, "接受到的数据有误", "提示", MB_OK);
	
}

}

void analyseCommand(char *message)
{

	char command = message[0];

	switch(command)
	{

	case '0'://取消鼠标动作
		mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		break;
	case '1'://移动鼠标
		mouseMove(message+2);
		break;
	case '2'://鼠标左键down
		mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
		break;
	case '3'://鼠标左键up
		mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		break;
	case '4':		
		break;
	case '5'://右击
		mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
		mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
		break;
	case '6'://单击
		mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
		mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
		break;
	case '7'://双击
		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);
		break;
	case '8'://向上拖动滚动
		mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 100, 0);
		break;
	case '9'://向下拖动滚动
		mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -100, 0);
		break;
	
}

}

void socketMoveMouse(int direction,int step) 
{

	// TODO: Add your control notification handler code here
	POINT lpPoint ;
	GetCursorPos(&lpPoint);
	switch(direction)
	{

		case 0:
			SetCursorPos(lpPoint.x , lpPoint.y - step);
			break;
		case 1:
			SetCursorPos(lpPoint.x + step, lpPoint.y);
			break;
		case 2:
			SetCursorPos(lpPoint.x , lpPoint.y + step);
			break;
		case 3:
			SetCursorPos(lpPoint.x - step , lpPoint.y);
			break;
		default :
			break;
	
}

}

class CAboutDlg : public CDialog
{

public:
	CAboutDlg();

// Dialog Data
	//{
{
AFX_DATA(CAboutDlg)
	enum {
 IDD = IDD_ABOUTBOX 
};
	//
}
}AFX_DATA
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.96 kB
.classpath364.00 B2011-12-26|15:52
.project845.00 B2011-12-26|15:52
AndroidManifest.xml1.05 kB2011-12-28|17:30
01.96 kB
01.96 kB
01.96 kB
classes.dex22.48 kB2011-12-30|16:41
01.96 kB
01.96 kB
ControlPCActivity$1.class2.26 kB2012-01-17|13:46
ControlPCActivity$2.class1.99 kB2012-01-17|13:46
ControlPCActivity$3.class2.00 kB2012-01-17|13:46
ControlPCActivity$4.class3.59 kB2012-01-17|13:46
ControlPCActivity$5.class1.27 kB2012-01-17|13:46
ControlPCActivity$6.class2.23 kB2012-01-17|13:46
ControlPCActivity$7.class3.15 kB2012-01-17|13:46
ControlPCActivity$8.class1.52 kB2012-01-17|13:46
ControlPCActivity.class9.50 kB2012-01-17|13:46
mouseActivity$1.class1.33 kB2012-01-17|13:46
mouseActivity$2.class1.13 kB2012-01-17|13:46
mouseActivity$3.class843.00 B2012-01-17|13:46
mouseActivity.class7.60 kB2012-01-17|13:46
R$attr.class325.00 B2012-01-17|13:46
R$drawable.class423.00 B2012-01-17|13:46
R$id.class1.16 kB2012-01-17|13:46
R$layout.class415.00 B2012-01-17|13:46
R$string.class412.00 B2012-01-17|13:46
R.class496.00 B2012-01-17|13:46
ControlPC.apk154.99 kB2011-12-30|16:41
01.96 kB
resources.ap_143.35 kB2011-12-30|15:39
01.96 kB
bg_chat.png129.57 kB2011-12-30|10:33
ic_launcher.png3.87 kB2011-12-30|10:33
01.96 kB
ic_launcher.png1.50 kB2011-12-30|10:33
01.96 kB
ic_launcher.png2.15 kB2011-12-30|10:33
01.96 kB
01.96 kB
01.96 kB
R.java2.10 kB2011-12-30|11:25
proguard.cfg1.22 kB2011-12-26|15:52
project.properties361.00 B2011-12-26|15:52
01.96 kB
01.96 kB
bg_chat.png132.86 kB1980-01-01|00:00
ic_launcher.png4.05 kB2011-12-26|15:52
01.96 kB
ic_launcher.png1.68 kB2011-12-26|15:52
01.96 kB
ic_launcher.png2.51 kB2011-12-26|15:52
01.96 kB
main.xml4.45 kB2011-12-30|15:13
mouse_layout.xml1.97 kB2011-12-30|10:33
01.96 kB
strings.xml184.00 B2011-12-26|15:52
01.96 kB
01.96 kB
01.96 kB
ControlPCActivity.java14.39 kB2011-12-30|11:42
mouseActivity.java9.63 kB2011-12-30|16:41
01.96 kB
01.96 kB
KeyboardHook.dll272.07 kB2011-12-27|19:48
KeyboardHook.lib2.51 kB2011-12-27|19:48
Keyexe.bsc5.17 MB2011-12-30|15:40
Keyexe.exe116.06 kB2011-12-30|15:40
Keyexe.ilk277.56 kB2011-12-30|15:40
Keyexe.obj13.34 kB2011-12-27|19:35
Keyexe.pch6.66 MB2011-12-22|18:15
Keyexe.pdb401.00 kB2011-12-30|15:40
Keyexe.res4.93 kB2011-12-30|11:59
Keyexe.sbr0.00 B2011-12-27|19:35
KeyexeDlg.obj59.41 kB2011-12-30|15:40
KeyexeDlg.sbr0.00 B2011-12-30|15:40
StdAfx.obj104.05 kB2011-12-22|18:15
StdAfx.sbr1.32 MB2011-12-22|18:15
vc60.idb41.00 kB2011-12-30|15:40
vc60.pdb364.00 kB2011-12-30|15:40
icon1.ico766.00 B2011-12-26|13:05
key.txt12.00 B2011-12-22|15:41
KeyboardHook.dll272.07 kB2011-12-27|19:48
KeyboardHook.lib2.51 kB2011-12-27|19:48
keydll3.H348.00 B2011-12-22|12:29
Keyexe.aps38.21 kB2011-12-30|11:59
Keyexe.clw1.86 kB2011-12-30|16:37
Keyexe.cpp3.05 kB2001-12-07|14:20
Keyexe.dsp4.38 kB2011-12-26|16:46
Keyexe.dsw537.00 B2001-12-05|12:23
Keyexe.h2.36 kB2001-12-07|14:20
Keyexe.ncb81.00 kB2011-12-30|17:34
Keyexe.opt56.50 kB2011-12-30|17:34
Keyexe.plg1.13 kB2011-12-30|15:40
Keyexe.rc7.15 kB2011-12-30|11:59
KeyexeDlg.cpp19.98 kB2011-12-30|14:42
KeyexeDlg.h3.08 kB2011-12-27|19:34
ReadMe.txt2.42 kB2001-12-07|22:07
01.96 kB
resource.h1.16 kB2011-12-27|19:35
icon1.ico766.00 B2011-12-26|14:50
Keyexe.ico1.05 kB2001-12-05|12:23
Keyexe.rc2398.00 B2001-12-05|12:23
notify.bmp1.82 kB2011-12-26|14:45
Thumbs.db6.50 kB2011-12-26|15:07
StdAfx.cpp1.35 kB2001-12-07|14:23
StdAfx.h2.06 kB2011-12-22|18:15
...
Sponsored links

KeyexeDlg.cpp (5.90 MB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D