فهرست منبع

更新部分函数,优化

surface pro7 4 سال پیش
والد
کامیت
c974470f7d
4فایلهای تغییر یافته به همراه51 افزوده شده و 42 حذف شده
  1. 3 3
      GameAssist/GameAssist/Assist.cpp
  2. 2 2
      GameAssist/GameAssist/Assist.h
  3. 36 27
      GameAssist/GameAssist/MouseAssist.cpp
  4. 10 10
      GameAssist/GameAssist/MouseAssist.h

+ 3 - 3
GameAssist/GameAssist/Assist.cpp

@@ -266,7 +266,7 @@ namespace GAssist
 		return dwProcessId;
 	}
 
-	HWND GetProcessWnd(const DWORD &dwTagetProcessId, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
+	HWND GetProcessMainWnd(const DWORD &dwTagetProcessId, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
 	{
 		DWORD dwCurPorcessId = 0;
 		HWND hTagetProcessWnd = NULL;
@@ -317,12 +317,12 @@ namespace GAssist
 		return hTagetProcessWnd;
 	}
 
-	HWND GetProcessWnd(LPCTSTR lpProcessName /* = _T("Game.exe") */, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
+	HWND GetProcessMainWnd(LPCTSTR lpProcessName /* = _T("Game.exe") */, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
 	{
 		HWND hTagetWnd = NULL;
 		DWORD dwProcessId = 0;
 		if ( (dwProcessId = GetProcessId(lpProcessName)) != 0 ) {
-			hTagetWnd = GetProcessWnd(dwProcessId, lpTagetWndName);
+			hTagetWnd = GetProcessMainWnd(dwProcessId, lpTagetWndName);
 		}
 
 		return hTagetWnd;

+ 2 - 2
GameAssist/GameAssist/Assist.h

@@ -37,8 +37,8 @@ namespace GAssist
 	// 根据进程名获取进程pid;
 	extern DWORD GetProcessId(LPCTSTR lpProcessName = _T("Game.exe"));
 	// 根据进程pid获取进程对应程序的窗口句柄;
-	extern HWND GetProcessWnd(const DWORD &dwTagetProcessId, LPCTSTR lpTagetWndName = _T("大话水浒"));
-	extern HWND GetProcessWnd(LPCTSTR lpProcessName = _T("Game.exe"), LPCTSTR lpTagetWndName = _T("大话水浒"));
+	extern HWND GetProcessMainWnd(const DWORD &dwTagetProcessId, LPCTSTR lpTagetWndName = _T("大话水浒"));
+	extern HWND GetProcessMainWnd(LPCTSTR lpProcessName = _T("Game.exe"), LPCTSTR lpTagetWndName = _T("大话水浒"));
 
 
 	typedef struct __GAME_HWNINFO__{

+ 36 - 27
GameAssist/GameAssist/MouseAssist.cpp

@@ -5,6 +5,7 @@ MouseAssist::MouseAssist()
 {
 	_hWnd = NULL;
 	_nMode = -1;
+	_curpt = {0,0};
 }
 
 MouseAssist::~MouseAssist()
@@ -25,7 +26,8 @@ void MouseAssist::UnBindWnd()
 	_nMode = -1;
 }
 
-BOOL MouseAssist::GetCursorPos(long& x, long& y)
+
+BOOL MouseAssist::GetCursorPos()
 {
 	BOOL bRet = ::GetCursorPos(&_curpt);
 	if (_nMode == PT_TYPE::WINDOW_POINT) {
@@ -37,6 +39,13 @@ BOOL MouseAssist::GetCursorPos(long& x, long& y)
 		}
 	}
 
+	return bRet;
+}
+
+BOOL MouseAssist::GetCursorPos(long& x, long& y)
+{
+	BOOL bRet = GetCursorPos();
+
 	x = _curpt.x;
 	y = _curpt.y;
 
@@ -91,38 +100,38 @@ BOOL MouseAssist::MoveToEx(int x, int y, int w, int h)
 
 BOOL MouseAssist::LeftClick()
 {
-	BOOL bRet1 = FALSE;
-	BOOL bRet2 = FALSE;
+	BOOL bDown = FALSE;
+	BOOL bUp = FALSE;
 	if ( _nMode == PT_TYPE::SCREEN_POINT ) {
 		INPUT Input = { 0 };
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
-		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+		bDown = ::SendInput(1, &Input, sizeof(INPUT));
 
 		::ZeroMemory(&Input, sizeof(INPUT));
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
-		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+		bUp = ::SendInput(1, &Input, sizeof(INPUT));
 	}
 	else if (_nMode == PT_TYPE::WINDOW_POINT) {
-		//bRet1 = ::SendMessageTimeout(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
-		//bRet2 = ::SendMessageTimeout(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
-		bRet1 = ::PostMessage(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
+		//bDown = ::SendMessageTimeout(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		//bUp = ::SendMessageTimeout(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bDown = ::PostMessage(_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(_curpt.x, _curpt.y));
 		::PostMessage(_hWnd, WM_NCHITTEST, 0, MAKELPARAM(_curpt.x, _curpt.y));
 		::PostMessage(_hWnd, WM_NCHITTEST, HTCLIENT, 0);
-		bRet2 = ::PostMessage(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y));
+		bUp = ::PostMessage(_hWnd, WM_LBUTTONUP, 0, MAKELPARAM(_curpt.x, _curpt.y));
 	}
 
-	return bRet1 & bRet2;
+	return bDown & bUp;
 }
 
 BOOL MouseAssist::LeftDoubleClick()
 {
-	BOOL bRet1 = LeftClick();
+	BOOL bDown = LeftClick();
 	::Sleep(1);
-	BOOL bRet2 = LeftClick();
+	BOOL bUp = LeftClick();
 
-	return bRet1 & bRet2;
+	return bDown & bUp;
 }
 
 BOOL MouseAssist::LeftDown()
@@ -169,25 +178,25 @@ BOOL MouseAssist::LeftUp()
 
 BOOL MouseAssist::MiddleClick()
 {
-	BOOL bRet1 = FALSE;
-	BOOL bRet2 = FALSE;
+	BOOL bDown = FALSE;
+	BOOL bUp = FALSE;
 	if (_nMode == PT_TYPE::SCREEN_POINT) {
 		INPUT Input = { 0 };
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN;
-		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+		bDown = ::SendInput(1, &Input, sizeof(INPUT));
 
 		::ZeroMemory(&Input, sizeof(INPUT));
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_MIDDLEUP;
-		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+		bUp = ::SendInput(1, &Input, sizeof(INPUT));
 	}
 	else if (_nMode == PT_TYPE::WINDOW_POINT) {
-		bRet1 = ::SendMessageTimeout(_hWnd, WM_MBUTTONDOWN, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
-		bRet2 = ::SendMessageTimeout(_hWnd, WM_MBUTTONUP, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bDown = ::SendMessageTimeout(_hWnd, WM_MBUTTONDOWN, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bUp = ::SendMessageTimeout(_hWnd, WM_MBUTTONUP, MK_MBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
 	}
 
-	return bRet1 & bRet2;
+	return bDown & bUp;
 }
 
 BOOL MouseAssist::MiddleDown()
@@ -222,25 +231,25 @@ BOOL MouseAssist::MiddleUp()
 
 BOOL MouseAssist::RightClick()
 {
-	BOOL bRet1 = FALSE;
-	BOOL bRet2 = FALSE;
+	BOOL bDown = FALSE;
+	BOOL bUp = FALSE;
 	if (_nMode == PT_TYPE::SCREEN_POINT) {
 		INPUT Input = { 0 };
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
-		bRet1 = ::SendInput(1, &Input, sizeof(INPUT));
+		bDown = ::SendInput(1, &Input, sizeof(INPUT));
 
 		::ZeroMemory(&Input, sizeof(INPUT));
 		Input.type = INPUT_MOUSE;
 		Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
-		bRet2 = ::SendInput(1, &Input, sizeof(INPUT));
+		bUp = ::SendInput(1, &Input, sizeof(INPUT));
 	}
 	else if (_nMode == PT_TYPE::WINDOW_POINT) {
-		bRet1 = ::SendMessageTimeout(_hWnd, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
-		bRet2 = ::SendMessageTimeout(_hWnd, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bDown = ::SendMessageTimeout(_hWnd, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
+		bUp = ::SendMessageTimeout(_hWnd, WM_RBUTTONUP, MK_RBUTTON, MAKELPARAM(_curpt.x, _curpt.y), SMTO_BLOCK, 2000, nullptr);
 	}
 
-	return bRet1 & bRet2;
+	return bDown & bUp;
 }
 
 BOOL MouseAssist::RightDown()

+ 10 - 10
GameAssist/GameAssist/MouseAssist.h

@@ -16,7 +16,6 @@ public:
 	MouseAssist();
 	~MouseAssist();
 
-
 private:
 	// 关联的进程窗口句柄;
 	HWND _hWnd;
@@ -28,6 +27,7 @@ public:
 	void BindWnd(HWND hWnd, int nMode);
 	void UnBindWnd();
 	// 获取当前鼠标位置;
+	BOOL GetCursorPos();
 	BOOL GetCursorPos(long &x, long &y);
 	BOOL SetCursorPos(int x, int y);
 
@@ -36,21 +36,21 @@ public:
 	// 在指定范围内随机移动;
 	BOOL MoveToEx(int x, int y, int w, int h);
 
-	BOOL LeftClick();
 	BOOL LeftDoubleClick();
-	BOOL LeftDown();
-	BOOL LeftUp();
+	inline BOOL LeftClick();	
+	inline BOOL LeftDown();
+	inline BOOL LeftUp();
 
 	BOOL MiddleClick();
-	BOOL MiddleDown();
-	BOOL MiddleUp();
+	inline BOOL MiddleDown();
+	inline BOOL MiddleUp();
 
 	BOOL RightClick();
-	BOOL RightDown();
-	BOOL RightUp();
+	inline BOOL RightDown();
+	inline BOOL RightUp();
 
-	BOOL WheelDown();
-	BOOL WheelUp();
+	inline BOOL WheelDown();
+	inline BOOL WheelUp();
 };