vb.net中的API GetWindowThreadProcessId 怎么用?
发布网友
发布时间:2024-10-10 12:47
我来回答
共2个回答
热心网友
时间:2024-11-23 21:34
试试这段代码,测试正确:
Mole Mole1
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Sub Main()
Dim pid As Integer, rtv As Integer, xlapp As Object
xlapp = CreateObject("excel.application")
rtv = GetWindowThreadProcessId(xlapp.hwnd, pid)
MsgBox(pid)
MsgBox(xlapp.hwnd)
xlapp.quit()
End Sub
End Mole
热心网友
时间:2024-11-23 21:34
Public Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, <Out> ByRef lpdwProcessId As Integer) As Long
Dim pid As Integer = 0
GetWindowThreadProcessId(officeApplication.HWnd, pid)
这样声明,才能正确获取ProcessId