16,555
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
'┏〓〓〓〓〓〓〓〓〓 ProcessIdToHwnd,start 〓〓〓〓〓〓〓〓〓┓
'[定义]:
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, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
'[简介]:
'由进程ID获得该窗口的句柄
Function ProcessIdToHwnd(ByVal ByProcessId As Long) As Long
'[mycode_id:1827],edittime:2010-12-6 下午 07:56:17
Dim Hwnd1 As Long, Pid1 As Long, ThreadId1 As Long
'Find the first window
Hwnd1 = FindWindow(vbNullString, vbNullString)
Do While Hwnd1 <> 0
'Check if the window isn't a child
If GetParent(Hwnd1) = 0 Then
'Get the window's thread
ThreadId1 = GetWindowThreadProcessId(Hwnd1, Pid1)
If Pid1 = ByProcessId Then
ProcessIdToHwnd = Hwnd1
Exit Do
End If
End If
Hwnd1 = GetWindow(Hwnd1, GW_HWNDNEXT)
Loop
'By:应用程序专家
'QQ:1085992075
'http://www.0086ly.com
'欢迎与我们交流编程方面的技术,如果有软件需要开发设计,可以联系我们
End Function
'┗〓〓〓〓〓〓〓〓〓 ProcessIdToHwnd,end 〓〓〓〓〓〓〓〓〓┛
Private Sub Form_Load()
MsgBox ProcessIdToHwnd(5384)
End Sub