GetWindowThreadProcessId

来源:百度知道 编辑:UC知道 时间:2024/07/05 04:15:01
谁能给我一个使用GetWindowThreadProcessId的例子,越简单越好,谢谢

Option Explicit

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Command1_Click()
Dim pName As String
pName = "我的电脑"
Dim pNameHWND As Long
pNameHWND = FindWindow(vbNullString, pName)
Dim WTP As Long
WTP = GetWindowThreadProcessId(pNameHWND, vbNull)
MsgBox "窗口句柄:" & CStr(pNameHWND) & vbCrLf & vbCrLf & "进程id:" & CStr(WTP)
End Sub

获得创建 我的电脑 窗口的进程ID。

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long,