Sign in to follow this  
Followers 0
strate

Your Techniques

6 posts in this topic

I had no idea what to call this so I picked, trick. It maybe more of a preference though. What kind of things do you do when you code to keep it clean and simple?

Almost all of my scripts have multiple windows and I work with OnEvent instead of loops. So to keep things easy for me when I need to close or open a window I call a function like the one below.

Func _Exit()
    Select
        Case @GUI_WinHandle = $h_Main ; Main Window
            $var = MsgBox(4 + 16 + 256 + 4096 + 262144, 'PPS V3', 'Do you wish to exit?')
            Switch $var
                Case 6 ; Yes
                    Exit
                Case 7 ; No
                    Return
            EndSwitch
        Case @GUI_WinHandle = $h_QuickLinksGUI ; Quick Links Window
            GUISetState(@SW_HIDE, $h_QuickLinksGUI)
            GUISetState(@SW_SHOW, $h_Main)
        Case @GUI_WinHandle = $h_Config ; Setup Window
            GUISetState(@SW_HIDE, $h_Config)
            GUISetState(@SW_SHOW, $h_Main)
    EndSelect
EndFunc   ;==>_Exit

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

I think you need a more specific example. But I'll try to go along with it. I never use OnEvent(), actually never have. I would have a main loop:

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Switch @GUI_WinHandle
                Case $h_Main
                    If MsgBox(0x44,"PPSv3","Do you really want to exit?") = 6 Then Exit
                Case $h_QuickLinksGUI
                    GUISetState(@SW_HIDE, $h_QuickLinksGUI)
                    GUISetState(@SW_SHOW, $h_Main)
                Case $h_Config
                    GUISetState(@SW_HIDE, $h_Config)
                    GUISetState(@SW_SHOW, $h_Main)
            EndSwitch
        Case ;something else
            ;some other action
    EndSwitch
WEnd

I believe this is exactly the same as yours.

Personally, I don't regularly have multiple windows operating simultaneously... I would have separate loops within the main loop for each window. Like I said, I could get more specific if you asked a more specific question.

Edited by crzftx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It seems to me that I have an OCD about making my scripts as neat as possible :)

That's why my script source is delayed when I release applications, I look through all the script for about an hour making sure that its all good.

Things I tend to look for:

Capitalized/Correct Spelling/Punctuations on any thing including variables, and functions.

I also make sure my functions are spaced apart and not squished up and not too spaced like:

Func  _ApplicationExit
Exit
EndFunc

Func  _MsgBox
Dllcall(...)
EndFuncoÝ÷ Ø(®Úq«^âÍèhÀe
í®l¢y²±Êâ¦Ùb殶­sbb33c´wVÒwV7&VFRââââ ¢b33c´'WGFöãÒââà¢b33c´'WGFöã"Òââà ¢b33c´6V6´&÷Òââà ¢b33c´çWCÒââà¤wV6WE7FFR ¥vÆR¥tVæ

Stuff like that.

Edited by JustinReno

Share this post


Link to post
Share on other sites

I had no idea what to call this so I picked, trick. It maybe more of a preference though. What kind of things do you do when you code to keep it clean and simple?

Almost all of my scripts have multiple windows and I work with OnEvent instead of loops. So to keep things easy for me when I need to close or open a window I call a function like the one below.

Func _Exit()
    Select
        Case @GUI_WinHandle = $h_Main ; Main Window
            $var = MsgBox(4 + 16 + 256 + 4096 + 262144, 'PPS V3', 'Do you wish to exit?')
            Switch $var
                Case 6 ; Yes
                    Exit
                Case 7 ; No
                    Return
            EndSwitch
        Case @GUI_WinHandle = $h_QuickLinksGUI ; Quick Links Window
            GUISetState(@SW_HIDE, $h_QuickLinksGUI)
            GUISetState(@SW_SHOW, $h_Main)
        Case @GUI_WinHandle = $h_Config ; Setup Window
            GUISetState(@SW_HIDE, $h_Config)
            GUISetState(@SW_SHOW, $h_Main)
    EndSelect
EndFunc   ;==>_Exit
That's the way I do mine. I prefer GuiOnEventMode these days, and also prefer to cover multiple events with each handler function. You've done both nicely here, it looks to me.

;)

P.S. Don't listen to those addicted to the GuiGetMsg loop! :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I also never use OnEvent mode.

