@@ -603,14 +603,29 @@ pub fn callMain() u8 {
603
603
}
604
604
605
605
pub fn call_wWinMain () std.os.windows.INT {
606
+ const peb = std .os .windows .peb ();
606
607
const MAIN_HINSTANCE = @typeInfo (@TypeOf (root .wWinMain )).Fn .params [0 ].type .? ;
607
608
const hInstance = @as (MAIN_HINSTANCE , @ptrCast (std .os .windows .kernel32 .GetModuleHandleW (null ).? ));
608
609
const lpCmdLine = std .os .windows .kernel32 .GetCommandLineW ();
609
610
610
- // There's no (documented) way to get the nCmdShow parameter, so we're
611
- // using this fairly standard default.
612
- const nCmdShow = 5 ;
611
+ // This makes Zig mostly match the nCmdShow behavior of a C program with a WinMain symbol:
612
+ // - With STARTF_USESHOWWINDOW set in STARTUPINFO.dwFlags of the CreateProcess call:
613
+ // - Compiled with subsystem:console -> nCmdShow is always SW_SHOWDEFAULT
614
+ // - Compiled with subsystem:windows -> nCmdShow is STARTUPINFO.wShowWindow from
615
+ // the parent CreateProcess call
616
+ // - With STARTF_USESHOWWINDOW unset:
617
+ // - nCmdShow is always SW_SHOWDEFAULT
618
+ //
619
+ // TODO: Figure out how to check the subsystem and use it to match the above
620
+ // behavior, or intentionally avoid matching the above behavior with
621
+ // regards to the subsystem.
622
+ const SW_SHOWDEFAULT = 10 ;
623
+ const STARTF_USESHOWWINDOW = 1 ;
624
+ var nCmdShow : std.os.windows.ULONG = SW_SHOWDEFAULT ;
625
+ if (peb .ProcessParameters .dwFlags & STARTF_USESHOWWINDOW != 0 ) {
626
+ nCmdShow = peb .ProcessParameters .dwShowWindow ;
627
+ }
613
628
614
629
// second parameter hPrevInstance, MSDN: "This parameter is always NULL"
615
- return root .wWinMain (hInstance , null , lpCmdLine , nCmdShow );
630
+ return root .wWinMain (hInstance , null , lpCmdLine , @intCast ( nCmdShow ) );
616
631
}
0 commit comments