转载请注明来源:http://www.cnblogs.com/xuesongshu/
这个外挂主要用来帮助鼠标点击的。最近很忙,代码注释我以后会慢慢补充进来。请多多指点。
1 #include "PC2StdAfx.h" 2 3 BOOL CALLBACK PCEnumDlgItem(HWND,LPARAM); 4 BOOL CALLBACK PCEnumWindows(HWND,LPARAM); 5 LRESULT CALLBACK PCMainWinProc(HWND,UINT,WPARAM,LPARAM); 6 BOOL CALLBACK PCHelpWinProc(HWND,UINT,WPARAM,LPARAM); 7 void PC2WmHotKey(HWND hwnd,WPARAM wparam); 8 void PC2WmCommand(HWND hwnd,WPARAM wparam); 9 void PC2WmTimer(); 10 11 TCHAR szAppName[]=TEXT("PCMainWin"); 12 13 //界面类 14 TCHAR szStart[256],szStop[256],szPointFormat[256],szHelpResName[256],szComputePoint[256],szClearPoint[256]; 15 //提示类 16 TCHAR szMousePositionError[256],szOperateTip[256],szGlobalFastKey[256],szLUFirst[256],szLUBiggerRD[256],szPointNotComeplete[256]; 17 18 static HFONT hfont; 19 HWND hDlg=NULL; 20 21 int WINAPI WinMain( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd ) 22 { 23 MSG msg; 24 HWND hwnd; 25 WNDCLASS wc; 26 27 TCHAR szFontName[256]; 28 wc.cbClsExtra=0; 29 wc.cbWndExtra=DLGWINDOWEXTRA; 30 wc.hbrBackground=CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); 31 wc.hCursor=LoadCursor(hInstance,TEXT("PCCursor")); 32 wc.hIcon=LoadIcon(hInstance,TEXT("PCIcon")); 33 wc.hInstance=hInstance; 34 wc.lpfnWndProc=PCMainWinProc; 35 wc.lpszClassName=szAppName; 36 wc.lpszMenuName=TEXT("PCMenu"); 37 wc.style=CS_HREDRAW|CS_VREDRAW; 38 if (!RegisterClass(&wc)) 39 { 40 return 0; 41 } 42 hwnd=CreateDialog(hInstance,szAppName,NULL,NULL); 43 if (!hwnd) 44 { 45 return 0; 46 } 47 LoadString(hInstance,IDS_STRINGFONT,szFontName,256); 48 LoadString(hInstance,IDS_MOUSEPOSITIONERROR,szMousePositionError,256); 49 LoadString(hInstance,IDS_OPERATETIP,szOperateTip,256); 50 LoadString(hInstance,IDS_START,szStart,256); 51 LoadString(hInstance,IDS_STOP,szStop,256); 52 LoadString(hInstance,IDS_POINTFORMAT,szPointFormat,256); 53 LoadString(hInstance,IDS_GLOBALFASTKEY,szGlobalFastKey,256); 54 LoadString(hInstance,IDS_HELPRESNAME,szHelpResName,256); 55 LoadString(hInstance,IDS_COMPUTEPOINT,szComputePoint,256); 56 LoadString(hInstance,IDS_CLEARPOINT,szClearPoint,256); 57 LoadString(hInstance,IDS_LUFIRST,szLUFirst,256); 58 LoadString(hInstance,IDS_LUBIGGERRD,szLUBiggerRD,256); 59 LoadString(hInstance,IDS_POINTNOTCOMPLETE,szPointNotComeplete,256); 60 hfont=CreateFont(18,0,0,0,FW_NORMAL,NULL,NULL,NULL,GB2312_CHARSET,NULL,NULL,NULL,NULL,szFontName); 61 if (hfont==NULL) 62 { 63 hfont=(HFONT)GetStockObject(DEFAULT_GUI_FONT); 64 } 65 SendMessage(hwnd,0xFFFC,NULL,(LPARAM)hfont); 66 while (GetMessage(&msg,NULL,0,0)) 67 { 68 if (hDlg==0||!IsDialogMessage(hDlg,&msg)) 69 { 70 TranslateMessage(&msg); 71 DispatchMessage(&msg); 72 } 73 } 74 return 0; 75 } 76 77 //主窗口消息处理函数。 78 LRESULT CALLBACK PCMainWinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) 79 { 80 switch (msg) 81 { 82 case 0xFFFC: 83 EnumWindows((WNDENUMPROC)PCEnumWindows,NULL); 84 EnumChildWindows(hwnd,(WNDENUMPROC)PCEnumDlgItem,lparam); 85 InvalidateRect(hwnd,NULL,true); 86 //CTRL+SHIFT+A 87 RegisterHotKey(hwnd,PICKCOIN_LU,MOD_CONTROL|MOD_SHIFT,0x41); 88 //CTRL+SHIFT+S 89 RegisterHotKey(hwnd,PICKCOIN_START,MOD_CONTROL|MOD_SHIFT,0x53); 90 //CTRL+SHIFT+Z 91 RegisterHotKey(hwnd,PICKCOIN_COMPUTE,MOD_CONTROL|MOD_SHIFT,0x5A); 92 //CTRL+SHIFT+X 93 RegisterHotKey(hwnd,PICKCOIN_RD,MOD_CONTROL|MOD_SHIFT,0x58); 94 return 0; 95 case WM_HOTKEY: 96 PC2WmHotKey(hwnd,wparam); 97 return 0; 98 case WM_KEYDOWN: 99 switch(wparam) 100 { 101 case VK_SHIFT: 102 break; 103 } 104 return 0; 105 case WM_TIMER: 106 PC2WmTimer(); 107 return 0; 108 case WM_COMMAND: 109 PC2WmCommand(hwnd,wparam); 110 return 0; 111 case WM_DESTROY: 112 UnregisterHotKey(hwnd,PICKCOIN_LU); 113 UnregisterHotKey(hwnd,PICKCOIN_RD); 114 UnregisterHotKey(hwnd,PICKCOIN_START); 115 UnregisterHotKey(hwnd,PICKCOIN_COMPUTE); 116 PostQuitMessage(0); 117 return 0; 118 } 119 return DefWindowProc(hwnd,msg,wparam,lparam); 120 } 121 122 //设定控件字体。 123 BOOL CALLBACK PCEnumDlgItem(HWND hwnd,LPARAM lparam) 124 { 125 SendMessage(hwnd,WM_SETFONT,(WPARAM)(HFONT)lparam,NULL); 126 return true; 127 } 128 129 130 131 //帮助对话框,返回值0表示需要windows自带消息处理函数处理逻辑。 132 BOOL CALLBACK PCHelpWinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) 133 { 134 switch(msg) 135 { 136 case WM_INITDIALOG: 137 EnumChildWindows(hwnd,(WNDENUMPROC)PCEnumDlgItem,(LPARAM)hfont); 138 return 0; 139 case WM_NCLBUTTONDOWN: 140 if (DefWindowProc(hwnd,WM_NCHITTEST,wparam,lparam)==HTCLOSE) 141 { 142 EndDialog(hwnd,TRUE); 143 hDlg=NULL; 144 return 0; 145 } 146 return false; 147 case WM_DESTROY: 148 EndDialog(hwnd,TRUE); 149 return 0; 150 } 151 return 0; 152 }
#define _WIN32_WINNT 0x0601 #define WINVER 0x0601 #define PICKCOIN_LU 0x7FFC #define PICKCOIN_RD 0x7FFB #define PICKCOIN_COMPUTE 0x7FFA #define PICKCOIN_START 0x7FF9 #define ID_PICKCOIN_TIMER 0x7FF8 #define PICKCOIN_PIXELDISTANCE 40 #define PICKCOIN_TIMESPAN 1000 #include <Windows.h> #include <vector> #include "resource.h" #ifdef _WIN32_WINNT #endif
1 //{{NO_DEPENDENCIES}} 2 // Microsoft Developer Studio generated include file. 3 // Used by PC2Res.rc 4 // 5 #define IDS_STRING1 1 6 #define IDS_STRINGFONT 1 7 #define IDS_MOUSEPOSITIONERROR 2 8 #define IDS_OPERATETIP 3 9 #define IDS_START 4 10 #define IDS_STOP 5 11 #define IDS_POINTFORMAT 6 12 #define IDS_GLOBALFASTKEY 7 13 #define IDS_HELPRESNAME 8 14 #define IDS_COMPUTEPOINT 9 15 #define IDS_CLEARPOINT 10 16 #define IDS_LUFIRST 11 17 #define IDS_LUBIGGERRD 12 18 #define IDS_POINTNOTCOMPLETE 13 19 #define IDC_BUTTONLU 1000 20 #define IDC_BUTTONSTART 1001 21 #define IDC_STATICLU 1002 22 #define IDC_BUTTONRD 1007 23 #define IDC_STATICRD 1008 24 #define IDC_BUTTONCOMPUTE 1009 25 #define ID_MENUITEM40001 40001 26 27 // Next default values for new objects 28 // 29 #ifdef APSTUDIO_INVOKED 30 #ifndef APSTUDIO_READONLY_SYMBOLS 31 #define _APS_NEXT_RESOURCE_VALUE 106 32 #define _APS_NEXT_COMMAND_VALUE 40002 33 #define _APS_NEXT_CONTROL_VALUE 1015 34 #define _APS_NEXT_SYMED_VALUE 101 35 #endif 36 #endif
1 //Microsoft Developer Studio generated resource script. 2 // 3 #include "resource.h" 4 5 #define APSTUDIO_READONLY_SYMBOLS 6 ///////////////////////////////////////////////////////////////////////////// 7 // 8 // Generated from the TEXTINCLUDE 2 resource. 9 // 10 #include "afxres.h" 11 12 ///////////////////////////////////////////////////////////////////////////// 13 #undef APSTUDIO_READONLY_SYMBOLS 14 15 ///////////////////////////////////////////////////////////////////////////// 16 // Chinese (P.R.C.) resources 17 18 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) 19 #ifdef _WIN32 20 LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED 21 #pragma code_page(936) 22 #endif //_WIN32 23 24 #ifdef APSTUDIO_INVOKED 25 ///////////////////////////////////////////////////////////////////////////// 26 // 27 // TEXTINCLUDE 28 // 29 30 1 TEXTINCLUDE DISCARDABLE 31 BEGIN 32 "resource.h\0" 33 END 34 35 2 TEXTINCLUDE DISCARDABLE 36 BEGIN 37 "#include ""afxres.h""\r\n" 38 "\0" 39 END 40 41 3 TEXTINCLUDE DISCARDABLE 42 BEGIN 43 "\r\n" 44 "\0" 45 END 46 47 #endif // APSTUDIO_INVOKED 48 49 50 ///////////////////////////////////////////////////////////////////////////// 51 // 52 // Dialog 53 // 54 55 PCMAINWIN DIALOG DISCARDABLE 0, 0, 187, 122 56 STYLE DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 CAPTION "植物大战僵尸鼠标外挂——[email protected]" 58 CLASS "PCMainWin" 59 FONT 10, "System" 60 BEGIN 61 PUSHBUTTON "定位(CTRL+SHIFT+A)",IDC_BUTTONLU,13,13,86,18 62 RTEXT "左上角:",IDC_STATIC,100,13,33,18,SS_CENTERIMAGE 63 LTEXT "(0,0)",IDC_STATICLU,136,13,44,18,SS_CENTERIMAGE 64 PUSHBUTTON "开始(CTRL+SHIFT+S)",IDC_BUTTONSTART,13,85,160,18 65 PUSHBUTTON "定位(CTRL+SHIFT+X)",IDC_BUTTONRD,13,37,86,18 66 RTEXT "右下角:",IDC_STATIC,100,38,33,18,SS_CENTERIMAGE 67 LTEXT "(0,0)",IDC_STATICRD,136,38,44,18,SS_CENTERIMAGE 68 PUSHBUTTON "计算坐标(CTRL_SHIFT+Z)",IDC_BUTTONCOMPUTE,13,61,160,18 69 END 70 71 PCHELP DIALOG DISCARDABLE 0, 0, 187, 94 72 STYLE DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 73 CAPTION "关于作者" 74 FONT 10, "System" 75 BEGIN 76 LTEXT "作者:曹威",IDC_STATIC,7,7,173,14 77 LTEXT "联系方式:[email protected]",IDC_STATIC,7,23,173, 78 14 79 LTEXT "版权所有,侵权必究",IDC_STATIC,7,39,173,14 80 LTEXT "^_^ ^_^",IDC_STATIC,7,55,173,14 81 END 82 83 84 ///////////////////////////////////////////////////////////////////////////// 85 // 86 // DESIGNINFO 87 // 88 89 #ifdef APSTUDIO_INVOKED 90 GUIDELINES DESIGNINFO DISCARDABLE 91 BEGIN 92 "PCMAINWIN", DIALOG 93 BEGIN 94 LEFTMARGIN, 7 95 RIGHTMARGIN, 180 96 TOPMARGIN, 7 97 BOTTOMMARGIN, 115 98 END 99 100 "PCHELP", DIALOG 101 BEGIN 102 LEFTMARGIN, 7 103 RIGHTMARGIN, 180 104 TOPMARGIN, 7 105 BOTTOMMARGIN, 87 106 END 107 END 108 #endif // APSTUDIO_INVOKED 109 110 111 ///////////////////////////////////////////////////////////////////////////// 112 // 113 // Icon 114 // 115 116 // Icon with lowest ID value placed first to ensure application icon 117 // remains consistent on all systems. 118 PCICON ICON DISCARDABLE "FACE02.ICO" 119 120 ///////////////////////////////////////////////////////////////////////////// 121 // 122 // Cursor 123 // 124 125 PCCURSOR CURSOR DISCARDABLE "cursor1.cur" 126 127 ///////////////////////////////////////////////////////////////////////////// 128 // 129 // Menu 130 // 131 132 PCMENU MENU DISCARDABLE 133 BEGIN 134 POPUP "帮助" 135 BEGIN 136 MENUITEM "关于作者", ID_MENUITEM40001 137 END 138 END 139 140 141 ///////////////////////////////////////////////////////////////////////////// 142 // 143 // String Table 144 // 145 146 STRINGTABLE DISCARDABLE 147 BEGIN 148 IDS_STRINGFONT "华文中宋" 149 IDS_MOUSEPOSITIONERROR "鼠标请放置于目标窗口的显示范围内!" 150 IDS_OPERATETIP "操作提示" 151 IDS_START "开始(CTRL+SHIFT+S)" 152 IDS_STOP "停止(CTRL+SHIFT+S)" 153 IDS_POINTFORMAT "(%d,%d)" 154 IDS_GLOBALFASTKEY "请使用全局快捷键!" 155 IDS_HELPRESNAME "PCHelp" 156 IDS_COMPUTEPOINT "计算坐标(CTRL_SHIFT+Z)" 157 IDS_CLEARPOINT "清空坐标(CTRL_SHIFT+Z)" 158 IDS_LUFIRST "请先定义左上角坐标!" 159 IDS_LUBIGGERRD "左上角坐标大于右下角坐标!" 160 IDS_POINTNOTCOMPLETE "坐标未定义完毕。请检查左上角坐标和右下角坐标的值。" 161 END 162 163 #endif // Chinese (P.R.C.) resources 164 ///////////////////////////////////////////////////////////////////////////// 165 166 167 168 #ifndef APSTUDIO_INVOKED 169 ///////////////////////////////////////////////////////////////////////////// 170 // 171 // Generated from the TEXTINCLUDE 3 resource. 172 // 173 174 175 ///////////////////////////////////////////////////////////////////////////// 176 #endif // not APSTUDIO_INVOKED
1 #include "PC2StdAfx.h" 2 3 extern HWND hDlg; 4 //界面类 5 extern TCHAR szStart[256],szStop[256],szPointFormat[256],szHelpResName[256],szComputePoint[256],szClearPoint[256]; 6 //提示类 7 extern TCHAR szMousePositionError[256],szOperateTip[256],szGlobalFastKey[256],szLUFirst[256],szLUBiggerRD[256],szPointNotComeplete[256]; 8 9 bool bBeg=false,bCompute=false; 10 std::vector<POINT> vpt; 11 HWND hDst=NULL; 12 RECT rtDst; 13 14 void PC2ButtonStart(HWND hwnd); 15 void PC2ComputePoint(HWND hwnd); 16 BOOL CALLBACK PCHelpWinProc(HWND,UINT,WPARAM,LPARAM); 17 18 void PC2WmHotKey(HWND hwnd,WPARAM wparam) 19 { 20 TCHAR szLocation[256]; 21 POINT pt; 22 switch(wparam) 23 { 24 case PICKCOIN_LU: 25 GetCursorPos(&pt); 26 ScreenToClient(hDst,&pt); 27 if (pt.x<0||pt.x>rtDst.right-rtDst.left||pt.y<0||pt.y>rtDst.bottom-rtDst.top) 28 { 29 MessageBox(hwnd,szMousePositionError,szOperateTip,MB_OK|MB_ICONERROR); 30 break; 31 } 32 vpt.clear(); 33 vpt.push_back(pt); 34 wsprintf(szLocation,szPointFormat,pt.x,pt.y); 35 SetDlgItemText(hwnd,IDC_STATICLU,szLocation); 36 break; 37 case PICKCOIN_RD: 38 if (vpt.size()==0) 39 { 40 MessageBox(hwnd,szLUFirst,szOperateTip,MB_OK|MB_ICONERROR); 41 break; 42 } 43 GetCursorPos(&pt); 44 ScreenToClient(hDst,&pt); 45 if (pt.x<0||pt.x>rtDst.right-rtDst.left||pt.y<0||pt.y>rtDst.bottom-rtDst.top) 46 { 47 MessageBox(hwnd,szMousePositionError,szOperateTip,MB_OK|MB_ICONERROR); 48 break; 49 } 50 while (vpt.size()>1) 51 { 52 vpt.pop_back(); 53 } 54 if (pt.x<vpt[0].x||pt.y<vpt[0].y) 55 { 56 MessageBox(hwnd,szLUBiggerRD,szOperateTip,MB_OK|MB_ICONERROR); 57 break; 58 } 59 vpt.push_back(pt); 60 wsprintf(szLocation,szPointFormat,pt.x,pt.y); 61 SetDlgItemText(hwnd,IDC_STATICRD,szLocation); 62 break; 63 case PICKCOIN_START: 64 PC2ButtonStart(hwnd); 65 break; 66 case PICKCOIN_COMPUTE: 67 PC2ComputePoint(hwnd); 68 break; 69 } 70 71 } 72 73 void PC2WmCommand(HWND hwnd,WPARAM wparam) 74 { 75 int nId,nEvent; 76 nId=LOWORD(wparam); 77 nEvent=HIWORD(wparam); 78 switch(nId) 79 { 80 case IDC_BUTTONLU: 81 case IDC_BUTTONRD: 82 MessageBox(hwnd,szGlobalFastKey,szOperateTip,MB_OK|MB_ICONERROR); 83 return; 84 case IDC_BUTTONCOMPUTE: 85 PC2ComputePoint(hwnd); 86 break; 87 case IDC_BUTTONSTART: 88 PC2ButtonStart(hwnd); 89 break; 90 case ID_MENUITEM40001: 91 hDlg=(HWND)DialogBox((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),szHelpResName,hwnd,PCHelpWinProc); 92 break; 93 default: 94 break; 95 } 96 } 97 98 void PC2WmTimer() 99 { 100 std::vector<POINT>::reverse_iterator vptit; 101 int x,y; 102 DWORD dwLparam=0; 103 DWORD *pdwLparam=&dwLparam; 104 for (vptit=vpt.rbegin();vptit<vpt.rend();++vptit) 105 { 106 x=vptit->x; 107 y=vptit->y; 108 __asm 109 { 110 PUSH EAX 111 PUSH EBX 112 PUSH ECX 113 MOV EAX,x 114 MOV EBX,y 115 MOV ECX,pdwLparam 116 MOV WORD PTR [ECX],AX 117 ADD ECX,2 118 MOV WORD PTR [ECX],BX 119 POP ECX 120 POP EBX 121 POP EAX 122 } 123 SendMessage(hDst,WM_LBUTTONDOWN,1,dwLparam); 124 SendMessage(hDst,WM_LBUTTONUP,0,dwLparam); 125 } 126 } 127 128 //查找植物大战僵尸游戏主窗口。 129 BOOL CALLBACK PCEnumWindows(HWND hwnd,LPARAM lparam) 130 { 131 TCHAR szTitle[256]; 132 RECT rtTmp; 133 GetWindowText(hwnd,szTitle,256); 134 if (lstrlen(szTitle)>0) 135 { 136 std::string strTitle=szTitle; 137 if(strTitle.find("Plants vs.")!=std::string::npos) 138 { 139 GetWindowRect(hwnd,&rtTmp); 140 if (rtTmp.left<0||rtTmp.top<0) 141 { 142 return true; 143 } 144 if (rtTmp.right-rtTmp.left>300) 145 { 146 hDst=hwnd; 147 rtDst=rtTmp; 148 } 149 } 150 } 151 return true; 152 } 153 154 void PC2ButtonStart(HWND hwnd) 155 { 156 if (bBeg) 157 { 158 KillTimer(hwnd,ID_PICKCOIN_TIMER); 159 SetDlgItemText(hwnd,IDC_BUTTONSTART,szStart); 160 } 161 else 162 { 163 if (vpt.size()<2) 164 { 165 MessageBox(hwnd,szPointNotComeplete,szOperateTip,MB_OK|MB_ICONERROR); 166 return; 167 } 168 SetTimer(hwnd,ID_PICKCOIN_TIMER,PICKCOIN_TIMESPAN,NULL); 169 SetDlgItemText(hwnd,IDC_BUTTONSTART,szStop); 170 } 171 bBeg=!bBeg; 172 } 173 174 void PC2ComputePoint(HWND hwnd) 175 { 176 POINT ptLU,ptRD,ptTmp; 177 int i,j; 178 if (bCompute) 179 { 180 vpt.clear(); 181 SetDlgItemText(hwnd,IDC_STATICLU,TEXT("(0,0)")); 182 SetDlgItemText(hwnd,IDC_STATICRD,TEXT("(0,0)")); 183 SetDlgItemText(hwnd,IDC_BUTTONCOMPUTE,szComputePoint); 184 } 185 else 186 { 187 if (vpt.size()<2) 188 { 189 MessageBox(hwnd,szPointNotComeplete,szOperateTip,MB_OK|MB_ICONERROR); 190 return; 191 } 192 ptLU=vpt[0]; 193 ptRD=vpt[1]; 194 vpt.clear(); 195 for (i=ptLU.x;i<ptRD.x;i+=PICKCOIN_PIXELDISTANCE) 196 { 197 ptTmp.x=i; 198 ptTmp.y=ptRD.y; 199 vpt.push_back(ptTmp); 200 } 201 for (j=ptLU.y;j<ptRD.y;j+=PICKCOIN_PIXELDISTANCE) 202 { 203 ptTmp.x=ptRD.x; 204 ptTmp.y=j; 205 vpt.push_back(ptTmp); 206 } 207 for (i=ptLU.x;i<ptRD.x;i+=PICKCOIN_PIXELDISTANCE) 208 { 209 for (j=ptLU.y;j<ptRD.y;j+=PICKCOIN_PIXELDISTANCE) 210 { 211 ptTmp.x=i; 212 ptTmp.y=j; 213 vpt.push_back(ptTmp); 214 } 215 } 216 vpt.push_back(ptLU); 217 vpt.push_back(ptRD); 218 SetDlgItemText(hwnd,IDC_BUTTONCOMPUTE,szClearPoint); 219 } 220 bCompute=!bCompute; 221 }