首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么结束用WinExec()调用的外部程序

2012-03-16 
如何结束用WinExec()调用的外部程序程序如下,是利用WinExec()调用DEWEsoft.exe。然后在按下btn2,程序退出后

如何结束用WinExec()调用的外部程序
程序如下,是利用WinExec()调用DEWEsoft.exe。然后在按下btn2,程序退出后,DEWEsoft.exe并没有结束,我想知道怎么才能让程序结束后,调用的DEWEsoft也同时结束。
  先谢谢各位了

  还有一个问题,就是用Chart组件能作出X-Y记录仪吗?怎么做呢


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  pnl1: TPanel;
  btn1: TButton;
  btn2: TButton;
   

  procedure btn2Click(Sender: TObject);
  procedure btn1Click(Sender: TObject);
  private
  { Private declarations }
  public
  { Public declarations }
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.btn2Click(Sender: TObject);
begin

close
end;

procedure TForm1.btn1Click(Sender: TObject);
var
h :HWND;

begin

WinExec('C:\Program Files\Dewetron\DEWEsoft66\DEWEsoft.exe',SW_SHOWNORMAL);
h := FindWindow(nil,'DEWEsoft');
windows.SetParent(h,pnl1.Handle);
SetWindowPos(h, 0, 0, 0, pnl1.Width , pnl1.Height, SWP_NOZORDER);

end;

end.

[解决办法]
var
h :HWND; // 变成全局变量就行了

然后在FORMCLOSE事件里写上

SendMessage(h, WM_CLOSE, 0, 0);

热点排行