Jump to content

Is the menu visible?


Recommended Posts

This is a scaled down reproducer. The label on my GUI can be updated manually or automatically. I can switch between these two modes using the Mode menu. However, when in Auto mode, if I click on the menu and ponder a while before deciding which mode to select, the automated actions become queued. As soon as I make a decision the GUI updates several steps in one hit. I would like to be able to freeze all action until either a mode has been selected or the menu display has disappeared.

How can I tell if the user clicked on 'Mode' main menu? Any suggestions would be appreciated.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $hGUI, $h_Mode, $h_Manual, $h_Auto, $h_Label
$hGUI = GUICreate("", 100, 120)
$h_Mode = GUICtrlCreateMenu("Mode")
$h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode)
$h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode)
$h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER)
GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS")
GUISetState()

Local $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F], $i_Mode = 0, $i_Count = 1

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $h_Manual
            $i_Mode = 0
        Case $h_Auto
            $i_Mode = 1
            Local $i_TmStrt = TimerInit(), $i_TmIntval = 2000
        Case $h_Label
            If $i_Mode = 0 Then _UpdateLabel($i_Count) ; Update the label manually.
    EndSwitch
    If $i_Mode = 1 Then ; Update the label automatically at regular intervals.
        If TimerDiff($i_TmStrt) > $i_TmIntval Then
            _UpdateLabel($i_Count)
            $i_TmIntval += 2000
        EndIf
    EndIf
WEnd

Func _UpdateLabel(ByRef $iCount) ; Changes the display.
    If $iCount = 10 Then $iCount = 1
    GUICtrlSetData($h_Label, $iCount)
    $iCount += 1
    GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($iCount, 3)])
EndFunc
Edited by czardas
Link to comment
Share on other sites

Why are you added 2000ms each time the timer has reached it's limit?

Why not reset the TimerInit() ?

If $i_Mode = 1 Then ; Update the label automatically at regular intervals.
        If TimerDiff($i_TmStrt) > 2000 Then
            _UpdateLabel($i_Count)
            $i_TmStrt = TimerInit()
        EndIf
    EndIf

*! I could be missing something, didn't read the whole post yet. This is just a small notice. !*

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Why are you added 2000ms each time the timer has reached it's limit?

Why not reset the TimerInit() ?

If $i_Mode = 1 Then ; Update the label automatically at regular intervals.
        If TimerDiff($i_TmStrt) > 2000 Then
            _UpdateLabel($i_Count)
            $i_TmStrt = TimerInit()
        EndIf
    EndIf

*! I could be missing something, didn't read the whole post yet. This is just a small notice. !*

Yes that helps, thanks! It's an improvement. Now it only leaps forward one step. haha! ;)

That is something I think I can probably just about live with. Although it would still be better if I could pause it completely.

Edited by czardas
Link to comment
Share on other sites

Is this what you want?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global Const $hGUI = GUICreate("", 100, 120)
Global Const $h_Mode = GUICtrlCreateMenu("Mode")
Global Const $h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode)
Global Const $h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode)
Global Const $h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER)
GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS")
GUISetState()

Global Const $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F]
Global $i_Mode = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $h_Manual
            $i_Mode = 0
        Case $h_Auto
            $i_Mode = 1
        Case $h_Label
            If $i_Mode = 0 Then _UpdateLabel() ; Update the label manually.
    EndSwitch

    If $i_Mode = 1 Then ; Update the label automatically at regular intervals.
        _UpdateLabel()
        Sleep(2000)
    EndIf
WEnd

Func _UpdateLabel() ; Changes the display.
    Local Static $i_Count = 1

    If $i_Count = 10 Then $i_Count = 1

    GUICtrlSetData($h_Label, $i_Count)

    GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($i_Count - 1, 3)])

    $i_Count += 1
EndFunc ;==>_UpdateLabel
Link to comment
Share on other sites

  • Moderators

czardas,

When you open the menu bar, you enter a modal loop which freezes the script until you exit the loop by choosing something. If you look for this exit, you can reset the timer and so not jump ahead. ;)

It is coded like this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $hGUI, $h_Mode, $h_Manual, $h_Auto, $h_Label, $i_TmStrt, $i_TmIntval = 2000

$hGUI = GUICreate("", 100, 120)
$h_Mode = GUICtrlCreateMenu("Mode")
$h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode)
$h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode)
$h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER)
GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS")
GUISetState()

GUIRegisterMsg(0x0212,"_WM_EXITMENULOOP") ; look for the WM_EXITMENULOOP message

Local $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F], $i_Mode = 0, $i_Count = 1

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $h_Manual
            $i_Mode = 0
        Case $h_Auto
            $i_Mode = 1
            $i_TmStrt = TimerInit()
        Case $h_Label
            If $i_Mode = 0 Then _UpdateLabel($i_Count) ; Update the label manually.
    EndSwitch
    If $i_Mode = 1 Then ; Update the label automatically at regular intervals.
        If TimerDiff($i_TmStrt) > $i_TmIntval Then
            _UpdateLabel($i_Count)
            $i_TmStrt = TimerInit()
        EndIf
    EndIf
WEnd

Func _UpdateLabel(ByRef $iCount) ; Changes the display.
    If $iCount = 10 Then $iCount = 1
    GUICtrlSetData($h_Label, $iCount)
    $iCount += 1
    GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($iCount, 3)])
EndFunc

Func _WM_EXITMENULOOP($hWnd, $iMsg, $wParam, $lParam)
    $i_TmStrt = TimerInit() ; Now reset the timer so we stay on the same menu number
EndFunc

I hope that is what you wanted. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I don't know what you did, but I can't switch backwards and forwards between modes anymore.

He did a Sleep(2000) instead of a TimerInit, TimerDiff.

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

  • Moderators

czardas,

I only learnt about those particular MENULOOP messages last week - glad I was able to put it to good use so soon afterwards. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Both you, M23, and AlmarM set me on the right path. I much appreciate it.

It's for a tic-tac-toe engine I made (I know it's old hat!), which has 5 playing modes and two levels of skill. When the computer plays against itself, the grid also displays an analysis by highlighting different fields using a colour scheme. A bit like a disco. ;)

Edited by czardas
Link to comment
Share on other sites

I only learnt about those particular MENULOOP messages last week - glad I was able to put it to good use so soon afterwards. :shocked:

I learned somethnig today! ;)

It's for a tic-tac-toe engine I made (I know it's old hat!), which has 5 playing modes and two levels of skill. When the computer plays against itself, the grid also displays an analysis by highlighting different fields using a colour scheme. A bit like a disco. ;)

Ah, yes... That made sence! :)

Also, glad I could help.

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Sheesh, I was way off the mark! I learned something new too, thanks M23!

Your input is still appreciated. The reason for not using sleep, in this situation, is so I can still interact with the controls whilst the display changes in automatic mode. The script needed to be slowed down in order to be able to observe the changes. M23's solution opens a lot of new possiblities I didn't know about. ;)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...