When I have multiple windows I call them in a function.

MainGui()

PluginManager() (Parent is MainGui)

EditPlugin() (Parent is PluginManager)

-MainGui gets called if there are no silent command line options.

-Each function gets its on message loop.

-I comment the hell out of my code

-I am not happy until I can reduce a script into the smallest amount of code (or less code than Sm0ke or Psalty :) )

Share this post


Link to post
Share on other sites

@crzftx: Actually your example code would error out pretty fast in a real application (and I'm not talking about the incomplete Case at the end of your first Switch). You say you use message loop mode, yet you reference @GUI_WinHandle? ;)

A corrected version of that snippet might look like this.

While 1
    $aGUIMsg = GUIGetMsg(1) ; Advanced mode
    Switch $aGUIMsg[0] ; Event or Control ID
        Case $GUI_EVENT_CLOSE
            Switch $aGUIMsg[1] ; Window handle causing the event
                Case $h_Main
                    If MsgBox(0x44,"PPSv3","Do you really want to exit?") = 6 Then Exit
                Case $h_QuickLinksGUI
                    GUISetState(@SW_HIDE, $h_QuickLinksGUI)
                    GUISetState(@SW_SHOW, $h_Main)
                Case $h_Config
                    GUISetState(@SW_HIDE, $h_Config)
                    GUISetState(@SW_SHOW, $h_Main)
            EndSwitch
        ;~ Case ;something else
            ;some other action
    EndSwitch
WEnd

I notice you mention your technique for multiple GUIs at the bottom of your post though so I can understand your confused code. Just thought I'd make a correction so you might know for future use. :)

Personally I have a habit of overloading my functions (using GUI onevent mode). For example I have this piece of code in a program I'm currently working on:

Func _Generic()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            If @GUI_WinHandle = $gui_Main Then
                GUISetState(@SW_HIDE, $gui_Main)
                GUISetState(@SW_HIDE, $gui_View)
            Else
                GUISetState(@SW_HIDE, $gui_View)
                GUICtrlSetData($lb_View_Index, '')
                GUICtrlSetData($ed_View_Text, '')
                $bViewVisible = False
            EndIf
        Case $ch_Main_HotKey
            If BitAND(GUICtrlRead($ch_Main_HotKey), $GUI_CHECKED) Then
                $sNewKey = _ChooseHotKey($sHotKey, 0, 'Choose HotKey', Default, Default, Default, Default, $gui_Main)
                If @error Then
                    GUICtrlSetState($ch_Main_HotKey, $GUI_UNCHECKED)
                Else
                    If Not @extended Then
                        GUICtrlSetState($ch_Main_HotKey, $GUI_UNCHECKED)
                        MsgBox(0x42030, 'Notice', 'Hotkey ' & _HotKeyToString($sNewKey) & ' unavailable, possibly in use by another program.')
                    ElseIf HotKeySet($sNewKey, '_ShowWindow') Then
                        $sHotKey = $sNewKey
                    Else
                        GUICtrlSetState($ch_Main_HotKey, $GUI_UNCHECKED)
                        MsgBox(0x42030, 'Notice', 'Hotkey unable to be used for unknown reasons.')
                    EndIf
                EndIf
            Else
                HotKeySet($sHotKey)
            EndIf
        Case $bt_Main_Copy
            _ClipCopyOrPaste()
        Case $bt_Main_Paste
            _ClipCopyOrPaste(True)
        Case $bt_Main_View
            If BitAND(WinGetState($gui_View), 2) Then
                $bViewVisible = False
                GUISetState(@SW_HIDE, $gui_View)
            Else
                Local $aWinPosMain = WinGetPos($gui_Main)
                Local $aWinPosView = WinGetPos($gui_View)
                If $sViewWindowDock = 'left' Then
                    WinMove($gui_View, '', $aWinPosMain[0] - $aWinPosView[2], $aWinPosMain[1])
                Else
                    WinMove($gui_View, '', $aWinPosMain[0] + $aWinPosMain[2], $aWinPosMain[1])
                EndIf
                $bViewVisible = True
                GUISetState(@SW_SHOWNA, $gui_View)
                _ClipListChange()
            EndIf
        Case $bt_View_Save
            _ClipSave(GUICtrlRead($lb_View_Index))
        Case $bt_View_SaveFile
            _ClipSave()
    EndSwitch
EndFunc

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