完成了 基本介面設置 後,就可以開始寫 Code 囉!
此篇教各位如何 尋找、打開遊戲進程 。
添加程式碼
為了讓 Code 更整潔、好整理,我們先添加個 模組 ,方便後續。
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
點選上方 專案(P) -> 選擇 加入模組(M)...。
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
點擊後,會出現 加入新項目 的視窗,這邊我們選擇 模組,並將 名稱(N) 輸入,再點選 新增(A) 。
完成後,會轉跳至 模組 ->程式碼區 ,這樣就完成了 新增模組 。
貼入程式碼本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
將下方 程式碼貼入模組 最上方。
Imports System.Runtime.InteropServices
將下方 程式碼貼入模組 之中。本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function OpenProcessAPI Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Int32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As Int32
Public Declare Function CloseHandleAPI Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As IntPtr, <Out()> ByRef lpdwProcessId As IntPtr) As Integer
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Integer, ByVal lppe As PROCESSENTRY32) As Integer
Public Declare Function Process32Next Lib "kernel32" (ByVal hSapshot As Integer, ByVal lppe As PROCESSENTRY32) As Integer
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public hWnd, Handlex, pid, hprocess As Integer
Public Inited As Boolean
Public Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUseage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim swFlags As Integer
Dim szExeFile As String
End Structure
Public Function OpenProcess(Optional ByVal lpPID As Long = -1) As Long
If lpPID = 0 And pid = 0 Then Exit Function
If lpPID > 0 And pid = 0 Then pid = lpPID
Handlex = OpenProcessAPI(PROCESS_ALL_ACCESS, False, pid)
OpenProcess = Handlex
If Handlex > 0 Then Inited = True
End Function
Public Function OpenProcessByProcessName(ByVal lpName As String) As Long
Dim PE32 As PROCESSENTRY32
Dim hSnapshot As Long
pid = 0
hSnapshot = CreateToolhelp32Snapshot(2, 0&) 'TH32CS_SNAPPROCESS = 2
PE32.dwSize = Len(PE32)
Process32First(hSnapshot, PE32)
While pid = 0 And CBool(Process32Next(hSnapshot, PE32))
If Right$(LCase$(Left$(PE32.szExeFile, InStr(1, PE32.szExeFile, Chr(0)) - 1)), Len(lpName)) = LCase$(lpName) Then
pid = PE32.th32ProcessID
End If
End While
CloseHandleAPI(hSnapshot)
OpenProcessByProcessName = OpenProcess()
End Function
Public Function OpenProcessByWindow(ByVal lpWindowName As String, Optional ByVal lpClassName As String = vbNullString) As Long
hWnd = FindWindow(lpClassName, lpWindowName)
GetWindowThreadProcessId(hWnd, pid)
OpenProcessByWindow = OpenProcess(pid)
hprocess = OpenProcessAPI(PROCESS_ALL_ACCESS, False, pid)
End Function
即可完成程式碼貼入。
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
基本的遊戲鎖定
模組區 完成後,我們回到 Form 中,繼續撰寫最基本的 遊戲鎖定。
雙擊我們的 Button 進入 程式撰寫區。
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
並貼上以下程式碼。
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
'遊戲鎖定區
OpenProcessByWindow("MapleStory", "StartUpDlgClass")
If pid <> 0 Then
MsgBox("遊戲鎖定成功囉!", 64, "FirstProject_Tipe")
Else
MsgBox("鎖定遊戲失敗!", 16, "FirstProject_Error")
End If
本站作者:米粒 本站網址:http://bps1331.blogspot.tw/
即可完成基本的 遊戲鎖定,
註:程式僅支持在Play頁面進行鎖定。
vb2010沒有欸
回覆刪除