Jump to content
Sign in to follow this  

Activated window not being brought to front

Recommended Posts

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinWaitDelay", 0)

$MainForm = GUICreate("MainForm", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 248, 192, 97, 41)

$SubForm = GUICreate("SubForm", 395, 252, 192, 124)
WinSetOnTop($SubForm, "", 1)

While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]

    Case $MainForm

        Switch $nMsg[0]

            Case $Button1
                WinSetState($SubForm, "", @SW_SHOW)
                WinSetState($MainForm, "", @SW_DISABLE)

            Case $GUI_EVENT_CLOSE


    Case $SubForm

        Switch $nMsg[0]

            Case $GUI_EVENT_CLOSE
                WinSetState($SubForm, "", @SW_HIDE)
                WinSetState($MainForm, "", @SW_ENABLE)



This is similar to the structure of my main script. The problem is that when you close the subform, focus is given to the main form but it isn't brought to the front. This issue doesn't occur in this script but does occur in my main script on the seemingly random occasion. This means I can't make it reproducible (At the moment it's working consistently).

When this bug occurs it keeps occurring for the rest of the session and when it occurs in that session it occurs more frequently when the two windows are in front of the SciTE window.

I just need some help as to what could be causing it so I can make it reproducible or find a possible work around.

Edited by T0M50N

Share this post

Link to post
Share on other sites


It means there's something wrong in your script, you can still use a workaround which is to set the z-order pos to bring your window back to the front.

Take a look at _WinAPI_SetWindowPos in the helpfile (and its example).

Br, FireFox.


OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control


Share this post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...