GetWindowThreadProcessId返回的是线程id,第2个参数返回的值才是pid。 如: Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Sub Form_Load() Dim Pid As Long GetWindowThreadProcessId Me.hwnd, Pid MsgBox Pid End Sub
如:
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Form_Load()
Dim Pid As Long
GetWindowThreadProcessId Me.hwnd, Pid
MsgBox Pid
End Sub