Replies: 5 comments 1 reply
-
It still needs to respect the original startup style for the window, though. Windows can launch an app minimized or maximized or regular, and I think that’s passed in the startup info. So long as that’s not lost.
It sounds like a regression if that’s being ignored? It doesn’t have to go through WinMain like it used to but still need to support the startup style.
- Dave
… On Feb 5, 2023, at 8:53 PM, Charles Stevens ***@***.***> wrote:
@davepl <https://github.com/davepl>
It looks to me that the call to GetStartupInfo is vestigial code. I think originally it was present to set up the nCommandShow parameter to WinMain(), which then gets passed to the ShowWindow() API call. When WinMain() was collapsed into MainEntry, the ShowWindow() call was replaced by UpdateWindow() so there is no longer any place for the wShowWindow parameter to go. It just gets pushed on the stack and then never used.
I believe removing that stanza should be OK, since the result is not used. It will also remove a few bytes from the IAT.
—
Reply to this email directly, view it on GitHub <#26>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA4HCF7AIUPJZ27HYLT3T5DWWB7VRANCNFSM6AAAAAAUSHCA4E>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
OK. My reading of the code says that this is a regression then. I will do some testing later and go from there. |
Beta Was this translation helpful? Give feedback.
-
As along as it still works, that’s all I care. I added that to make Raymond Chen happy, so don’t want to remove it like it didn’t matter :-)
… On Feb 8, 2023, at 5:56 PM, Charles Stevens ***@***.***> wrote:
@davepl <https://github.com/davepl>
I tested Tiny.exe using a shortcut with the "Run" field set to each of the three available values. TinyOriginal never calls ShowWindow(). Nevertheless the docs for ShowWindow() describe what we do: we call CreateWindow() with the WS_VISIBLE flag set. In this case when the window is displayed the OS consults the STARTUPINFO structure to see how to display the main (first) window. If you agree that this test was valid, I would say the call to GetStartupInfo() is not needed and is simply left over from when there was a need to create the parameter list for WinMain().
—
Reply to this email directly, view it on GitHub <#26 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA4HCF6D2ZSMHQHBTPDJBILWWRFFJANCNFSM6AAAAAAUSHCA4E>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
@davepl I went back and read Raymond's blog post on STARTF_USESHOWWINDOW as well as the MSDN entries on ShowWindow, CreateWindowEx and WinMain My summary of all four sources is that the window manager will feel free to override your provided argument to ShowWindow on the first call for the application's main window. Since we don't care about how the window is shown, and only that it is shown as requested by the starting application we should be good without calling GetStartupInfo. Again we don't call ShowWindow directly, so even trying to control the second argument to ShowWindow is even more convoluted when going through CreateWindowEx. |
Beta Was this translation helpful? Give feedback.
-
Thanks for doing the research! Are you saying, then, that the window manager has a hack to do it for you because most apps don’t do it right? If so, then we don’t have to either, I guess. It feels more correct with it, but if it’s ignored anyway, I don’t mind.
If it works and starts minimized when you use this code, then that’s what I mean. Your shortcut test does this behind the scenes in ShellExecute, I imagine. I used to really miss having access to the Windows code when trying to sort out stuff like this!
So if I get what you’re saying, whoever calls CreateProcess and happens to specify STARTF_USESHOWWINDOW gets that behavior from all apps now because the window manager looks and does it for you?
Cheers,
Dave
#include <Windows.h>
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWMINIMIZED;
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
TCHAR cmdLine[] = _T("tiny.exe");
BOOL bSuccess = CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (!bSuccess)
{
_tprintf(_T("CreateProcess failed (%d)\n"), GetLastError());
return 1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
… On Feb 12, 2023, at 7:41 PM, Charles Stevens ***@***.***> wrote:
@davepl <https://github.com/davepl>
I believe this one has a high enough payback to continue this discussion. I am a big fan of @oldnewthing <https://github.com/oldnewthing> and have read his blog for many years. So I would like to not only make the result smaller, I'd like it to still be correct. (And not just work by accident)
I went back and read Raymond's blog post on STARTF_USESHOWWINDOW <https://devblogs.microsoft.com/oldnewthing/20100301-00/?p=14773> as well as the MSDN entries on ShowWindow <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow>, CreateWindowEx <https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexa> and WinMain <https://learn.microsoft.com/en-us/windows/win32/learnwin32/winmain--the-application-entry-point>
My summary of all four sources is that the window manager will feel free to override your provided argument to ShowWindow on the first call for the application's main window. Since we don't care about how the window is shown, and only that it is shown as requested by the starting application we should be good without calling GetStartupInfo. Again we don't call ShowWindow directly, so even trying to control the second argument to ShowWindow is even more convoluted when going through CreateWindowEx.
—
Reply to this email directly, view it on GitHub <#26 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA4HCF5KNV2XQ6O2ZRMVK33WXGUPXANCNFSM6AAAAAAUSHCA4E>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
@davepl
It looks to me that the call to GetStartupInfo is vestigial code. I think originally it was present to set up the nCommandShow parameter to WinMain(), which then gets passed to the ShowWindow() API call. When WinMain() was collapsed into MainEntry, the ShowWindow() call was replaced by UpdateWindow() so there is no longer any place for the wShowWindow parameter to go. It just gets pushed on the stack and then never used.
I believe removing that stanza should be OK, since the result is not used. It will also remove a few bytes from the IAT.
Beta Was this translation helpful? Give feedback.
All reactions