急急急!如何实现:B程序像模式窗体一样运行,在 B 结束关闭后 A 才能作操作? ( 积分: 20 )

  • 主题发起人 主题发起人 cx0731
  • 开始时间 开始时间
C

cx0731

Unregistered / Unconfirmed
GUEST, unregistred user!
帮忙看看,我用了下面这个函数,为什么还是不行?
我通过窗体A自动运行了另一登陆程序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('test.exe', 1, true);
 
如果A只有一个窗体,可以试试 Application.MainForm.Enabled:=false; 等B执行完之后
再 :=true;
 
问题解决了,谢谢你!
 
后退
顶部