1,216
社区成员
发帖
与我相关
我的任务
分享
'根据窗口句柄得到应用程序的路径
Public Function AppPath(Optional ByVal hwn1) As String
Dim dwProcessID As Long, hProcess As Long, hModule As Long
Dim nSize As Long
If IsMissing(hwn1) Then '如果没写则表示处理当前存储的句柄
If hWnd_ > 0 Then dwProcessID = ProcessID() 'GetWindowThreadProcessId hWnd_, dwProcessID
Else
dwProcessID = ProcessID(hwn1)
End If
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, dwProcessID)
AppPath = Space(255)
nSize = GetModuleFileNameEx(hProcess, 0, StrPtr(AppPath), 255)
AppPath = Mid(AppPath, 1, nSize)
Call CloseHandle(hProcess)
End Function
通过WindowFromPoint得到的句柄(不用管控件还是窗口的)可以直接传入这个函数得到程序路径。相关api函数和常数声明自己补充。 函数是摘自clswindow类,如果懒得找声明可以直接下载,然后调用。