Ok, I have found the source of the issue, by changing options that were given to
CreateProcess, but it revealed an issue that comes from a weird behavior of the
ShowWindow API.
Indeed, that API ignores its parameter the first time it is called, if a default value was given to the
CreateProcess call that started the process. This is clearly documented in the
MSDN, but I had no idea that this existed.
So, when the application is started via the Launcher, it has a default visibility value set to
SW_HIDE, which means that the call
ShowWindow(FMainWnd, SW_SHOWNORMAL) inside
TExceptionBox.Create is interpreted as
ShowWindow(FMainWnd, SW_HIDE)
What's really weird is that the MSDN documentation says the parameter is ignored "the first time ShowWindow is called by an application", but the VCL calls
ShowWindow before on various other windows and yet, I still see the documented behavior.
So, in the end, I have multiple solutions :
- Use my own code that calls CreateProcess without the SW_HIDE parameter in startup info
- Modify the JCL code so that one can control what value gets set in the startup info for CreateProcess
- Call ShowWindow with a dummy value in my own code on the madExcept assistant window via the OnExceptBoxCreate callback
- Wait for a madExcept version which calls SetWindowPos instead of ShowWindow
I'll implement point 2 as it might be of use for other people, but for a quick fix, I have implemented point 3 like this:
Code: Select all
procedure OnExceptBoxCreate(exceptBox: HWND; simpleMsgBox: boolean);
begin
// Workaround a "feature" of ShowWindow that ignores its parameter the first time it is called
ShowWindow(exceptBox, SW_SHOWDEFAULT);
end;
However, as madExcept cannot know if the process it is running into has been called with the appropriate flags for CreateProcess, nor can it force its user to use the above workaround, I believe it should change its code to call
SetWindowPos instead of
ShowWindow, like this:
Code: Select all
SetWindowPos(FMainWnd, 0, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_SHOWWINDOW);
I have tested it here, it works just fine in all cases.
What's even weirder with the
ShowWindow API is that it ignores its parameter on first call only if its related to visibility, but not when passing
WS_RESTORE or
WS_MINIMIZE which means the code right after it that tests if the window is minimized will appropriately restore the window.
Thanks for the suggestions along the way that helped me pinpoint the source of all this.