需要VBAPI函數:
FindWindow←尋找窗口列表中第一個符合指定條件的頂級窗口
GetWindowThreadProcessId←獲取與指定窗口關聯在一起的一個進程和線程標識符
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
FindWindow
↓
PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong
GetWindowThreadProcessId
↓
PrivateDeclareFunctionGetWindowThreadProcessIdLib"user32"(ByValhwndAsLong,lpdwProcessIdAsLong)
AsLong
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控件:Label、Timer
--------------------------------------------------------------------------------------------------------------------------------------------------------自定義函數:
DimhwndAsLong
--------------------------------------------------------------------------------------------------------------------------------------------------------源代碼:
PrivateDeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong
PrivateDeclareFunctionGetWindowThreadProcessIdLib"user32"(ByValhwndAsLong,lpdwProcessIdAsLong)AsLong
PrivateSubTimer1_Timer()
DimhwndAsLong'儲存FindWindow函數返回的句柄
hwnd=FindWindow(vbNullString,"WindowsMediaPlayer")'取得進程標識符
'只要把WindowsMediaPlayer換成游戲的名稱就可了!
Ifhwnd=0Then
Label1.Caption="游戲未運行"
Else
Label1.Caption="游戲已運行"
EndIf
EndSub
->