delphi 调用 EXE 并在Panle中运行

求助 delphi 调用外部EXE文件 并在Panle中运行谢谢回复,,,,,, 能给个实例吗?gentleman66@qq.com

界面上就4个常用控件,全部的代码在此,自己照着代码加控件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
PProcessWindow = ^TProcessWindow;
TProcessWindow = record
TargetProcessID: Cardinal;
FoundWindow: hWnd;
end;
TForm1 = class(TForm)
Button1: TButton;
OpenD: TOpenDialog;
Panel1: TPanel;
Splitter1: TSplitter;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hWin: HWND = 0;
implementation
{$R *.dfm}

function EnumWindowsProc(Wnd: hWnd; ProcWndInfo: PProcessWindow): BOOL; stdcall;
var
WndProcessID: Cardinal;
begin
GetWindowThreadProcessId(Wnd, @WndProcessID);
if WndProcessID = ProcWndInfo^.TargetProcessID then begin
ProcWndInfo^.FoundWindow := Wnd;
Result := False; // This tells EnumWindows to stop enumerating since we've already found a window.
end else Result := True; // Keep searching
end;
function GetProcessWindow(TargetProcessID: Cardinal): hWnd;
var
ProcWndInfo: TProcessWindow;
begin
ProcWndInfo.TargetProcessID := TargetProcessID;
ProcWndInfo.FoundWindow := 0;
EnumWindows(@EnumWindowsProc, Integer(@ProcWndInfo));
Result := ProcWndInfo.FoundWindow;
end;
function RunAppInPanel(const AppName: string; PanelHandle: HWND): boolean;
var
si: STARTUPINFO;
pi: TProcessInformation;
begin
FillChar(si, SizeOf(si), 0);
si.cb := SizeOf(si);
si.wShowWindow := SW_SHOW;
result := CreateProcess(nil, PChar(AppName), nil,
nil, true, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, si, pi);
if not result then exit;
WaitForInputIdle(pi.hProcess, 10000); // let process start!
hWin := GetProcessWindow(pi.dwProcessID);
if hWin > 0 then begin
Windows.SetParent(hWin, PanelHandle);
SetWindowPos(hWin, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
result := true;
end;
// we don't need the handles so we close them
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenD.Execute then begin
if hWin > 0 then PostMessage(hWin, WM_CLOSE, 0, 0); // close any app currently opened
if not RunAppInPanel(OpenD.FileName, Panel1.Handle) then ShowMessage('App not found');
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hWin > 0 then
PostMessage(hWin, WM_CLOSE, 0, 0);
end;
end.
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-12-23
在uses 中使用ShellAPI;
加一个button; onClick事件
ShellExecute(handle, 'open ', '盘符路径:\project1.exe ', Nil, Nil, SW_SHOWNORMAL);

WinExec( 'project1.exe ',1);
不过这是外部调用,怎么在panel中运行,就不知道了!

delphi 调用 EXE 并在Panle中运行
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls, ExtCtrls;type PProcessWindow = ^TProcessWindow;TProcessWindow = record TargetProcessID: Cardinal;FoundWindow: hWnd;end;TForm1 = class(TForm)Button1: TButton;OpenD: TOpenDialog;Panel1: ...

如何在delphi 中调用 DLL中的窗体,并且把这个窗体嵌套在TPanel中?
把panel传到DLL里,并设置窗体的parent为panel就行了。不过建议不要这么做,因为会有一些比较麻烦的问题出现。

...控件进入panel控件中时产生磁性效果,并在panel中自动排列?
你可以设置align属性 拖动img 设置 align 为alnone 放下后还原

delphi中如何将一个窗口添加进panel中去?拜托各位了 3Q
是JPanel 类的方法 是把button这个实例添加到 JPanel实例中(相当与VB Delphi 中将 一个Button 托进一个 Panel) button.addMouseListener(new MouseAdapter(){\/\/这里的鼠标事件监听是不是必须要加,才能实现隐藏鼠标的效果? 看你需不需要了,通常如果想用鼠标操作 是要加的 还有不是隐藏鼠标 publi...

请问delphi窗体显示在panel中,屏幕抖动如何解决?
窗体属性中 visable=false ,然后在panel中显示的时候设置为true就可以了。平滑过渡。

请问delphi 的panel 怎么移动啊,就在自己的窗口中移动,不要超出窗口...
Panel2: TPanel;procedure FormCreate(Sender: TObject);procedure Timer1Timer(Sender: TObject);private { Private declarations } public { Public declarations } end;var Form1: TForm1;\/\/ 移动时的偏移值 Xadd: Shortint = 1;Yadd: Shortint = 1;implementation {$R *.dfm} procedure ...

delphi中在panel控件上怎样再加panel控件并让子panel控件完全位于主panel...
把第二个panel的Align属性设置为altop

delphi中怎样判断鼠标是否在panel范围内? panel里含有button等其他控 ...
你可以捕捉鼠标在当前界面或者窗体的位置,然后根据panel的top或者left去判断

Delphi中MediaPlayer控件的使用
Execute then begin Mediaplayer1.FileName :=Opendialog1.FileName;Mediaplayer1.Open;Mediaplayer1.Play ;end;end;还有如果想在panel这种容器控件中播放的话先在属性中设置DisPlay属性 转移播放窗口 然后在MediaPlayer1.Play后面加一句 MediaPlayer1.DisplayRect := Panel1.ClientRect;...

delphi中MediaPlayer控件怎么用
1.open方法:open方法用于打开一个多媒体设备。在调用该方法之前,必须确保在MediaPlayer组件的DeviceType(设备类型)属性中设定正确的多媒体设备类型。【示例】以下代码用于在程序开始运行时就播放CD音乐。procedureTForm1.FormCreat(Sender:Tobject);begin with MediaPlayer1 do begin DeviceType:=dtC...

相似回答