我想问两个问题:
  1.如何通过一个应用程序调用另一个应用程序,Delphi里类似于VB里的Shell功能的函数是哪一个??如何用
  2.两个不同的应用程序如何用自定义的消息进行通信?

解决方案 »

  1.   

    winexec
    ShellExecute需要uses shellapi
      

  2.   

    谢谢,能不能说的更清楚一点
    比如我要运行"C:\1.exe"
    ShellEXecute "C:\1.exr" 就行了??
    两个函数有什么不一样,他们还有什么参数??
      

  3.   

    参数看帮助了HINSTANCE ShellExecute(    HWND hwnd, // handle to parent window
        LPCTSTR lpOperation, // pointer to string that specifies operation to perform
        LPCTSTR lpFile, // pointer to filename or folder name string
        LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters 
        LPCTSTR lpDirectory, // pointer to string that specifies default directory
        INT nShowCmd  // whether file is shown when opened
       );
    等等。
      

  4.   

    调用外部应用程序    我们常用的函数有两个,WinExec 和 ShellExecute。   1) 使用 WinExec 函数 (属于 WinProcs单元) 
    · 声明形式   UNIT WinExec(LPCSTR lpCmdLine, UINT uCmdShow); 
     [例] var SDir:string; 
    SetLength(SDir,144); 
    GetWindowsDirectory(PChar(SDir),144); 
    SetLength(SDir,StrLen(PChar(SDir))); 
    SDir:=SDir+'\notepad.exe'+' '+savedialog1.FileName; 
    WinExec(PChar(SDir), SW_SHOWMAXIMIZED); 
        注意:如果 SDir 不是有效路径不会提示错误。 
    [例] winexec('command.com /c copy *.* c:\',SW_Normal); 
    [例] winexec('start abc.txt');   2)使用 ShellExecute 函数(属于ShellAPI单元) 
    它的几个参数: 
    · hwnd:窗体的句柄; 
    · lpOperation:打开程序执行的操作,共预留有"open"、"explore"、 "print"三种方式,此参数可以省略,此时将依据打开的文件(lpFile)的类型执行相应的操作,比如:如果lpFile为一文本文件,那么将会在与该文件相关联的程序中打开它 
    · lpFile:文件名;  
    · lpParamerters:打开文件时所需的参数;  
    · lpDirectory:文件名所在的路径,当然,一般来说,在Windows中登记过的程序(如WinWord)不必提供此参数; 
    · nShowCmd:打开文件后程序窗体如何显示。  (1)运行可执行文件 
      [例] 以"记事本"为例 
    procedure TForm1.OpenBtnClick(Sender:TObject);  
     begin ShellExecute(handle,'open','notepad.exe',nil,nil,SW_ShowNormal);  end;  
       此外,ShellExeCute() 还可以进行链接网络。 
     [例] procedure TForm1.HttpClick(Sender: TObject);  
    begin  
      ShellExecute(handle,'open','http://liangming.163.net', nil,nil,SW_ShowNormal);  
    end; (2)打开在Windows注册的外部文件   
        如果一个文件已经在Windows的注册表中注册了,那我们就可以通过以下方法运行他,首先要在uses部分加入: uses Shellapi;  
    接着定义一个过程  
    procedure URLink(URL:PChar); 
    begin 
      ShellExecute(0, nil, URL, nil, nil, SW_NORMAL); 
    end;  
    在要调用的地方使用: URLink('Readme.txt');  
    要链接到主页就改用:   URLink('http://vortex.yeah.net');  
    要发邮件就要在邮件地址前加: mailto URLink('mailto:[email protected]');  
    如果是打开外部执行程序的话,那么也可以直接调用。