Sign in to follow this  
Followers 0
czardas

Enabled GUI hides behind window

6 posts in this topic

#1 ·  Posted (edited)

I seem to have run into this problem. Somehow it seems familiar to me, but I have no idea what is causing it. Run the GUI and navigate to the first menu item 'New'. As soon as you click the message box that appears, the GUI disappears behind the next active window. That's not what the code tells it to do. Has anyone any idea how to disable the GUI without this unwanted behaviour?

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

_Main()

Func _Main()

    Local $sWinTitle
    $sWinTitle = "Reproducer Window"

    Local $hGUI = GUICreate($sWinTitle, 600, 400, Default, Default, BitOR($WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED))
    $ahMenuItem = _CreateMenus()
    Local $hEdit1
    _CreateEdit($hEdit1)

    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $ahMenuItem[2], $GUI_EVENT_CLOSE ; Exit
                Exit

            Case $ahMenuItem[1] ; New
                GUISetState(@SW_DISABLE, $hGUI)
                MsgBox(0, "Message", "New")
                GUISetState(@SW_ENABLE, $hGUI) ; GUI disappears behind other windows. Why?
        EndSwitch
    WEnd
EndFunc ;==>_Main

Func _CreateEdit(ByRef $hEdit)
    Local $dStyle = BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_NOHIDESEL)
    $hEdit = GUICtrlCreateEdit("", 0, 10, 600, 380, $dStyle, $WS_EX_LAYERED)
    GUICtrlSetResizing($hEdit, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM))
EndFunc ;==> _CreateEdit

Func _CreateMenus()
    Local $ahMenu[2] = [1, "File"]
    Local $ahMenuItem[3] = [2, _
    "New", _
    "Exit"]

    Local $iItemCount = 1
    ; FILE
    $ahMenu[1] = GUICtrlCreateMenu($ahMenu[1]) ; File
    For $i = $iItemCount To $iItemCount + 1
        $ahMenuItem[$iItemCount] = GUICtrlCreateMenuItem($ahMenuItem[$iItemCount], $ahMenu[1])
        $iItemCount += 1
    Next
    Return $ahMenuItem
EndFunc   ;==>_CreateMenus
Edited by czardas

Share this post


Link to post
Share on other sites



Use GUISetState(@SW_RESTORE, $hGUI) after enabling the GUI that will solve the problem.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use GUISetState(@SW_RESTORE, $hGUI) after enabling the GUI that will solve the problem.

Thanks, but there are two problems with this suggestion: Firstly the window may be maximised, in which case the GUI will restore down. Secondly I need to disable the GUI in 40 or more different circumstances, so the number of additional lines of code may become excessive. I really want just one or two lines of code to fix it permanently if possible (or a better solution).

BTW If you remove the message box from the script the window remains on top.

Edited by czardas

Share this post


Link to post
Share on other sites

czardas,

When I run your script, the GUI remains on top but also remains inactive when the MsgBox is closed. Adding a WinActivate line solves that. :)

I realise that you are probably not merely running a MsgBox when that menu item is actioned, but could I point out that if you were then you could avoid the problem by making the MsgBox modal - then your GUI is automatically disabled when the dialog is preset. The Modal MsgBox Styles tutorial in the Wiki explains the various modal states. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Melba, that's solved it. Less code needed than I had already. Posted Image

MsgBox(8243, "", "Do you want to save changes")

I still wonder why the GUI diappears on my machine and not yours.

Edited by czardas

Share this post


Link to post
Share on other sites

Case $ahMenuItem[1] ; New

                ; GUISetState(@SW_DISABLE, $hGUI)

                MsgBox(0, "Message", "New", 0, $hGUI)

                ; GUISetState(@SW_ENABLE, $hGUI) ; GUI disappears behind other windows. Why?

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  
Followers 0