[ÆÁ]¿ÜºÎ ÇÁ·Î±×·¥ ¸ð´Þ âó·³ ¶ç¿ö¼ Á¾·áµÉ¶§ ±â´Ù¸®±â(½ÃÁ¡ ¾Ë±â)
//±¸Ã¢¹ÎÀÔ´Ï´Ù.
//Å×½ºÆ® °ÅÃƱ¸¿©, ShowModal âó·³ ¶°¼ Á¤È®ÇÏ°Ô µ¿ÀÛÇÕ´Ï´Ù.
//Ç×»ó Áñ°Å¿î ÇÁ·Î±×·¡¹Ö Çϼ¼¿ä.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function WinExecAndWait32V2(FileName: string; Visibility: integer): DWORD;
procedure WaitFor(processHandle: THandle);
var
msg: TMsg;
ret: DWORD;
begin
repeat
ret:= MsgWaitForMultipleObjects(1, processHandle, False, INFINITE,
QS_PAINT or QS_SENDMESSAGE);
if ret = WAIT_FAILED then Exit;
if ret = (WAIT_OBJECT_0 + 1) then
begin
while PeekMessage(msg, 0, WM_PAINT, WM_PAINT, PM_REMOVE) do
DispatchMessage(msg);
end;
until ret = WAIT_OBJECT_0;
end;
var
zAppName: array[0..512] of char;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(zAppName, FileName);
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,
ProcessInfo) then
Result:= DWORD(-1)
else
begin
Waitfor(ProcessInfo.hProcess);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
while WinExecAndWait32V2(PChar('notepad'), 1) <> 0 do
Application.ProcessMessages;
ShowMessage('OK~');
end;
end.
|
|