Jump to content

Strangeness with parent GUI windows

Recommended Posts

The problem that is currently vexing me is nicely demonstrated by the following minimal script. I have two windows, one is a child of the other. The parent is meant to be disabled when the child is shown. The script performs exactly as expected unless a message box is displayed while the child window is open, in which case closing the child window inexplicably causes the parent window to be sent behind all other open windows.

Try this: Run the script and leave your browser window open, behind the GUI window. Click the "Demonstrate" button and the "Close" button repeatedly. No problems. Now click the "Demonstrate" button once more, but this time press the "Show Message" button. Click away the message box and click the "Close" button again. Window 1 will now be located behind your browser window. This appears to happen with all window styles and messagebox parameters.

#include <GuiConstants.au3>

$gui1 = GuiCreate("Window 1", 300, 130,(@DesktopWidth-300)/2, (@DesktopHeight-130)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$exit = GuiCtrlCreateButton("Exit", 170, 40, 100, 40)
$demo = GuiCtrlCreateButton("Demonstrate", 30, 40, 100, 40)
$gui2 = GuiCreate("Window 2", 280, 120,(@DesktopWidth-280)/2, (@DesktopHeight-120)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS, -1, $gui1)
$message = GuiCtrlCreateButton("Show Message", 160, 35, 100, 40)
$close = GuiCtrlCreateButton("Close", 20, 35, 100, 40)

While 1
    $msg = GuiGetMsg()
    Case $msg = $GUI_EVENT_CLOSE or $msg = $exit
    Case $msg = $demo
    Case $msg = $close
    Case $msg = $message
        MsgBox(0,"Test","A message!")

Note that you can work around this by adding a GUISetState(@SW_SHOW,$gui1) line, but it doesn't prevent Window 1 from being sent to the back, so you get a kind of flickering effect, which becomes more pronounced with larger windows (and the main window in my real script is quite large). Can anyone tell me how or why this problem occurs, and if there's anything I can do to remove it? I'm using beta version 80.

Link to post
Share on other sites

$gui2 = GuiCreate("Window 2", 280, 120,(@DesktopWidth-280)/2, (@DesktopHeight-120)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_POPUP, -1, $gui1)

Been doing something similar recently myself, just added $WS_POPUP to your gui2 code

and seems to work ok..

Why?...dont ask me! I've know idea....it just works......wish i was that smart to know.



Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to post
Share on other sites

Hey, thanks! That solves the problem. I wonder what other differences $WS_POPUP is supposed to make, since I can't see any visual change in the style of the window. The manual is far from clear on this subject.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...