Position := Img_Dropper.ClientToScreen(RelPosition);
WindowHandle := WindowFromPoint(Position);
Modulename := WHandleToFileName(WindowHandle);
Function WHandleToFileName(WindowHandle: hWnd): String;
Var
ProcessID, NumberReturned: DWORD;
ProcessEntry: TProcessEntry32;
hSnapShot: THandle;
Cursor: Boolean;
ProcessHandle: THandle;
ModuleHandle: HMODULE;
RC: Boolean;
ReturnName: Array[0..2048] of char;
Begin
Result := '';
GetWindowThreadProcessId(WindowHandle, @ProcessID);
// Do this based on windows version
if (WinPlatform = 'NT') {AND (WinVersion<5)} then
Begin
ProcessHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE, ProcessID);
RC := EnumProcessModules(ProcessHandle, ModuleHandle, 4, NumberReturned);
if RC then
Begin
GetModuleFilenameEx(ProcessHandle, ModuleHandle, ReturnName, 2048);
Result := ReturnName;
End;
End
Else
Begin
hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, ProcessID);
ProcessEntry.dwSize := SizeOf(ProcessEntry);
Cursor := Process32First(hSnapShot, ProcessEntry);
while (Cursor) do
Begin
if (ProcessEntry.th32ProcessID = ProcessID) then
Begin
Result := ProcessEntry.szExeFile;
break;
End;
Cursor := Process32Next(hSnapShot, ProcessEntry);
End;
CloseHandle(hSnapShot);
End;
End;
Becca
Somtimes, the easy answer is the hardest to find.
Still under construction ...