1
\$\begingroup\$

So I wrote this to simulate a program that would have a start and stop feature, and has a tab design. Right now there is a tab that has a RichEdit object intended to be a running log.

As you can see, after we "start" the program I put just some milliseconds of sleep to simulate running instructions. I created a function to check for requests that would be called on a larger scale randomly throughout code to ping the GUI per say.

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

Global Const $h_numOfTabs = 2
Global Enum $H_TAB_1, $H_TAB_2, $H_TAB_END
Global $hGui, $h_logRichEdit, $iMsg,  $h_tabs, $h_startButton, $h_stopButton

Example()

Func Example()
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 400, 550, -1, -1)

    ; ADD START AND STOP BUTTONS
    $h_startButton = GUICtrlCreateButton( "Start", 50, 450 )
    $h_stopButton = GUICtrlCreateButton( "Stop", 150, 450 )

    $h_tabs = GUICtrlCreateTab( 5, 5, 390,375 )

    ; LOG TAB
    GUICtrlCreateTabItem( "Log" )
    $h_logRichEdit = _GUICtrlRichEdit_Create ( $hGui, "", 8, 30, 384, 347, BitOR( $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ) )

    ; STATS TAB
    GUICtrlCreateTabItem( "Stats" )

    ; Close TABS
    GUICtrlCreateTabItem( "" )

    GUISetState( @SW_SHOW ) ; initialize the gui

    While True
        CheckRequests()
    WEnd
EndFunc   ;==>Example

Func Start()
    while true
        Sleep(100)
        CheckRequests()
    WEnd
EndFunc

Func Stop()

EndFunc

Func CheckRequests()
    $iMsg = GUIGetMsg()
    while $iMsg <> 0
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($h_logRichEdit) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
            Case $iMsg = $h_tabs
                Switch GUICtrlRead( $h_tabs )
                    Case $H_TAB_1
                        ControlShow( $hGui, "", $h_logRichEdit )
                    Case Else
                        ControlHide( $hGui, "", $h_logRichEdit )
                EndSwitch
            Case $iMsg = $h_startButton
                Start()
            Case $iMsg = $h_stopButton
                Stop()
        EndSelect
        $iMsg = GUIGetMsg()
    WEnd
EndFunc

At about 500ms sleep, the lag when switching tabs is visible.

My question: On a larger scale, is this how we would handle/update things that are specific to a tab while running a larger program? If not, what would be a more efficient way of updating tab specific properties while running a larger overall program.

I have also seen a design recently where all the tabs and related components were their own GUI's but I am not sure the relevance of everything being its own GUI and if it pertains to this question.

Any help or clarification is greatly appreciated, I am new to AutoIT and trying to figure out some do's and dont's as well as efficiency.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.