Downloaded nsis 3 beta 1
Built a hello, world installer following http://www.rolandbaer.ch/software/tutorials/nsis-tutorial-teil-1/
Ran it on Windows 7 sp1
After telling UAC the program was ok to run, couldn't see it anywhere except the taskbar.
Clicking on its taskbar icon brought it to the foreground.
I'm worried that users won't think to do that, and will think my installer is broken.
I've seen some discussion of this elsewhere on the net, e.g.
http://forums.winamp.com/showthread.php?t=324514
http://stackoverflow.com/questions/15429673/why-is-setwindowpos-failing-to-bring-windows-to-the-front-of-the-z-order-when-i
http://stackoverflow.com/questions/4646725/nsis-installer-opens-up-in-the-background
I can appreciate that Windows doesn't make this easy, but shouldn't the simplest
possible installer script handle this right without workarounds?
How exactly did you start the installer? Double-click in a Explorer file list? A file on the desktop? Did you use your mouse or keyboard?
If I remember correctly, this happens when the script (or the stub as a bug) displays a window before the main installer window. Windows only brings the first window to the foreground. If another window is created before the main window, only that window will be brought to the front. There's more to it, because we do show a banner sometimes and it works with that, but I think that's at least the right direction to investigate.
Aha! If launched from cmd, or by double-clicking, it does seem to behave properly.
To reproduce the problem, launch it from a cygwin terminal window.
So this is less severe than I thought. Cygwin users can probably handle z-order problems. Still, it'd be cool if the installer handled that situation, too.
Well that's the thing, Windows forbids it. The StackOverflow question you posted actually explains it. Windows blocks the second attempt to bring a window to the front if it's too soon after the first one. So the solution here would be to find that first window and remove it or have it run in the same thread so that the main window can get the focus.
Wait, what? What's the first window? I'm confused. All I did was run the
installer, there weren't any more windows involved than if I had run it from cmd.exe.
That's the question still to be answered. But that's usually why the main window is hidden. There is a window created before it in another thread. Windows only allows the first window to be set as the foreground window.
So would looking for CreateWindow or CreateWindowEx in Process Monitor be sufficient?
That would be a good start, yes. If we can figure out which window it is, it will be easier to fix.
So nothing comes up in Process Monitor?
Process Monitor does not catch GUI events?
NSIS itself has the little compression window before .onInit, I have always suspected that there is a moment in time there after it closed where we have no HWND and might lose our foreground lock before the main window is created/visible but I have never been able to reproduce the issue...
Should be fine as long as the windows are created in the same thread.
Not if it we have a moment in time with no (visible) window? Windows has to activate some other window.