当前位置:主页>销售管理软件> 列表

如何在自己程序的某个窗体中打开其他程序? 找进销存表格

记账软件版1楼: 如何在自己程序的某个窗体中打开其他程序?

也就是说限制其他程序在我的程序中运行呢?

2楼: 可以调用
有三个API函数可以运行可执行文件WinExec、ShellExecute和CreateProcess。 CreateProcess因为使用复杂,比较少用。
WinExec主要运行EXE文件。如:
WinExec(''Notepad.exe Readme.txt'', SW_SHOW);
ShellExecute不仅可以运行EXE文件,也可以运行已经关联的文件(需要在Uses部分加上shellapi)。如:
ShellExecute(0, ''open'', ''http://askpro.yeah.net'', nil, nil, 0); 如a9财务软件免费下载

3楼: 楼上用的两个函数只是调用了外部应用程序,并没理解楼主的意思,楼主说的是让外部应用程序运行在自己设计的窗口中

4楼: ole

5楼: var
h: HWnd; //全局变量,保存被捆绑的程序的句柄.

h := FindWindow(nil, ''被捆绑的程序的标题'');
if h <> 0 then
begin
Windows.SetParent(h, Panel1.Handle);
Windows.SetWindowPos(h, 0, 0, 0, Panel1.Width, Panel1.Height, 0);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Windows.SetParent(h, 0);
end;

6楼: wade_thunder,请问有没有使用OLE的例子?

liyinwei,你的例子能否给得详细点?谢谢。

记账软件版7楼: 如果用OLE又如何操作呢??麻烦大家给点提示吧。

8楼: unit Unit12;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
H: THandle;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ShellExecute(Handle,PChar(''Open''),PChar(''Notepad.exe''),'''','''',SW_SHOWNORMAL);


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
H := FindWindow(nil, ''无标题 - 记事本'');
if H <> 0 then
begin
Windows.SetParent(H, Panel1.Handle);
Windows.SetWindowPos(h, 0, 0, 0, Panel1.Width, Panel1.Height, 0);
end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Windows.SetParent(H, 0);
end;

end.

9楼: liyinwei兄的程序执行是可以限制在 panel1中,不过当主程序关闭的时候,notepad 并没有关闭。而且在状态栏中看到两个程序一起运行的。好象没有实现内嵌。是不是有更好的办法解决呢?liyinwei 可以得到一部分分的。

10楼: liyinwei兄,这样打开的程序又如何关闭他呢?FindWindow 报错说找不到这个内嵌的程序,关不了喔。

11楼: 可以把其他程序改写成包DLL,然后进行调用....

12楼: MDI窗体应该可以
打开的新应用程序显示在子窗体中 如进销存表格

13楼: procedure TForm1.Button1Click(Sender: TObject);
begin
//取巧,用隐藏的方法运行,然后再捆绑


ShellExecute(Handle,PChar(''Open''),PChar(''Notepad.exe''),'''','''',SW_HIDE);
//Sleep(1000); //如果被启动的程序启动较需时,可以挂起主程序一定的时间
H := FindWindow(nil, ''无标题 - 记事本'');
if H <> 0 then
begin
SetParent(H, Panel1.Handle);
SetWindowPos(H, 0, 0, 0, Panel1.Width, Panel1.Height, 0);
ShowWindow(H,SW_RESTORE); //显示被捆绑的程序
end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Windows.SetParent(H, 0); //释放程序的捆绑
PostMessage(H,WM_QUIT,0,0); //关闭被捆绑的程序
end;

记账软件版14楼: 用shellexecute 去打开程序有点怪现象,notepad 就可以内嵌,其他程序不太行。
给分了,谢谢liyinwei。

15楼: liyinwei兄,在PostMessage(H,WM_QUIT,0,0); 的时候,有时侯会出错。不知道啥问题。

liyinwei有QQ吗?