Delphi - show console application from SW_HIDE state

I have a console application in Delphi that I start with another 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 state, I would like to show that it is displayed (accept in SW_SHOWNORMAL state). How can i do this?

Thus, it does not show:

ShowWindow(GetConsoleWindow, SW_SHOW);

Not even that:

BringWindowToTop(GetConsoleWindow);
SetActiveWindow(GetConsoleWindow);
SetForegroundWindow(GetConsoleWindow);
ShowWindow(GetConsoleWindow, SW_SHOW)

But it manifests itself like this:

MessageBox(GetConsoleWindow, PChar(IntToStr(GetConsoleWindow)), PChar(''), MB_SETFOREGROUND);
ShowWindow(GetConsoleWindow, SW_SHOW);

But of course I do not want this message box.

What is the problem?

+4
source share
1 answer

The shell passes the information that you supply with SHELLEXECUTEINFOthrough CreateProcess()to a console application that distinguishes this information when you first try to display the console window.

The documentation for ShowWindow()reads:

nCmdShow [in]
: int

, . ShowWindow, , , STARTUPINFO structure. ShowWindow , , WinMain nCmdShow. ...

, ShowWindow SW_HIDE, ShellExecuteEx(). .

+8

Source: https://habr.com/ru/post/1656276/


All Articles