ورود

View Full Version : نحوه دسترسی به هندل



parhizkar2000
شنبه 06 تیر 1383, 17:28 عصر
برای دسترسی به هندل یک برنامه چیکار باید کرد و نوع متغیرش چیه کلا در این مورد اطلاعاتی هر کی داره ممنون میشم ارایه بده

پسر خاک
شنبه 06 تیر 1383, 17:56 عصر
سلام



procedure TForm1.Button1Click(Sender: TObject);
var
hNotepadWindow: HWND;
begin
hNotepadWindow := FindWindow('notepad', nil);
end;




procedure TForm1.Button1Click(Sender: TObject);
var
hWordWindow: HWND;
begin
hWordWindow := FindWindow ('OpusApp', nil);
ShowWindow(hWordWindow, SW_HIDE);
Sleep(2000);
ShowWindow(hWordWindow, SW_SHOW);
end;




procedure TForm1.Button1Click(Sender: TObject);
var
hIExplorer: HWND;
begin
hIExplorer := FindWindow('IEFrame', nil);
if hIExplorer <> 0 then
begin
// Minimize IE:
SendMessage(hIExplorer, WM_SYSCOMMAND, SC_MINIMIZE, 0);
// Close IE:
SendMessage(hIExplorer, WM_SYSCOMMAND, SC_CLOSE, 0);
end;
end;




function FindWindowByTitle(WindowTitle: string): Hwnd;
var
NextHandle: Hwnd;
NextTitle: array[0..260] of char;
begin
// Get the first window
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
// retrieve its text
GetWindowText(NextHandle, NextTitle, 255);
if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
begin
Result := NextHandle;
Exit;
end
else
// Get the next window
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;




procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
begin
h := FindWindowByTitle('notepad');
if h <> 0 then // if we found notepad
ShowWindow(h, SW_MAXIMIZE)
else
ShowMessage('not found.');
end;




procedure TForm1.Button1Click(Sender: TObject);
var
FoundWindow: HWND;
WindowText: array[0..255] of char;
begin
{Find a TButton child window}
FoundWindow := FindWindowEx(Form1.Handle, 0, 'TButton', nil);
{Get its text}
GetWindowText(FoundWindow, WindowText, 255);
{Display it}
label1.Caption := 'FindWindowEx found window handle ' +
IntToStr(FoundWindow) + ': ' + WindowText;
end;


function FindControlByNumber(hApp: HWND; ControlClassName: string; ControlNr: Word = 1): HWND;
var
i: Word;
hControl: HWND;
begin
Result := 0;
if IsWindow(hApp) then
begin
Dec(ControlNr);
hControl := 0;
for i := 0 to ControlNr do
begin
hControl := FindWindowEx(hApp, hControl, PChar(ControlClassName), nil);
if hControl = 0 then
Exit;
end;
end;
Result := hControl;
end;




procedure SetEditText(hApp: HWND; EditClassName, AText: string; EditNr: Integer);
var
hEdit: HWND;
begin
// Search for the 2. Edit Field in a application
hEdit := FindControlByNumber(FindWindow('Write_Here_Class_O f_App', nil), 'Edit', 2);
if hEdit <> 0 then
// Test: Send a "Hello" to the Edit Field
SendMessage(hEdit, WM_SETTEXT, 0, Integer(PChar('Hello')));
end;





function EnumWindowsProc(wHandle: HWND; lb: TListBox): Bool; stdcall; export;
var
Title, ClassName: array[0..255] of char;
begin
Result := True;
GetWindowText(wHandle, Title, 255);
GetClassName(wHandle, ClassName, 255);
if IsWindowVisible(wHandle) then
lb.Items.Add(string(Title) + '-' + string(ClassName));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc, Integer(Listbox1));
end;