实现绑架其它程序 Form1 里有个 Panel1, Button1 .请教,如何实现以下功能:?1、点击BUTTON1调用一个外部程序,如notepad.exe;2、使得notepad.exe的Parent := panel1.handel ,也就是使得 notepad.exe 运行在 Pancel1 里面;3、notepad.exe 最大化后,尺寸为Pancel1 的尺寸。这三点如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 hwndNotePad:=FindWindow(PChar('Notepad'),0);hwndOldParent:=GetParent(hwndNotePad);Windows.SetParent(hwndNotePad,panel1.handle);退出时Windows.SetParent(hwndNotePad,hwndOldParent); 是可以的,我以前有这样一段程序,但后来硬盘坏了^^^^foolishidea(foolishidea)就是这样,但你的实现不了.第一句始终返加 0 SORRYfoolishidea(foolishidea)你的程序是 OK 的,但我要求是要程序启动另一程序,且将它"绑架"。 可以,我做过一个可以多张打印玉兰的报表系统,就是把reportmachine的打印玉兰窗口动态生成N个然后绑架到pagecontrol的tabsheets[i].panel里实现多份玉兰,而且和tabsheets[i].panel同大 FRMPreviewForms[N]:=TRMPreviewForm.Create(Self); FPanels[N]:=TPanel.Create(Self); FTabSheets[N]:=TTabSheet.Create(Self); FTabSheets[N].PageControl:=Box.PageControl1; Box.PageControl1.Pages[N].Tag:=FRMPreviewForms[N].Handle; FTabSheets[N].Caption:='['+FieldByName(TName.FieldName).AsString+']'; FPanels[N].Parent:=FTabSheets[N]; FPanels[N].BorderStyle:=bsNone; FPanels[N].BevelInner:=bvNone; FPanels[N].BevelOuter:=bvNone; FPanels[N].Left:=0; FPanels[N].Top:=0; FPanels[N].Width:=FTabSheets[N].ClientWidth; FPanels[N].Height:=FTabSheets[N].ClientHeight; Windows.SetParent(FRMPreviewForms[N].Handle,FPanels[N].Handle); FRMPreviewForms[N].Show; SetWindowPos(FRMPreviewForms[N].Handle,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW+SWP_NOSIZE); FRMPreviewForms[N].Left:=0; FRMPreviewForms[N].Top:=0; FRMPreviewForms[N].Width:=FPanels[N].ClientWidth; FRMPreviewForms[N].Height:=FPanels[N].ClientHeight; note 应该是一个道理,只要能find handle就都一样 -------问题已解决,可惜只能用于简单的程序,不能用于类似 WORD 、DELPHI 等有欢迎窗口的程序。-------unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type PEnumInfo = ^TEnumInfo; TEnumInfo = record ProcessID : DWORD; HWND : THandle;end;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Button2: TButton; Label5: TLabel; OpenDialog1: TOpenDialog; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; hwndOldParent,hwndNotePad : integer;implementation{$R *.dfm}{====================用于取得启动程序句柄====================}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;//用于 NOTEPADprocedure TForm1.Button1Click(Sender: TObject);begin hwndNotePad:=FindWindow(PChar(Edit1.Text),0); if hwndNotePad = 0 then Showmessage('没找到') else begin hwndOldParent:=GetParent(hwndNotePad); Windows.SetParent(hwndNotePad,handle); end;end;procedure TForm1.FormDestroy(Sender: TObject);begin Windows.SetParent(hwndNotePad,hwndOldParent);end;用于我的程序自选启动的程序procedure TForm1.Button2Click(Sender: TObject);var SI : TStartupInfo; PI : TProcessInformation; H : THandle; S : String; EXEFileName : String;begin if not OpenDialog1.Execute then exit; EXEFileName := OpenDialog1.FileName; ZeroMemory(@SI, SizeOf(SI)); ZeroMemory(@PI, SizeOf(PI)); SI.cb := SizeOf(SI); if CreateProcess(nil,PChar(EXEFileName), nil, nil, FALSE, 0 ,nil,nil, SI, PI) then begin //注意! WaitForInputIdle(PI.hProcess, INFINITE); H := FindMainWindow(PI.dwProcessID); if H > 0 then begin SetLength(S, 255); GetWindowText(H, PChar(S), 255); SetLength(S, StrLen(PChar(S))); //绑架 hwndOldParent:=GetParent(H); Windows.SetParent(H,handle); ShowMessage(S); end; CloseHandle(PI.hProcess); CloseHandle(PI.hThread); end;end;end. 软件是如何进行通信的? 求一种类似坐标纸的控件! (转)Microsoft程序员测试题 dbf一个棘手问题 Rave到底是怎么回事阿? 如何侦测鼠标离开控件的事件,如TLabel的OnMouseLeave我想写一个类似金山取词窗的东西,当鼠标离开控件的时候隐藏控件 一个TEdit有什么方法可以让它可以让每个英文单词的颜色都不相同 DEPHI5在连接数据库时(用ODBC连接)有会出现EOF,BOF的问题,送60分 怎样实现不用BDE而用ADO登录SQL SERVER库??? case 語句的問題...worry 如何判断日期的正确性? 关于串口通讯问题,请高手帮助看下面的代码为何得不到返回数据
hwndOldParent:=GetParent(hwndNotePad);
Windows.SetParent(hwndNotePad,panel1.handle);退出时
Windows.SetParent(hwndNotePad,hwndOldParent);
就是这样,但你的实现不了.第一句始终返加 0
foolishidea(foolishidea)
你的程序是 OK 的,
但我要求是要程序启动另一程序,且将它"绑架"。
FRMPreviewForms[N]:=TRMPreviewForm.Create(Self);
FPanels[N]:=TPanel.Create(Self);
FTabSheets[N]:=TTabSheet.Create(Self);
FTabSheets[N].PageControl:=Box.PageControl1;
Box.PageControl1.Pages[N].Tag:=FRMPreviewForms[N].Handle;
FTabSheets[N].Caption:='['+FieldByName(TName.FieldName).AsString+']';
FPanels[N].Parent:=FTabSheets[N];
FPanels[N].BorderStyle:=bsNone;
FPanels[N].BevelInner:=bvNone;
FPanels[N].BevelOuter:=bvNone;
FPanels[N].Left:=0;
FPanels[N].Top:=0;
FPanels[N].Width:=FTabSheets[N].ClientWidth;
FPanels[N].Height:=FTabSheets[N].ClientHeight; Windows.SetParent(FRMPreviewForms[N].Handle,FPanels[N].Handle); FRMPreviewForms[N].Show; SetWindowPos(FRMPreviewForms[N].Handle,HWND_TOP,0,0,0,0,SWP_SHOWWINDOW+SWP_NOSIZE); FRMPreviewForms[N].Left:=0;
FRMPreviewForms[N].Top:=0;
FRMPreviewForms[N].Width:=FPanels[N].ClientWidth;
FRMPreviewForms[N].Height:=FPanels[N].ClientHeight;
问题已解决,可惜只能用于简单的程序,不能用于类似 WORD 、DELPHI 等有欢迎窗口的程序。
-------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID : DWORD;
HWND : THandle;
end;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
Label5: TLabel;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hwndOldParent,hwndNotePad : integer;implementation{$R *.dfm}
{
====================
用于取得启动程序句柄
====================
}
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;//用于 NOTEPAD
procedure TForm1.Button1Click(Sender: TObject);
begin
hwndNotePad:=FindWindow(PChar(Edit1.Text),0);
if hwndNotePad = 0 then
Showmessage('没找到')
else begin
hwndOldParent:=GetParent(hwndNotePad);
Windows.SetParent(hwndNotePad,handle);
end;end;procedure TForm1.FormDestroy(Sender: TObject);
begin
Windows.SetParent(hwndNotePad,hwndOldParent);
end;用于我的程序自选启动的程序
procedure TForm1.Button2Click(Sender: TObject);
var
SI : TStartupInfo;
PI : TProcessInformation;
H : THandle;
S : String; EXEFileName : String;
begin
if not OpenDialog1.Execute then exit;
EXEFileName := OpenDialog1.FileName;
ZeroMemory(@SI, SizeOf(SI));
ZeroMemory(@PI, SizeOf(PI));
SI.cb := SizeOf(SI);
if CreateProcess(nil,PChar(EXEFileName), nil, nil, FALSE, 0 ,nil,nil, SI, PI) then
begin
//注意!
WaitForInputIdle(PI.hProcess, INFINITE); H := FindMainWindow(PI.dwProcessID);
if H > 0 then
begin
SetLength(S, 255);
GetWindowText(H, PChar(S), 255);
SetLength(S, StrLen(PChar(S)));
//绑架
hwndOldParent:=GetParent(H);
Windows.SetParent(H,handle); ShowMessage(S);
end; CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
end;
end;end.