
22.09.2011, 07:56
|
Так проходящий
|
|
Регистрация: 18.07.2011
Сообщения: 805
Версия Delphi: 7Lite
Репутация: 6063
|
|
поиск по части заголовка и имени exe:
FindWindow777('opera') ;
FindWindow777('torrent', 'utorrent.exe') ;
PHP код:
uses psapi;
var
FoundHandle: Cardinal;
Match: string;
exetofind: string;
function FindWindow777(TitlePart: string; exename: string = ''): Cardinal;
function Enumka(h: hWnd; p: Pointer): BOOL; stdcall; var s1, s2: string;
function GetModule(h: hWnd): string;
var
Module: string;
shit1: Cardinal;
function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := '';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end
finally
CloseHandle(Handle);
end;
end;
begin
GetWindowThreadProcessId(h, shit1);
result := ProcessFileName(shit1);
end;
function GetCaption(h: hWnd): string;
var
Caption: array[0..255] of char;
begin
FillChar(Caption, sizeof(Caption), 0);
GetWindowText(h, Caption, 255);
result := strpas(Caption);
end;
begin
result := true;
if Pos(LowerCase(Match), LowerCase(GetCaption(h))) > 0 then
if exetofind = '' then
begin
FoundHandle := h;
result := false;
end else {begin
s1 := GetModule(h);
s2 := GetCaption(h) ; }
if exetofind = ExtractFileName(GetModule(h)) then
begin
FoundHandle := h;
result := false;
end; {end; }
end;
begin
exetofind := exename;
FoundHandle := INVALID_HANDLE_VALUE;
Match := TitlePart;
EnumWindows(@Enumka, 0);
result := FoundHandle;
end;
|