VS竞技游戏平台辅助外挂制作实例

来源:互联网 发布:c语言源代码 编辑:程序博客网 时间:2024/04/29 18:43

实行文件下载地址:

http://download.csdn.net/source/743789

 

运行实例图:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

访问其他进程的头文件:

  1. //---------------------------------------------------------------------------
  2. #ifndef MemoryCtrH
  3. #define MemoryCtrH
  4. #include <windows.h>
  5. //---------------------------------------------------------------------------
  6. void* AllocMemInForeignProcess(HANDLE process, unsigned long size);
  7. void FreeMemInForeignProcess(HANDLE process, void* ptr);
  8. void ReadFromForeignProcessMemory(HANDLE process, void* ptr, void* target, unsigned long size);
  9. void WriteToForeignProcessMemory(HANDLE process, void* ptr, void* src, unsigned long size);
  10. //---------------------------------------------------------------------------
  11. #endif

访问其他进程内存的cpp文件:

 

  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include "MemoryCtr.h"
  4. //---------------------------------------------------------------------------
  5. #pragma package(smart_init)
  6. //---------------------------------------------------------------------------
  7. /*
  8.  * Allocated memory in a foreign process. Windows NT only!!!
  9.  */
  10. void* AllocMemInForeignProcess(HANDLE process, unsigned long size)
  11. {
  12.     void *ptr = VirtualAllocEx(process, NULL, size, MEM_COMMIT, PAGE_READWRITE);
  13.     if(ptr == NULL) throw(GetLastError());
  14.     else return ptr;
  15. }
  16. //---------------------------------------------------------------------------
  17. /*
  18.  * Frees previously allocated memory in a foreign process. Windows NT only!!!
  19.  */
  20. void FreeMemInForeignProcess(HANDLE process, void* ptr)
  21. {
  22.     if(VirtualFreeEx(process, ptr, 0, MEM_RELEASE) == 0) throw(GetLastError());
  23. }
  24. //---------------------------------------------------------------------------
  25. /*
  26.  * Reads from memory we previously allocated in a foreign process.
  27.  */
  28. void ReadFromForeignProcessMemory(HANDLE process, void* ptr, void* target, unsigned long size)
  29. {
  30.     if(ReadProcessMemory(process, ptr, target, size, NULL) == 0) throw(GetLastError());
  31. }
  32. //---------------------------------------------------------------------------
  33. /*
  34.  * Writes to memory we previously allocated in a foreign process.
  35.  */
  36. void WriteToForeignProcessMemory(HANDLE process, void* ptr, void* src, unsigned long size)
  37. {
  38.     if(WriteProcessMemory(process, ptr, src, size, NULL) == 0) throw(GetLastError());
  39. }
  40. //---------------------------------------------------------------------------

 主程序的头文件:

 

 

 

  1. //---------------------------------------------------------------------------
  2. #ifndef TVSEnterH
  3. #define TVSEnterH
  4. //---------------------------------------------------------------------------
  5. #include <Classes.hpp>
  6. #include <Controls.hpp>
  7. #include <StdCtrls.hpp>
  8. #include <Forms.hpp>
  9. #include "AdvAppStyler.hpp"
  10. #include "AdvAlertWindow.hpp"
  11. #include "AdvCircularProgress.hpp"
  12. #include "AdvGlassButton.hpp"
  13. #include "AdvListV.hpp"
  14. #include "ExeInfo.hpp"
  15. #include <ComCtrls.hpp>
  16. #include "FormSize.hpp"
  17. #include "AdvMenus.hpp"
  18. #include "trayicon.h"
  19. #include <ImgList.hpp>
  20. #include <Menus.hpp>
  21. #include "AdvOfficeStatusBar.hpp"
  22. #include <ExtCtrls.hpp>
  23. //---------------------------------------------------------------------------
  24. class TVSEnterForm : public TForm
  25. {
  26. __published:    // IDE-managed Components
  27.     TAdvListView *Roomlist;
  28.     TAdvGlassButton *btnOK;
  29.     TAdvCircularProgress *AdvCircularProgress1;
  30.     TAdvAlertWindow *AdvAlertWindow1;
  31.     TFormSize *vsInfo;
  32.     TTrayIcon *TrayIcon1;
  33.     TAdvPopupMenu *AdvPopupMenu1;
  34.     TMenuItem *popRestore;
  35.     TMenuItem *popStop;
  36.     TMenuItem *popGoOn;
  37.     TMenuItem *popExit;
  38.     TImageList *ImageList1;
  39.     TAdvOfficeStatusBar *AdvOfficeStatusBar1;
  40.     TAdvGlassButton *btnAllSelect;
  41.     TAdvGlassButton *btnAllCancel;
  42.     TTimer *EnterRoomTimer;
  43.     TAdvGlassButton *btnUpdateRoomList;
  44.     void __fastcall btnAllSelectClick(TObject *Sender);
  45.     void __fastcall RoomlistColumnRClick(TObject *Sender, int Column);
  46.     void __fastcall btnOKClick(TObject *Sender);
  47.     void __fastcall popRestoreClick(TObject *Sender);
  48.     void __fastcall popStopClick(TObject *Sender);
  49.     void __fastcall popGoOnClick(TObject *Sender);
  50.     void __fastcall popExitClick(TObject *Sender);
  51.     void __fastcall EnterRoomTimerTimer(TObject *Sender);
  52.     void __fastcall btnUpdateRoomListClick(TObject *Sender);
  53. private:    // User declarations
  54.     int StartHotKeyId; 
  55.     int StopHotKeyId;
  56.     int ExitHotKeyId;
  57.     void  __fastcall SetRoomList(void);
  58.     HWND  __fastcall GetVsRoomListHandle(void);
  59.     void  __fastcall SaveInfo(void);
  60.     void  __fastcall LoadInfo(void);
  61.     void  __fastcall SetRegKey(void);
  62.     void  __fastcall CancelRegKey(void);
  63.     void __fastcall HotKeyDown(TMessage &Msg);
  64.     void  __fastcall Init(void);
  65. public:     // User declarations
  66.     __fastcall TVSEnterForm(TComponent* Owner);
  67.     void  __fastcall EnterRoom(void);
  68.     
  69. BEGIN_MESSAGE_MAP 
  70.     VCL_MESSAGE_HANDLER(WM_HOTKEY, TMessage, HotKeyDown); 
  71. END_MESSAGE_MAP(TForm); 
  72. };
  73. //---------------------------------------------------------------------------
  74. extern PACKAGE TVSEnterForm *VSEnterForm;
  75. //---------------------------------------------------------------------------
  76. #endif

 主程序的cpp文件:

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "TVSEnter.h"
  5. #include "commctrl.h"
  6. #include "MemoryCtr.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "AdvAppStyler"
  10. #pragma link "AdvAlertWindow"
  11. #pragma link "AdvCircularProgress"
  12. #pragma link "AdvGlassButton"
  13. #pragma link "AdvListV"
  14. #pragma link "ExeInfo"
  15. #pragma link "FormSize"
  16. #pragma link "AdvMenus"
  17. #pragma link "trayicon"
  18. #pragma link "AdvOfficeStatusBar"
  19. #pragma resource "*.dfm"
  20. //---------------------------------------------------------------------------
  21. BOOL CALLBACK FindVSMainWinProc(HWND hWnd,LPARAM lParam);
  22. BOOL CALLBACK FindRoomListWinProc(HWND hWnd,LPARAM lParam);
  23. VOID CALLBACK VSEnterSendAsyncProc(HWND hwnd,UINT uMsg,DWORD dwData,LRESULT lResult);
  24. //---------------------------------------------------------------------------
  25. TVSEnterForm *VSEnterForm;
  26. //---------------------------------------------------------------------------
  27. HWND VSMainWin = NULL;
  28. HWND VSRoomList = NULL;
  29. TList *VSWinListParent = NULL;
  30. TList *VSWinListChild = NULL;
  31. //TStringList *StrList = NULL;
  32. //---------------------------------------------------------------------------
  33. const int WinCount = 5;
  34. // 窗口类名数组
  35. char *WinClassName[WinCount] =
  36. {
  37.     "#32770",
  38.     "Static",
  39.     "Static",
  40.     "Static",
  41.     "SysListView32"
  42. };
  43. // 窗口标题数组
  44. char *WinName[WinCount] =
  45. {
  46.     "VS竞技游戏平台",
  47.     "Static",
  48.     "Static",
  49.     "Static",
  50.     "List1"
  51. };
  52. //---------------------------------------------------------------------------
  53. __fastcall TVSEnterForm::TVSEnterForm(TComponent* Owner)
  54.     : TForm(Owner)
  55. {
  56.     Init();
  57.     //状态栏时间日期设定
  58.     AdvOfficeStatusBar1->Panels->Items[2]->Text = TDateTime::CurrentDateTime().DateTimeString();
  59.     AdvOfficeStatusBar1->Panels->Items[3]->Text = TDateTime::CurrentDateTime().DateTimeString();
  60.     VSMainWin = NULL;
  61.     VSWinListParent = new TList;
  62.     VSWinListChild = new TList;
  63.     //StrList = new TStringList;
  64.     SetRoomList();
  65. }
  66. //---------------------------------------------------------------------------
  67. void  __fastcall TVSEnterForm::SetRoomList(void)
  68. {
  69.     VSRoomList =GetVsRoomListHandle();
  70.     //找到VS进程号
  71.     DWORD vspid;
  72.     HANDLE vsproc;
  73.     int rowcount = 0;
  74.     void* vsroomitemdes = NULL;
  75.     char* itemtext = NULL;
  76.     bool error = false;
  77.     LRESULT msg_result = 0;
  78.     LVITEM iconlabel;
  79.     char buffer[sizeof(char)*(MAX_PATH+1)];
  80.     TListItem * item;
  81.     try
  82.     {
  83.         //得到当前大厅的房间数
  84.         rowcount = static_cast<int>(SendMessage(VSRoomList, LVM_GETITEMCOUNT, 0, 0));
  85.         if(rowcount == 0) return;
  86.         
  87.         //打开VS进程,创建通信内存区域
  88.         GetWindowThreadProcessId(VSMainWin, &vspid);
  89.         vsproc = OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, vspid);
  90.         if(vsproc == NULL)throw(GetLastError());
  91.         vsroomitemdes = AllocMemInForeignProcess(vsproc, sizeof(LVITEM));
  92.         itemtext = static_cast<char*>(AllocMemInForeignProcess(vsproc, sizeof(sizeof(char)*(MAX_PATH+1))));
  93.         
  94.         //逐个房间查询,得到房间的信息
  95.         for(int loop = 0; loop < rowcount; loop++){
  96.             //设置要得到的信息
  97.             iconlabel.iSubItem = 0;
  98.             iconlabel.cchTextMax = MAX_PATH;
  99.             iconlabel.mask = LVIF_TEXT;
  100.             iconlabel.pszText = (LPTSTR)itemtext;
  101.             
  102.             WriteToForeignProcessMemory(vsproc, vsroomitemdes, &iconlabel, sizeof(LVITEM));
  103.             msg_result = SendMessage(VSRoomList, LVM_GETITEMTEXT, loop, (LPARAM)vsroomitemdes);
  104.             if(msg_result < 0){
  105.                 MessageBox(NULL, "无法取得房间信息""VS挤房间", MB_OK|MB_ICONERROR);
  106.                 error = true;
  107.                 break;
  108.             }
  109.             
  110.             ReadFromForeignProcessMemory(vsproc, itemtext, &buffer, sizeof(buffer));
  111.             item = Roomlist->Items->Add();
  112.             item->Caption = buffer;
  113.             //设置要得到的信息
  114.             iconlabel.iSubItem = 2;
  115.             iconlabel.cchTextMax = MAX_PATH;
  116.             iconlabel.mask = LVIF_TEXT;
  117.             iconlabel.pszText = (LPTSTR)itemtext;
  118.             
  119.             WriteToForeignProcessMemory(vsproc, vsroomitemdes, &iconlabel, sizeof(LVITEM));
  120.             msg_result = SendMessage(VSRoomList, LVM_GETITEMTEXT, loop, (LPARAM)vsroomitemdes);
  121.             if(msg_result < 0){
  122.                 MessageBox(NULL, "无法取得房间信息""VS挤房间", MB_OK|MB_ICONERROR);
  123.                 error = true;
  124.                 break;
  125.             }
  126.             
  127.             ReadFromForeignProcessMemory(vsproc, itemtext, &buffer, sizeof(buffer));
  128.             item->SubItems->Add(buffer);
  129.             //设置要得到的信息
  130.             iconlabel.iSubItem = 3;
  131.             iconlabel.cchTextMax = MAX_PATH;
  132.             iconlabel.mask = LVIF_TEXT;
  133.             iconlabel.pszText = (LPTSTR)itemtext;
  134.             
  135.             WriteToForeignProcessMemory(vsproc, vsroomitemdes, &iconlabel, sizeof(LVITEM));
  136.             msg_result = SendMessage(VSRoomList, LVM_GETITEMTEXT, loop, (LPARAM)vsroomitemdes);
  137.             if(msg_result < 0)
  138.             {
  139.                 MessageBox(NULL, "无法取得房间信息""VS挤房间", MB_OK|MB_ICONERROR);
  140.                 error = true;
  141.                 break;
  142.             }
  143.             
  144.             ReadFromForeignProcessMemory(vsproc, itemtext, &buffer, sizeof(buffer));
  145.             item->SubItems->Add(buffer);
  146.         }
  147.         
  148.         //如果出错,清空所有的东西
  149.         if(error){
  150.             Roomlist->Items->BeginUpdate();
  151.             Roomlist->Items->Clear();
  152.             Roomlist->Items->EndUpdate();
  153.         }
  154.         //清空所有的东西
  155.         FreeMemInForeignProcess(vsproc, vsroomitemdes);
  156.         FreeMemInForeignProcess(vsproc, itemtext);
  157.         CloseHandle(vsproc);
  158.     }
  159.     catch(DWORD error)
  160.     {   
  161.         //清空所有的东西
  162.         delete itemtext;
  163.         if(vsproc)
  164.         {
  165.             if(vsroomitemdes) FreeMemInForeignProcess(vsproc, vsroomitemdes);
  166.             if(itemtext) FreeMemInForeignProcess(vsproc, itemtext);
  167.             CloseHandle(vsproc);
  168.         }
  169.         //Rethrow the original error.
  170.         throw error;
  171.     }
  172. }
  173. //---------------------------------------------------------------------------
  174. HWND  __fastcall TVSEnterForm::GetVsRoomListHandle(void)
  175. {
  176.     EnumWindows((WNDENUMPROC)FindVSMainWinProc,0);
  177.     VSWinListParent->Add(VSMainWin);
  178.     for(int i = 1; i < WinCount ; i++){
  179.         for(int j = 0 ; j < VSWinListParent->Count ; j++){
  180.             EnumChildWindows((HWND)(VSWinListParent->Items[j]),(WNDENUMPROC)FindRoomListWinProc,i);
  181.         }
  182.         VSWinListParent->Clear();
  183.         VSWinListParent->Assign(VSWinListChild,laCopy);
  184.         VSWinListChild->Clear();
  185.     }
  186.     if(VSWinListParent->Count == 1){
  187.         return  (HWND)(VSWinListParent->Items[0]);
  188.     }
  189.     //StrList->SaveToFile("d://1.txt");
  190. }
  191. //---------------------------------------------------------------------------
  192. BOOL CALLBACK FindRoomListWinProc(HWND hWnd,LPARAM lParam)
  193. {
  194.     char windclassname[MAX_PATH]; 
  195.     GetWindowText(hWnd,windclassname,MAX_PATH);
  196.     if(windclassname[0] != 0 && strstr(windclassname , WinName[(int)lParam])){
  197.         VSWinListChild->Add(hWnd);
  198.         //StrList->Add(AnsiString(IntToHex((int)hWnd,8))+":"+AnsiString(lParam));
  199.     } 
  200.     return true
  201. }
  202. //---------------------------------------------------------------------------
  203. BOOL CALLBACK FindVSMainWinProc(HWND hWnd,LPARAM lParam)
  204.     char windclassname[MAX_PATH]; 
  205.     GetWindowText(hWnd,windclassname,MAX_PATH); 
  206.     if(windclassname[0] != 0 && strstr(windclassname , WinName[0])){ 
  207.         VSMainWin = hWnd;
  208.         //StrList->Add(AnsiString(IntToHex((int)hWnd,8)));
  209.         return false
  210.     }
  211.     return true
  212. //---------------------------------------------------------------------------
  213. void  __fastcall TVSEnterForm::SaveInfo(void)
  214. {
  215. }
  216. //---------------------------------------------------------------------------
  217. void  __fastcall TVSEnterForm::LoadInfo(void)
  218. {
  219. }
  220. //---------------------------------------------------------------------------
  221. void  __fastcall TVSEnterForm::SetRegKey(void)
  222. {
  223.     StopHotKeyId = GlobalAddAtom("StopVSLoader")-0xC000;
  224.     StartHotKeyId = GlobalAddAtom("StartVSLoader")-0xC000;
  225.     ExitHotKeyId = GlobalAddAtom("ExitVSLoader")-0xC000;
  226.     RegisterHotKey(Handle , StartHotKeyId , MOD_CONTROL ,VK_F1);
  227.     RegisterHotKey(Handle , StopHotKeyId  , MOD_CONTROL ,VK_F2);
  228.     RegisterHotKey(Handle , ExitHotKeyId  , MOD_CONTROL ,VK_F3);
  229. }
  230. //---------------------------------------------------------------------------
  231. void  __fastcall TVSEnterForm::CancelRegKey(void)
  232. {
  233.     UnregisterHotKey(Handle , StartHotKeyId); 
  234.     UnregisterHotKey(Handle , StopHotKeyId);
  235.     UnregisterHotKey(Handle , ExitHotKeyId); 
  236. }
  237. //--------------------------------------------------------------------------- 
  238. void __fastcall TVSEnterForm::HotKeyDown(TMessage &Msg)
  239.     if( (Msg.LParamLo == MOD_CONTROL)&& (Msg.LParamHi == VK_F1) ){
  240.         EnterRoomTimer->Enabled = false;
  241.         TrayIcon1->Animate = false;
  242.         AdvCircularProgress1->Enabled = false;
  243.     } 
  244.     if( (Msg.LParamLo == MOD_CONTROL)&& (Msg.LParamHi == VK_F2) ){
  245.         EnterRoomTimer->Enabled = true;
  246.         TrayIcon1->Animate = true;
  247.         AdvCircularProgress1->Enabled = true;
  248.     }
  249.     if( (Msg.LParamLo == MOD_CONTROL)&& (Msg.LParamHi == VK_F3) ){
  250.         EnterRoomTimer->Enabled = false;
  251.         TrayIcon1->Animate = false;
  252.         AdvCircularProgress1->Enabled = false;
  253.         Close();
  254.     } 
  255. }
  256. //---------------------------------------------------------------------------
  257. void __fastcall TVSEnterForm::btnAllSelectClick(TObject *Sender)
  258. {
  259.     bool flag = true;
  260.     if((TAdvGlassButton *)Sender == btnAllCancel){
  261.         flag = false;
  262.     }
  263.     for(int i = 0 ; i < Roomlist->Items->Count ; i++){
  264.         Roomlist->Items->Item[i]->Checked = flag;
  265.     }
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TVSEnterForm::RoomlistColumnRClick(TObject *Sender,
  269.       int Column)
  270. {
  271.     Roomlist->ShowFilter(true);
  272. }
  273. //---------------------------------------------------------------------------
  274. void __fastcall TVSEnterForm::btnOKClick(TObject *Sender)
  275. {
  276.     Application->ShowMainForm = false;
  277.     TrayIcon1->Minimize();
  278.     TrayIcon1->Animate = true;
  279.     EnterRoomTimer->Enabled = true;
  280.     EnterRoom();
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TVSEnterForm::popRestoreClick(TObject *Sender)
  284. {
  285.     Application->ShowMainForm = true;
  286.     TrayIcon1->Restore();
  287. }
  288. //---------------------------------------------------------------------------
  289. void __fastcall TVSEnterForm::popStopClick(TObject *Sender)
  290. {
  291.     EnterRoomTimer->Enabled = false;
  292.     TrayIcon1->Animate = false;
  293.     AdvCircularProgress1->Enabled = false;
  294. }
  295. //---------------------------------------------------------------------------
  296. void __fastcall TVSEnterForm::popGoOnClick(TObject *Sender)
  297. {
  298.     EnterRoomTimer->Enabled = true;
  299.     TrayIcon1->Animate = true;
  300.     AdvCircularProgress1->Enabled = true;   
  301. }
  302. //---------------------------------------------------------------------------
  303. void __fastcall TVSEnterForm::popExitClick(TObject *Sender)
  304. {
  305.     EnterRoomTimer->Enabled = false;
  306.     TrayIcon1->Animate = false;
  307.     AdvCircularProgress1->Enabled = false;
  308.     Close();
  309. }
  310. //---------------------------------------------------------------------------
  311. void __fastcall TVSEnterForm::EnterRoomTimerTimer(TObject *Sender)
  312. {
  313.     EnterRoomTimer->Enabled = false;
  314.     HWND win = NULL;
  315.     win =FindWindow(NULL, "VS竞技游戏平台"); 
  316.     if(win){
  317.         HWND activewin = GetActiveWindow();
  318.         SetActiveWindow(win);
  319.         keybd_event(VK_ESCAPE ,0,KEYEVENTF_EXTENDEDKEY   |   0,0   ); 
  320.         keybd_event(VK_ESCAPE ,0,KEYEVENTF_EXTENDEDKEY   |   KEYEVENTF_KEYUP,0);
  321.         SetActiveWindow(activewin);
  322.     }
  323.     win =FindWindow(NULL, "VSClient");
  324.     if(win){
  325.         HWND activewin = GetActiveWindow();
  326.         SetActiveWindow(win);
  327.         keybd_event(VK_ESCAPE ,0,KEYEVENTF_EXTENDEDKEY   |   0,0   );
  328.         keybd_event(VK_ESCAPE ,0,KEYEVENTF_EXTENDEDKEY   |   KEYEVENTF_KEYUP,0);
  329.         SetActiveWindow(activewin);
  330.     }
  331.     EnterRoomTimer->Enabled = true;
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TVSEnterForm::btnUpdateRoomListClick(TObject *Sender)
  335. {
  336.     Init();
  337.     Roomlist->Items->BeginUpdate();
  338.     Roomlist->Items->Clear();
  339.     SetRoomList();
  340.     Roomlist->Items->EndUpdate();
  341. }
  342. //---------------------------------------------------------------------------
  343. void  __fastcall TVSEnterForm::Init(void)
  344. {
  345.     EnterRoomTimer->Enabled = false;
  346.     TrayIcon1->Animate = false;
  347.     AdvCircularProgress1->Enabled = false;
  348. }
  349. //---------------------------------------------------------------------------
  350. void  __fastcall TVSEnterForm::EnterRoom(void)
  351. {
  352.     //找到VS进程号
  353.     static int roomindex = 0;
  354.     DWORD vspid;
  355.     HANDLE vsproc;
  356.     LRESULT msg_result = 0;
  357.     POINT itempos;
  358.     void* itempospt = NULL;
  359.     void* vsroomitemdes = NULL;
  360.     LVITEM iconlabel;
  361.     try{
  362.         //打开VS进程,创建通信内存区域
  363.         bool find = false;
  364.         GetWindowThreadProcessId(VSMainWin, &vspid);
  365.         vsproc = OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, vspid);
  366.         if(vsproc == NULL)throw(GetLastError());
  367.         itempospt = AllocMemInForeignProcess(vsproc, sizeof(POINT));
  368.         vsroomitemdes = AllocMemInForeignProcess(vsproc, sizeof(LVITEM));
  369.         for(int i = roomindex ; i < Roomlist->Items->Count ; i++){
  370.             if(Roomlist->Items->Item[i]->Checked){
  371.                 find = true;
  372.                 iconlabel.state = LVIS_SELECTED|LVIS_FOCUSED;
  373.                 iconlabel.mask = LVIF_STATE;
  374.                 WriteToForeignProcessMemory(vsproc, vsroomitemdes, &iconlabel, sizeof(LVITEM));
  375.                 msg_result = SendMessage(VSRoomList, LVM_SETITEMSTATE, i, (LPARAM)vsroomitemdes);
  376.                 if(msg_result < 0){
  377.                     break;
  378.                 }
  379.                 msg_result = SendMessage(VSRoomList, LVM_GETITEMPOSITION, i, reinterpret_cast<LPARAM>(itempospt));
  380.                 if(msg_result != TRUE){
  381.                     break;
  382.                 }
  383.                 ReadFromForeignProcessMemory(vsproc, itempospt, &itempos, sizeof(POINT));
  384.                 roomindex  = i+1;
  385.                 ::ClientToScreen(VSRoomList,&itempos);
  386.                 SetCursorPos(itempos.x+10,itempos.y+5);
  387.                 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  388.                 mouse_event(MOUSEEVENTF_LEFTUP  ,0,0,0,0);
  389.                 Sleep(10);
  390.                 SendMessageCallback(VSRoomList,WM_LBUTTONDBLCLK,MK_LBUTTON,MAKELPARAM(itempos.x,itempos.y),(SENDASYNCPROC)VSEnterSendAsyncProc,0);
  391.                 break;
  392.             }
  393.         }
  394.         if(!find){
  395.             roomindex = 0;
  396.             for(int i = roomindex ; i < Roomlist->Items->Count ; i++){
  397.                 if(Roomlist->Items->Item[i]->Checked){
  398.                     find = true;
  399.                     iconlabel.state = LVIS_SELECTED|LVIS_FOCUSED;
  400.                     iconlabel.mask = LVIF_STATE;
  401.                     WriteToForeignProcessMemory(vsproc, vsroomitemdes, &iconlabel, sizeof(LVITEM));
  402.                     msg_result = SendMessage(VSRoomList, LVM_SETITEMSTATE, i, (LPARAM)vsroomitemdes);
  403.                     if(msg_result < 0){
  404.                         break;
  405.                     }
  406.                     msg_result = SendMessage(VSRoomList, LVM_GETITEMPOSITION, i, reinterpret_cast<LPARAM>(itempospt));
  407.                     if(msg_result != TRUE){
  408.                         break;
  409.                     }
  410.                     ReadFromForeignProcessMemory(vsproc, itempospt, &itempos, sizeof(POINT));
  411.                     roomindex  = i+1;
  412.                     ::ClientToScreen(VSRoomList,&itempos);
  413.                     SetCursorPos(itempos.x+10,itempos.y+5);
  414.                     mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  415.                     mouse_event(MOUSEEVENTF_LEFTUP  ,0,0,0,0);
  416.                     Sleep(10);
  417.                     SendMessageCallback(VSRoomList,WM_LBUTTONDBLCLK,MK_LBUTTON,MAKELPARAM(itempos.x,itempos.y),(SENDASYNCPROC)VSEnterSendAsyncProc,0);
  418.                     break;
  419.                 }
  420.             }
  421.         }
  422.         //清空所有的东西
  423.         if(itempospt) FreeMemInForeignProcess(vsproc, itempospt);
  424.         CloseHandle(vsproc);
  425.     }catch(DWORD error){
  426.         //清空所有的东西
  427.         delete itempospt;
  428.         if(vsproc){
  429.             if(itempospt) FreeMemInForeignProcess(vsproc, itempospt);
  430.             CloseHandle(vsproc);
  431.         }
  432.         //Rethrow the original error.
  433.         throw error;
  434.     }
  435. }
  436. //---------------------------------------------------------------------------
  437. VOID CALLBACK VSEnterSendAsyncProc(HWND hwnd,UINT uMsg,DWORD dwData,LRESULT lResult)
  438. {
  439.     VSEnterForm->EnterRoom();
  440. }