I have a console application in Delphi, what i start from an other application this way:
FillChar(ExecInfo, SizeOf(ExecInfo), 0);
With ExecInfo Do Begin
cbSize := SizeOf(ExecInfo);
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_NOASYNC;
Wnd := GetActiveWindow();
lpVerb := PChar('runas');
lpFile := PChar(FsCurrentPath + 'Install\Install_Elevated.exe');
lpDirectory := PChar(FNew.sBinDir);
lpParameters := PChar(sl.DelimitedText);
nShow := SW_HIDE
End;
ShellExecuteEx(@ExecInfo);
In some condition i would like to make it show itself (take in SW_SHOWNORMAL state). How can i do it?
This way it does not show:
ShowWindow(GetConsoleWindow, SW_SHOW);
Even not this way:
BringWindowToTop(GetConsoleWindow);
SetActiveWindow(GetConsoleWindow);
SetForegroundWindow(GetConsoleWindow);
ShowWindow(GetConsoleWindow, SW_SHOW)
But it shows itself this way:
MessageBox(GetConsoleWindow, PChar(IntToStr(GetConsoleWindow)), PChar(''), MB_SETFOREGROUND);
ShowWindow(GetConsoleWindow, SW_SHOW);
But of course i dont want this message box.
What is the problem?
The shell passes the information you supply with SHELLEXECUTEINFO
through CreateProcess()
to the console application, which honors that information when you first try to show the console window.
The documentation for ShowWindow()
says:
nCmdShow [in]
Type:int
Controls how the window is to be shown. This parameter is ignored the first time an application calls
ShowWindow
, if the program that launched the application provides aSTARTUPINFO
structure. Otherwise, the first timeShowWindow
is called, the value should be the value obtained by theWinMain
function in itsnCmdShow
parameter. In subsequent calls, this parameter can be one of the following values...
So, the first time you call ShowWindow
, the SW_HIDE
that was passed to ShellExecuteEx()
takes effect. In the subsequent calls, the parameter you specify takes effect instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With