Visual Basic 6 Получить путь к exe файлу активного окна - VB
Формулировка задачи:
Люди, что мне в код добавить, чтобы он еще показывал путь к exe файлу этого окна ?
Решение задачи: «Visual Basic 6 Получить путь к exe файлу активного окна»
textual
Листинг программы
Private Declare Function FindWindow Lib "user32" Alias "FindWindowW" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExW" (lpVersionInformation As Any) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function QueryFullProcessImageName Lib "kernel32" Alias "QueryFullProcessImageNameW" (ByVal hProcess As Long, ByVal dwFlags As Long, ByVal lpExeName As Long, lpdwSize As Long) As Long Private Sub Form_Load() Dim hwnd As Long Dim lr As Long Dim pid As Long hwnd = FindWindow(ByVal 0&, StrPtr("Calculator")) If hwnd <> 0 Then lr = GetWindowThreadProcessId(hwnd, pid) MsgBox GetProcessNameByPID(pid) Else MsgBox "No window." End If End Sub Function GetProcessNameByPID(pid As Long) As String Const PROCESS_QUERY_LIMITED_INFORMATION As Long = &H1000 Const PROCESS_QUERY_INFORMATION As Long = &H400 Const MAX_PATH As Long = 260 Dim hProc As Long Dim Path As String Dim lStr As Long Dim inf(68) As Long Dim IsVistaAndLater As Boolean inf(0) = 276: GetVersionEx inf(0): IsVistaAndLater = inf(1) >= 6 If Not IsVistaAndLater Then Exit Function hProc = OpenProcess(IIf(IsVistaAndLater, PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_QUERY_INFORMATION), False, pid) If hProc <> 0 Then 'INVALID_HANDLE_VALUE Then lStr = MAX_PATH Path = Space(lStr) ' minimum Windows Vista !!!!!!! If QueryFullProcessImageName(hProc, 0, StrPtr(Path), lStr) Then GetProcessNameByPID = Left$(Path, lStr) End If CloseHandle hProc End If End Function
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д