function FindProcessName:THandle; var lppe: tprocessentry32; sshandle: thandle; found: boolean; begin result:=0; sshandle := createtoolhelp32snapshot(TH32CS_SNAPALL, 0); found := process32first(sshandle, lppe); while found do begin if ansiCompareText(ExtractFileName(lppe.szExefile),'EXPLORER.EXE') = 0 then begin result:=lppe.th32ProcessID; break; end; found := process32next(sshandle, lppe); end; CloseHandle(sshandle); end;
楼上找的是进程IDfunction lpEnumFunc(H: HWND): Boolean; stdcall; var P, p2: array[0..255] of Char; begin GetClassName(H, P, 256); if Strpas(P) = 'IEFrame' then begin GetWindowText(H, p2, 256); Form1.Memo1.Lines.add('句柄为: ' + IntToHex(H, 16) + ' 窗口名:' + p2); end; result := True; end;procedure TForm1.BitBtn2Click(Sender: TObject); var Str: TStringList; i: integer; begin Str := TstringList.Create; EnumWindows(@lpEnumFunc, LongInt(Str)); Str.Free; end;
procedure TForm1.BitBtn2Click(Sender: TObject); begin EnumWindows(@lpEnumFunc, 0); end;
function FindProcessName:THandle;
var
lppe: tprocessentry32;
sshandle: thandle;
found: boolean;
begin
result:=0;
sshandle := createtoolhelp32snapshot(TH32CS_SNAPALL, 0);
found := process32first(sshandle, lppe);
while found do
begin
if ansiCompareText(ExtractFileName(lppe.szExefile),'EXPLORER.EXE') = 0 then
begin
result:=lppe.th32ProcessID;
break;
end;
found := process32next(sshandle, lppe);
end;
CloseHandle(sshandle);
end;
var
P, p2: array[0..255] of Char;
begin
GetClassName(H, P, 256);
if Strpas(P) = 'IEFrame' then
begin
GetWindowText(H, p2, 256);
Form1.Memo1.Lines.add('句柄为: ' + IntToHex(H, 16) + ' 窗口名:' + p2);
end;
result := True;
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
Str: TStringList;
i: integer;
begin
Str := TstringList.Create;
EnumWindows(@lpEnumFunc, LongInt(Str));
Str.Free;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
EnumWindows(@lpEnumFunc, 0);
end;