delphi 调用 EXE 并在Panle中运行

求助delphi调用外部EXE文件并在Panle中运行谢谢回复,,,,,,能给个实例吗?gentleman66@qq.com... 求助 delphi 调用外部EXE文件 并在Panle中运行谢谢回复,,,,,, 能给个实例吗?gentleman66@qq.com 展开
 我来答
googleyeyou
2010-12-23 · TA获得超过186个赞
知道小有建树答主
回答量:269
采纳率:100%
帮助的人:129万
展开全部
界面上就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.
ztfztf888
2010-12-23 · TA获得超过450个赞
知道答主
回答量:178
采纳率:0%
帮助的人:71.6万
展开全部
在uses 中使用ShellAPI;
加一个button; onClick事件
ShellExecute(handle, 'open ', '盘符路径:\project1.exe ', Nil, Nil, SW_SHOWNORMAL);

WinExec( 'project1.exe ',1);
不过这是外部调用,怎么在panel中运行,就不知道了!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式