请问如何调用外部的应用程序?(50分)

  • 主题发起人 主题发起人 xjtuspj
  • 开始时间 开始时间
X

xjtuspj

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用 ShellExecute(handle,'open','d:/tbmexpert/lb00ad1.exe','-s',nil,SW_SHOWNORMAL);<br>为何应用程序调用不成功?
代码:
 
winexec('d:/tbmexpert/lbooad1.exe',0);
 
能用shellexecute吗?能嵌入到固定窗体中运行吗?
 
能使用shellexecute,并能嵌入到指定窗体中吗?
 
我试过了不可以
 
嵌入到指定窗体中,不行吧
 
:<br>ShellExecute(handle,'open','lbooad1.exe','-s','d:/tbmexpert',SW_SHOWNORMAL);
 
根本不可以嵌入到指定的窗体中
 
在使用winexec 时首先在USEs 单元中加入ExtCtrls;<br>&nbsp; 二是winexec 中第一个参数是可执行的文件的绝对路径再写上要打开文件, 引起来.<br>&nbsp; <br>&nbsp; winexec('C:/Program Files/Accessories/WORDPAD.EXE &nbsp;abc.txt',1);<br><br>如:interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, Buttons, ExtCtrls;<br><br>type<br>&nbsp; TForm_brow_file = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; OpenDialog1: TOpenDialog;<br>&nbsp; &nbsp; SpeedButton1: TSpeedButton;<br>&nbsp; &nbsp; SpeedButton3: TSpeedButton;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure SpeedButton3Click(Sender: TObject);<br>&nbsp; &nbsp; procedure SpeedButton1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form_brow_file: TForm_brow_file;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm_brow_file.SpeedButton3Click(Sender: TObject);<br>begin<br>&nbsp; close ;<br>end;<br><br>procedure TForm_brow_file.SpeedButton1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp; winexec('C:/Program Files/Accessories/WORDPAD.EXE &nbsp;abc.txt' ,1);<br>end;<br>
 
按道理应该两个都可以!winexec不是很稳定,用ShellExecute应该更好,不过参数传递的时候应该正确~
 
我试过ShellExecute(handle,'open','lbooad1.exe','-s','d:/tbmexpert',SW_SHOWNORMAL);<br>好像还是不行的
 
不知道下面的行不行,若行,请给我加分:)<br>Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long<br>d:/tbmexpert/lbooad1.exe -s<br><br>用ShellExecute更好,在USES段加入SHELLAPI,使用时如:<br>执行"c:/myapp/myapp.exe"参数为"-s"<br>ShellExecute(handle,'open','c:/myapp/myapp.exe','-s','',SW_SHOWNORMAL);<br>第一个参数为父窗口句柄;<br>第二个参数为打开方式(OPEN,PRINT两种);<br>第三个参数为执行文件全路径;<br>第四个参数为执行文件参数;<br>第五个参数为执行文件开始运行时的初始目录;<br>第六个参数为为执行文件运行方式(SW_HIDE,SW_MAXIMIZE,SW_MINIMIZE,<br>SW_RESTORE,SW_SHOW,SW_SHOWDEFAULT,SW_SHOWMAXIMIZED,SW_SHOWMINIMIZED,<br>SW_SHOWMINNOACTIVE,SW_SHOWNA,SW_SHOWNOACTIVATE,SW_SHOWNORMAL);<br>具体请看帮助。另外,如果为字符串参数,其中包含变量或运算的必需用PCHAR()函数。<br><br><br>
 
當參要傳一個帶有空格的字符串時應該怎么處理呢?
 
后退
顶部