现有两个应用程序A、B。如何实现:B程序像模式窗体一样运行,在B结束前A不能作其他操作
现有两个应用程序A、B。怎么实现:B程序像模式窗体一样运行,在B结束前A不能作其他操作?
我现在已经让窗体A自动运行了另一程序B,请问:
怎么实现: B程序像模式窗体一样运行,在 B 结束前 A 不能作其他操作?
------解决方案--------------------
function WinExec32(FileName: String; Wind_State: integer; Wait_Flag:
Boolean): integer;
var
AppName: array[0..512] of char;
CurDir: array[0..255] of char;
WorkDir: String;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(AppName, FileName);
GetDir(0, WorkDir);
StrPCopy(CurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Wind_State;
{Case Wind_State of
0: 窗口隐藏
1: 窗口正常显示
2: 窗口最小化显示,焦点在工具栏处的窗口TITLE上
3: 窗口最大化显示
4: 窗口正常显示,但无焦点
5: 窗口正常显示,但有焦点
6: 窗口最小化显示,焦点不在工具栏处的窗口TITLE
......................
....................
参照 windows.pas
SW_HIDE = 0;
SW_SHOWNORMAL = 1;
SW_NORMAL = 1;
SW_SHOWMINIMIZED = 2;
SW_SHOWMAXIMIZED = 3;
SW_MAXIMIZE = 3;
SW_SHOWNOACTIVATE = 4;
SW_SHOW = 5;
SW_MINIMIZE = 6;
SW_SHOWMINNOACTIVE = 7;
SW_SHOWNA = 8;
SW_RESTORE = 9;
SW_SHOWDEFAULT = 10;
SW_MAX = 10;}
if not CreateProcess(nil,
AppName, { 命令行字符串 }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then
Result := -1 { pointer to PROCESS_INF }
else
begin
if Wait_Flag then
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
// if GetExitCodeProcess(ProcessInfo.hProcess,Result) then showmessage( '调用成功完成 ')
// else showmessage( '调用发生错误 ');
end;
end;
//调用
WinExec32( 'BBB.exe ', 0, true);
------解决方案--------------------
把A的窗体隐藏。需要操作时再显示出来。
------解决方案--------------------
这里有很多例子:
http://www.swissdelphicenter.ch/torry/showcode.php?id=93
我现在已经让窗体A自动运行了另一程序B,请问:
怎么实现: B程序像模式窗体一样运行,在 B 结束前 A 不能作其他操作?
------解决方案--------------------
function WinExec32(FileName: String; Wind_State: integer; Wait_Flag:
Boolean): integer;
var
AppName: array[0..512] of char;
CurDir: array[0..255] of char;
WorkDir: String;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(AppName, FileName);
GetDir(0, WorkDir);
StrPCopy(CurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Wind_State;
{Case Wind_State of
0: 窗口隐藏
1: 窗口正常显示
2: 窗口最小化显示,焦点在工具栏处的窗口TITLE上
3: 窗口最大化显示
4: 窗口正常显示,但无焦点
5: 窗口正常显示,但有焦点
6: 窗口最小化显示,焦点不在工具栏处的窗口TITLE
......................
....................
参照 windows.pas
SW_HIDE = 0;
SW_SHOWNORMAL = 1;
SW_NORMAL = 1;
SW_SHOWMINIMIZED = 2;
SW_SHOWMAXIMIZED = 3;
SW_MAXIMIZE = 3;
SW_SHOWNOACTIVATE = 4;
SW_SHOW = 5;
SW_MINIMIZE = 6;
SW_SHOWMINNOACTIVE = 7;
SW_SHOWNA = 8;
SW_RESTORE = 9;
SW_SHOWDEFAULT = 10;
SW_MAX = 10;}
if not CreateProcess(nil,
AppName, { 命令行字符串 }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then
Result := -1 { pointer to PROCESS_INF }
else
begin
if Wait_Flag then
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
// if GetExitCodeProcess(ProcessInfo.hProcess,Result) then showmessage( '调用成功完成 ')
// else showmessage( '调用发生错误 ');
end;
end;
//调用
WinExec32( 'BBB.exe ', 0, true);
------解决方案--------------------
把A的窗体隐藏。需要操作时再显示出来。
------解决方案--------------------
这里有很多例子:
http://www.swissdelphicenter.ch/torry/showcode.php?id=93