I use the folowing function to start MS Word and open a file. This is done OK but the Word app is not maximized on top of my application. Is that not possible to add to my function?
function TFiles.ExecuteAndWait(const aFile: string; aParam: string = ''; const aHidden: boolean = False): integer;
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
with SEInfo do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(aFile) ;
lpParameters := PChar(aParam) ;
if aHidden = True then
nShow := SW_HIDE
else
nShow := SW_SHOWNORMAL;
end;
if ShellExecuteEx(@SEInfo) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) Or Application.Terminated;
Result := ExitCode;
end
else
Result := -1;
end;
There are a few problems here:
SW_MAXIMIZE
if you want the window to be maximized. CloseHandle
when you have finished with the process handle. WaitForSingleObject
. Or if you must wait in the main thread, and must use ProcessMessages
, use MsgWaitForMultipleObjects
.