7,762
社区成员
发帖
与我相关
我的任务
分享
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
' Return PID
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long, pid As Long
On Error GoTo errr
tempHwnd = FindWindow(vbNullString, vbNullString)
Do Until tempHwnd = 0
If GetParent(tempHwnd) = 0 Then
pid = ProcIDFromWnd(tempHwnd)
If hInstance = pid Then
GetWinHandle = tempHwnd
Exit Do
End If
End If
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
errr:
End Function
Public Function hwndShell(fname As String, Optional gs As String) As Long
Dim hInst As Long
Dim s As String, s2 As String, s3 As String, p As Long, p2 As Long
On Error GoTo errr
Select Case gs
Case "exe"
s = fname
Case Else
s2 = String(260, vbNullChar)
p = FindExecutable(fname & vbNullChar, vbNullString, s2)
If p > 31 Then
p2 = InStr(1, s2, vbNullChar)
s3 = Left(s2, p2 - 1)
s = s3 & " " & fname
End If
End Select
If s <> "" Then
hInst = Shell(s, vbNormalFocus)
If hInst Then hwndShell = GetWinHandle(hInst)
errr:
End Function