Menu

#1096 Installer window appears behind other windows ("z-order problem")

2.0 Beta Series
open
nobody
None
5
2014-06-26
2014-06-20
Dan Kegel
No

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?

Discussion

  • Anders

    Anders - 2014-06-21

    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?

     
  • Amir Szekely

    Amir Szekely - 2014-06-22

    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.

     
  • Dan Kegel

    Dan Kegel - 2014-06-22

    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.

     
  • Amir Szekely

    Amir Szekely - 2014-06-22

    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.

     
  • Dan Kegel

    Dan Kegel - 2014-06-22

    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.

     
  • Amir Szekely

    Amir Szekely - 2014-06-22

    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.

     
  • Dan Kegel

    Dan Kegel - 2014-06-22

    So would looking for CreateWindow or CreateWindowEx in Process Monitor be sufficient?

     
  • Amir Szekely

    Amir Szekely - 2014-06-22

    That would be a good start, yes. If we can figure out which window it is, it will be easier to fix.

     
  • Amir Szekely

    Amir Szekely - 2014-06-26

    So nothing comes up in Process Monitor?

     
    • Anders

      Anders - 2014-06-26

      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...

       
      • Amir Szekely

        Amir Szekely - 2014-06-27

        Should be fine as long as the windows are created in the same thread.

         
        • Anders

          Anders - 2014-06-27

          Not if it we have a moment in time with no (visible) window? Windows has to activate some other window.

          1. hVerify = CreateDialog()
          2. CRC()
          3. DestroyWindow(hVerify)
          4. hMainWnd = CreateDialog()
           

Log in to post a comment.

MongoDB Logo MongoDB