Demonx писал(а):Можете напситать код такой, чтобы например есть процесс "iexplorer.exe" и надо узнать его hwnd.
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) 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 ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function NtQueryInformationProcess Lib "ntdll" (ByVal hProcess As Long, ByVal ProcessInformationClass As Long, ProcessInformation As Any, ByVal ProcessInformationLength As Long, ReturnLength As Long) As Long
Private Type PROCESS_BASIC_INFORMATION
ExitStatus As Long
PebBaseAddress As Long 'points to a structure too long to declare
AffinityMask As Long
BasePriority As Long
UniqueProcessId As Long
InheritedFromUniqueProcessId As Long
End Type
Private Type UNICODE_STRING
Length As Integer
MaximumLength As Integer
Buffer As Long
End Type
Private Type RTL_USER_PROCESS_PARAMETERS
MaximumLength As Long
Length As Long
Flags As Long
DebugFlags As Long
ConsoleHandle As Long
ConsoleFlags As Long
StdInputHandle As Long
StdOutputHandle As Long
StdErrorHandle As Long
CurrentDirectoryPath As UNICODE_STRING
CurrentDirectoryHandle As Long
DllPath As UNICODE_STRING
ImagePathName As UNICODE_STRING
CommandLine As UNICODE_STRING
Environment As Long
StartingPositionLeft As Long
StartingPositionTop As Long
Width As Long
Height As Long
CharWidth As Long
CharHeight As Long
ConsoleTextAttributes As Long
WindowFlags As Long
ShowWindowFlags As Long
WindowTitle As UNICODE_STRING
DesktopName As UNICODE_STRING
ShellInfo As UNICODE_STRING
RuntimeData As UNICODE_STRING
DLCurrentDirectory(1 To &H200) As Byte
End Type
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const PROCESS_VM_READ = &H10
Sub Main()
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim PID As Long, hProcess As Long, pbi As PROCESS_BASIC_INFORMATION
Dim ProcessParameters As Long, upp As RTL_USER_PROCESS_PARAMETERS
Dim ImagePathName As String
GetWindowThreadProcessId hWnd, PID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, PID)
If hProcess Then
NtQueryInformationProcess hProcess, 0, pbi, Len(pbi), 0&
ReadProcessMemory hProcess, pbi.PebBaseAddress + 16, ProcessParameters, 4, 0&
ReadProcessMemory hProcess, ProcessParameters, upp, LenB(upp), 0&
ImagePathName = String(upp.ImagePathName.Length \ 2, 0)
ReadProcessMemory hProcess, upp.ImagePathName.Buffer, ByVal StrPtr(ImagePathName), LenB(ImagePathName), 0&
CloseHandle hProcess
If LCase(Right(ImagePathName, 12)) = "iexplore.exe" Then Debug.Print hWnd
End If
EnumWindowsProc = 1
End Function
bevaine2000 писал(а):пожалуйста объясните мне чайнику что и куда вставлять(что на форму, что в модуль)
Сейчас этот форум просматривают: Yandex-бот и гости: 19