Jump to content

Recommended Posts

Posted (edited)

This is my true first project, and have a minor glitch with GUI_EVENT_CLOSE, and cannot locate the problem my self. This is not a full function code yet. However the GUI is for the most part, working. When I attempt to close it, I have to push the button twice in order for it to send the msg to close. Could someone take a minute and look at my code and tell me where I went wrong? Thanks in advance

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_TAB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hTab

_Main()

Func _Main()
    Local $hGUI
    Local $defaultstatus = "Ready", $status, $filemenu, $fileitem
    Local $helpmenu, $saveitem, $infoitem, $exititem, $recentfilesmenu
    Local $separator1, $viewmenu, $viewstatusitem, $okbutton, $cancelbutton
    Local $statuslabel, $msg, $file, $optionmenu, $optionmenuitem
    Local $version = "Beta 0.0.0.1", $versionlabel, $versionitem

    ; Create GUI
    $hGUI = GUICreate("VRS - MTGO Collection Analyzer", 616, 450)
    $hTab = _GUICtrlTab_Create($hGUI, 2, 0, 612, 410)

        $filemenu = GUICtrlCreateMenu("&File")
    $fileitem = GUICtrlCreateMenuItem("Open", $filemenu)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    $helpmenu = GUICtrlCreateMenu("Help")
    $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1)

    $separator1 = GUICtrlCreateMenuItem("", $filemenu, 2)   ; create a separator line

    $viewmenu = GUICtrlCreateMenu("Options", -1, 1)    ; is created before "?" menu
    $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlSetState(-1, $GUI_FOCUS)
    $versionitem = GUICtrlCreateMenuItem("Version", $viewmenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlSetState(-1, $GUI_FOCUS)

    $statuslabel = GUICtrlCreateLabel($defaultstatus, 2, 415, 492, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))
    $versionlabel = GUICtrlCreateLabel($version, 493, 415, 120, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))

    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

     ; Add tabs
    _GUICtrlTab_InsertItem($hTab, 0, "Collection Statistics")
    _GUICtrlTab_InsertItem($hTab, 1, "Mythic Rares")
    _GUICtrlTab_InsertItem($hTab, 2, "Rares")
    _GUICtrlTab_InsertItem($hTab, 3, "Special Rares")
    _GUICtrlTab_InsertItem($hTab, 4, "Uncommons")
    _GUICtrlTab_InsertItem($hTab, 5, "Commons")
    _GUICtrlTab_InsertItem($hTab, 6, "Boosters & More")
    _GUICtrlTab_InsertItem($hTab, 7, "Vanguard")
    _GUICtrlTab_InsertItem($hTab, 8, "Other")
    ; Loop until user exits
    While 1
        $msg = GUIGetMsg()

        If $msg = $fileitem Then
            $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
            If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu)
        EndIf
        If $msg = $viewstatusitem Then
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
        EndIf
        If $msg = $versionitem Then
            If BitAND(GUICtrlRead($versionitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($versionitem, $GUI_UNCHECKED)
                GUICtrlSetState($versionlabel, $GUI_HIDE)
            Else
                GUICtrlSetState($versionitem, $GUI_CHECKED)
                GUICtrlSetState($versionlabel, $GUI_SHOW)
            EndIf
        EndIf
        If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then ExitLoop
        If $msg = $infoitem Then MsgBox(0, "Info", "Only a test...")
    WEnd
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab
    $hWndTab = $hTab
    If Not IsHWnd($hTab) Then $hWndTab = GUICtrlGetHandle($hTab)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTab
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; The return value is ignored by the tab control
                Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                    _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
                    _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
;~                  Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case $NM_RELEASEDCAPTURE ; control is releasing mouse capture
                    _DebugPrint("$NM_RELEASEDCAPTURE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Posted

Hi and Welcome to the forums!

Think about it. First you are in a loop that only ends when it receives GUI_EVENT_CLOSE, and then you start another loop that also waits for GUI_EVENT_CLOSE :(

So just remove that second loop! :)

Posted

hehehe... Once I Was Blind, Now I See.

Thanks for the quick response

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Posted

Someone else also replied...this a switch...but I don't see your post anymore.

I looked into it, and gave it a whirl. Much cleaner, and more defined for what I need to add in...Thanks alot for your post even though i can't find it now!

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Posted (edited)

As i understand, using X or Close, you want to close your program, so beside of using ExitLoop, just use Exit, thats what you need.

Oh, as it was said before, delete this part, as i even dont know why its here:

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Edited by Makaule
  • 2 weeks later...
Posted

As i understand, using X or Close, you want to close your program, so beside of using ExitLoop, just use Exit, thats what you need.

Oh, as it was said before, delete this part, as i even dont know why its here:

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

Thanks for your reply as well.

I know why, 'cause I'm a noob, and did'nt understand how GUI_EVENT_CLOSE worked at that moment, but with your guys' help, I do now

Thanks again!

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

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
×
×
  • Create New...