ألق نظرة هنا
Host a process window inside your applications window
الكود مكتوب بـ سي شارب
الجزء المهم منه الدالة SetParent
Host a process window inside your applications window
الكود مكتوب بـ سي شارب
الجزء المهم منه الدالة SetParent
PHP كود :
function GetMainWindowHandleByPID(const PID: THandle): THandle;
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID: DWORD;
HWND: THandle;
end;
function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall;
var
PID: DWORD;
begin
GetWindowThreadProcessID(Wnd, @PID);
Result := (PID <> EI.ProcessID) or
(not IsWindowVisible(WND)) or
(not IsWindowEnabled(WND));
if not Result then
EI.HWND := WND;
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI: TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
EnumWindows(@EnumWindowsProc, Integer(@EI));
Result := EI.HWND;
end;
begin
if PID <> 0 then
Result := FindMainWindow(PID)
else
Result := 0;
end;
procedure LoadApplication(const Path: string; hParent: THandle);
var
SI: TStartupInfo;
PI: TProcessInformation;
MainWindow: THandle;
begin
FillChar(SI, SizeOf(TStartupInfo), #0);
if CreateProcess(PChar(Path), nil, nil, nil, True, 0, nil, nil, SI, PI) then
begin
Sleep(500);
MainWindow := GetMainWindowHandleByPID(PI.dwProcessId);
end;
SetParent(MainWindow, hParent); // Set the process parent window to the window we want
SetWindowPos(MainWindow, 0, 0, 0, 0, 0, $0001 or $0040); // Place the window in the top left of the parent window without resizing it
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadApplication('c:\windows\system32\notepad.exe', Form1.Handle);
end;
سبحان الله وبحمده سبحان الله العظيم

