发信人: redfox (Z掉了几乎所有的版...), 信区: BorlandDev
标  题: Delphi编程 -- 15.3 怎样启动16位的应用程序
发信站: 哈工大紫丁香 (2000年09月01日17:38:13 星期五), 站内信件

怎样启动16位的应用程序?  
In a D3/Win95/Word 6.0 environment:
I need to bring up winword for the user if it's not already up, in a 
way
that will leave it running after my app is down. Can't use WinExec 
(etc.) as it's
a 16bit version of winword. There has to be some more-or-less direct 
way
of doing this... but all the documented methods assume 32bit. Any
suggestions?
回复:
  Try the following. It uses the ExecuteFile() function that can be 
found in the FMXUtils.pas file that came in the Demos\Doc\Filemanex 
directory with Delphi 1.0 and 2.0. (As far as I know it should also be 
in D3) ExecuteFile() is basically just a wrapper for the 
ShellExecute() function so this shows how to convert the params from 
pascal for
use with it. I used WinSight32 to find WinWord's ClassName which is used
 in the FindWindow() function. I have
no idea why it's OpusApp?? This will open it if it's not already running
 and will bring it to the front if it is
running.

uses
  ShellAPI;

function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..79] of Char;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if FindWindow('OpusApp',Nil) = 0 then
    ExecuteFile('E:\MSOFFICE\WINWORD\WINWORD.EXE','','',SW_SHOW)
  else
    if IsIconic(FindWindow('OpusApp',Nil)) then
      ShowWindow(FindWindow('OpusApp',Nil),SW_MAXIMIZE)
    else
      BringWindowToTop(FindWindow('OpusApp',Nil));
end;
-------------------
另一回复:
In addition to Rodney's reply, you really should try the WinExec 
function which you say you cannot use. In D2 you can just do:
    if WinExec(pchar(16exenamestring),SW_NORMAL) < 32 then

   ShowMessage('program did not start'); {otherwise the program 
started}


 

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.107]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.654毫秒