Delphi calls the external EXE and waits for the calling program to run end

Source: Internet
Author: User

function tfmain.runwait (filename:string; Visibility:integer): Thandle;
Var
ZAPPNAME:ARRAY[0..512] of Char;
ZCURDIR:ARRAY[0..255] of Char;
workdir:string;
Startupinfo:tstartupinfo;
Processinfo:tprocessinformation;
Begin
Try
Strpcopy (Zappname, FileName);
Getdir (0, Workdir);
Strpcopy (Zcurdir, Workdir);
Fillchar (Startupinfo, SizeOf (startupinfo), #0);
STARTUPINFO.CB: = SizeOf (Startupinfo);
Startupinfo.dwflags: = Startf_useshowwindow;
Startupinfo.wshowwindow: = Visibility;
If not CreateProcess (nil, zappname, nil, nil, false, create_new_console or normal_priority_class, nil, nil, startupinfo, P Rocessinfo) Then
Begin
Result: = 0;
Exit;
End
Else
Begin
WaitForSingleObject (processinfo.hprocess, INFINITE);
GetExitCodeProcess (processinfo.hprocess, result);
End
Finally
End
End

Call

Procedure Tfmain.img_buyclick (Sender:tobject);
Var
msg:string;
Begin

timer1.enabled: = False;

Runwait (' Cs_buy.exe ', sw_showmaximized);

timer1.enabled: = True;

End

Where the parameter Visibility value is as follows:


Line number parameter meaning
1 sw_hide hides this form and activates other forms.
2 Sw_maximize maximizes the specified form.
3 sw_minimize minimizes the specified form and activates the topmost form sequentially.
4 Sw_restore activates and displays the form. If the form is minimized or maximized, the form reverts to the original large
Small and set. The application specifies the markup when a minimized form is restored.
5 Sw_show activates and displays the form at its current size and position.
6 Sw_showdefault
7 sw_showmaximized activates and maximizes the display of the form.
8 sw_showminimized activates and minimizes the reality form.
9 sw_showminnoactive Minimize the form and keep it active.
Sw_showna displays the form in its current state, keeping it active.
Sw_shownoactivate displays the form in its current size and position and retains its active status.
Sw_shownormal activates and displays a form. If the form is maximized or minimized, the form reverts to its original size and position. When the form is first displayed, the application records the markup

Delphi calls the external EXE and waits for the calling program to run end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.