Sign in to follow this  
Followers 0
VertigoRay

GUICtrlCreateLabel failure

4 posts in this topic

#1 ·  Posted (edited)

Hello,

First, I want to give my thanks to the AutoIt team for their awesome work. I've saved and helped save countless hours in automation, courtesy of AutoIt.

Before I ask my question, I have searched the forums extensively and was unable to turn-up a similar problem. If this has already been asked, I apologize in advance.

I have been working on an installer wrapper that I can use to standardize my installer GUIs. This way I can more easily re-use my logic. Everything seems to work great except for a small problem that occurs on the Finish page:

Func _GUI_createPage loads the installer page, but for some reason when calling the final page, it flips out and wants to fail when running the GUICtrlCreateLabel function. I haven't figured out why, yet. Anyone have any thoughts?

Note: None of the fields are processed. There is no functionality in this script except navigation. You can leave the fields blank as you toggle through the GUI.

Thank you in advance for taking the time to look through my code.

#NoTrayIcon
#AutoIt3Wrapper_icon=images\favicon.ico

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
#include <Array.au3> ; Used with GUI Controls
#include <Constants.au3> ; For Stdout
#include <GUIConstants.au3>
#include <GuiListView.au3>
;#include "..\au3_CasLog\caslog.au3"

#region Globals
Global $CASGUI_version = '0.13.923.645'
Global $nslookup_stdout
Global $ScriptName = StringRegExpReplace(@ScriptName, "\.au3|\.exe$", '')
Global $fileWorkingName = @TempDir & '\' & $ScriptName
Global $inifile = @ScriptDir & '\' & $ScriptName & '.ini'

Global $backup_folder
Global $computer_ip = IniRead($inifile, "main", "computer_ip", '')
Global $computer_name = IniRead($inifile, "main", "computer_name", '')
Global $copySubDir = IniRead($inifile, "main", "copySubDir", '\')
Global $copyTo = IniRead($inifile, "main", "copyTo", 'C:\OLD_Win32\%RemoteComputer%')
Global $defaultPassword = IniRead($inifile, "main", "defaultPassword", '')
Global $CASGUI_adminPasswd
Global $CASGUI_back_btn
Global $CASGUI_cancel_btn
Global $CASGUI_computerIP
Global $CASGUI_computerName
Global $CASGUI_created = False
Global $CASGUI_error_code
Global $CASGUI_error_label
Global $CASGUI_error_msg
Global $CASGUI_finish_btn
Global $CASGUI_items[1]
Global $CASGUI_itemsIndex[1]
Global $CASGUI_itemsPageSet[200]
Global $CASGUI_loading_msg
Global $CASGUI_next_btn
Global $CASGUI_numberOfPages = 3 ; include First & Finish page, NOT loading/processing/negative pages.
Global $CASGUI_pageCurr
Global $CASGUI_pageNext
Global $CASGUI_pagePrev
Global $CASGUI_startCopy
Global $CASGUI_startOver_btn
Global $CASGUI_window
Global $remoteDrive = IniRead($inifile, "main", "remoteDrive", 'c')
Global $printer_lst
Global $printerIP
Global $printerQueueLong
#endregion Globals

#region GUI Setup
_GUI_itemPageSet()

Local $appName = "Scotty 2 Hotty Copy"
Local $appLog = 'C:\Windows\Debug\CAS\Scotty2HottyCopy.log'
#endregion GUI Setup

;LogStart($appName, $appLog)

; Check to see if the OS it's being run on is Windows 2K or Windows XP, all others fail.
Local $OSVer = @OSVersion
If $OSVer <> "Win_XP" Then
    If $OSVer <> "Win_2000" Then
        MsgBox(48, "Wrong OS Version", "Sorry, you are running " & $OSVer & ", this program is for Windows 2000 or XP only.")
        Exit
    EndIf
EndIf

_GUI_Create()

While 1
    Sleep(5000)
WEnd

#cs ----------------------------------------------------------------------------
    
    Functions
    
#ce ----------------------------------------------------------------------------

Func _GUI_Create($page = 0)
    If $CASGUI_created Then _GUI_itemHideAll()
    
    If $page > -1 Then
        $CASGUI_pageCurr = $page
        $CASGUI_pageNext = $page + 1
        If $page > 0 Then
            $CASGUI_pagePrev = $page - 1
        Else
            $CASGUI_pagePrev = 0
        EndIf
    EndIf
    
    ;MsgBox(0, 'Pages', $CASGUI_pagePrev &':'& $CASGUI_pageCurr &':'& $CASGUI_pageNext)
    
    #region ### START GUI section ###
    If Not $CASGUI_created Then
        $CASGUI_window = GUICreate(@ComputerName &' - '& $appName, 500, 360)
        GUISetIcon('.\images\favicon.ico')
        GUISetBkColor(0xFFFFFF)
        GUICtrlCreatePic(".\images\box-base.bmp", 0, 0, 500, 360)
        GUICtrlSetState(-1, $GUI_DISABLE) ;disable the BG image or it will screw up the forground functionality
        
        $CASGUI_back_btn = GUICtrlCreateButton("&< Back", 140, 325, 121, 25, 0)
        GUICtrlSetOnEvent($CASGUI_back_btn, "_GUI_btnclick_BACK")
        GUICtrlSetState($CASGUI_back_btn, $GUI_HIDE)
        $CASGUI_next_btn = GUICtrlCreateButton("&Next >", 265, 325, 121, 25, 0)
        GUICtrlSetOnEvent($CASGUI_next_btn, "_GUI_btnclick_NEXT")
        GUICtrlSetState($CASGUI_next_btn, $GUI_HIDE)
        $CASGUI_cancel_btn = GUICtrlCreateButton("&Cancel", 390, 325, 105, 25, 0)
        GUICtrlSetOnEvent($CASGUI_cancel_btn, "_GUI_btnclick_CANCEL")
        GUICtrlSetState($CASGUI_cancel_btn, $GUI_HIDE)
        $CASGUI_startOver_btn = GUICtrlCreateButton("&<< Start Over", 265, 325, 121, 25, 0)
        GUICtrlSetOnEvent($CASGUI_startOver_btn, "_GUI_btnclick_STARTOVER")
        GUICtrlSetState($CASGUI_startOver_btn, $GUI_HIDE)
        $CASGUI_finish_btn = GUICtrlCreateButton("&Finish", 390, 325, 105, 25, 0)
        GUICtrlSetOnEvent($CASGUI_finish_btn, "_GUI_btnclick_CANCEL")
        GUICtrlSetState($CASGUI_finish_btn, $GUI_HIDE)
        
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_btnclick_CANCEL")
    EndIf
    
    _GUI_displayButtons($page)
    
    ;MsgBox(0, '_GUI_itemPageSet('& $page &')', _GUI_itemPageSet($page))
    If _GUI_itemPageSet($page) Then
        _GUI_itemShowPage($page)
    Else
        _GUI_createPage($page)
    EndIf
    
    ;GUICtrlCreateLabel($CASGUI_pagePrev &':'& $CASGUI_pageCurr &':'& $CASGUI_pageNext, 164, 293, 336, 20, 0x0001) ; debuggin
    If Not $CASGUI_created Then GUISetState(@SW_SHOW, $CASGUI_window)
    $CASGUI_created = True
    #endregion ### START GUI section ###
EndFunc   ;==>_GUI_Create

Func _GUI_btnclick_BACK()
    ;GUISetState(@SW_HIDE, $CASGUI_window)
    ;MsgBox(0, $ScriptName &' - _GUI_btnclick_BACK', $CASGUI_pagePrev &':'& $CASGUI_pageCurr &':'& $CASGUI_pageNext)
    _GUI_Create($CASGUI_pagePrev)
EndFunc   ;==>btnclick_BACK

Func _GUI_btnclick_CANCEL()
    ;LogEnd($appLog)
    Exit
EndFunc   ;==>btnclick_CANCEL

Func _GUI_btnclick_NEXT()
    ;GUISetState(@SW_HIDE, $CASGUI_window)
    ;MsgBox(0, $ScriptName &' - _GUI_btnclick_NEXT', $CASGUI_pagePrev &':'& $CASGUI_pageCurr &':'& $CASGUI_pageNext)
    If _GUI_processPage($CASGUI_pageCurr) Then
        _GUI_Create($CASGUI_pageNext)
        _GUI_errorClear()
    Else
        _GUI_Create($CASGUI_pagePrev)
        _GUI_errorDisplay()
    EndIf
EndFunc   ;==>btnclick_NEXT

Func _GUI_btnclick_STARTOVER()
    _GUI_Create(0)
EndFunc   ;==>_GUI_btnclick_STARTOVER

Func _GUI_createPage($page)
    Switch $page
        Case -1 ; Loading
            _GUI_itemAdd($page, GUICtrlCreateIcon(@WindowsDir &"\Cursors\hourgla3.ani", -1, 305, 80, 50, 50))
            GUISetFont(14, 800)
            $CASGUI_loading_msg = GUICtrlCreateLabel("Loading ...", 164, 135, 336, 178, 0x0002)
            _GUI_itemAdd($page, $CASGUI_loading_msg)
            GUICtrlSetColor(-1, 0xAAAAAA)
            GUICtrlSetStyle(-1, $SS_CENTER)
            ;GUICtrlSetBkColor(-1, 0x00ff00) ; green
            GUISetFont(10, 400)
        Case 0 ; First Page
            GUISetFont(20, 800)
            _GUI_itemAdd($page, GUICtrlCreateLabel("and", 172, 135, 140, 30, 0x0002))
            GUICtrlSetColor(-1, 0xAAAAAA)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            GUISetFont(10, 400)
            _GUI_itemAdd($page, GUICtrlCreateLabel("Please input both the IP address and the computer" & @CRLF & "name of the computer to be connected to and copied.", 172, 3, 400, 40))
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            _GUI_itemAdd($page, GUICtrlCreateLabel("Name:", 172, 90, 98, 18, 0x0002))
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            $CASGUI_computerName = GUICtrlCreateInput($computer_name, 272, 90, 200, 20)
            _GUI_itemAdd($page, $CASGUI_computerName)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            _GUI_itemAdd($page, GUICtrlCreateLabel("IP:", 172, 190, 98, 18, 0x0002))
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            $CASGUI_computerIP = GUICtrlCreateInput($computer_ip, 272, 190, 200, 20)
            _GUI_itemAdd($page, $CASGUI_computerIP)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        Case 1
            _GUI_itemAdd($page, GUICtrlCreateLabel("Admin Password:", 172, 90, 98, 18, 0x0002))
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            $CASGUI_adminPasswd = GUICtrlCreateInput($defaultPassword, 272, 90, 200, 20, $ES_PASSWORD)
            _GUI_itemAdd($page, $CASGUI_adminPasswd)
            GUICtrlSetState(-1, $GUI_FOCUS)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            ;$CASGUI_startCopy = GUICtrlCreateCheckbox('Start Copy Immediately', 265, 120, 200, 20)
            ;GUICtrlSetState(-1, $CASGUI_CHECKED)
            GUISetFont(12, 800)
            _GUI_itemAdd($page, GUICtrlCreateLabel($computer_name, 164, 53, 336, 25, 0x0001))
        Case Else ; Finish
            _GUI_itemAdd($page, GUICtrlCreateLabel("Successfully Completed Copy!" & @CRLF & @CRLF & "From: "& @CRLF & $computer_name & '\' & $remoteDrive & '$' & $copySubDir & @CRLF & @CRLF & "To: "& @CRLF & $copyTo, 164, 35, 336, 178, 0x0002))
            GUICtrlSetColor(-1, 0xAAAAAA)
            GUICtrlSetStyle(-1, $SS_CENTER)
            
            _ArrayDisplay($CASGUI_itemsIndex, '$CASGUI_itemsIndex')
            _ArrayDisplay($CASGUI_items, '$CASGUI_items')
            _ArrayDisplay($CASGUI_itemsPageSet, '$CASGUI_itemsPageSet')
    EndSwitch
EndFunc

Func _GUI_displayButtons($btnConfig = 1)
    Switch $btnConfig
        Case -1 ; Loading
            GUICtrlSetState($CASGUI_back_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_back_btn, $GUI_DISABLE)
            GUICtrlSetState($CASGUI_next_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_next_btn, $GUI_DISABLE)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_startOver_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_finish_btn, $GUI_HIDE)
        Case 0 ; First Page
            GUICtrlSetState($CASGUI_back_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_next_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_next_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_startOver_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_finish_btn, $GUI_HIDE)
        Case 1 To $CASGUI_numberOfPages-2
            GUICtrlSetState($CASGUI_back_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_back_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_next_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_next_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_startOver_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_finish_btn, $GUI_HIDE)
        Case Else ; Finish
            GUICtrlSetState($CASGUI_back_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_next_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_cancel_btn, $GUI_HIDE)
            GUICtrlSetState($CASGUI_startOver_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_startOver_btn, $GUI_ENABLE)
            GUICtrlSetState($CASGUI_finish_btn, $GUI_SHOW)
            GUICtrlSetState($CASGUI_finish_btn, $GUI_ENABLE)
    EndSwitch
EndFunc   ;==>_GUI_displayButtons

Func _GUI_errorClear()
    ;MsgBox(0, $ScriptName &' - _GUI_errorClear', '!')
    GUISetState($CASGUI_error_label, $GUI_HIDE)
EndFunc   ;==>_GUI_errorClear

Func _GUI_errorDisplay()
    ;MsgBox(0, $ScriptName &' - _GUI_errorDisplay', '!')
    $CASGUI_error_label = GUICtrlCreateLabel($CASGUI_error_code & ': ' & $CASGUI_error_msg, 164, 293, 336, 20, 0x0001)
    GUICtrlSetColor(-1, 0xff0000)
    GUISetState($GUI_SHOW)
EndFunc   ;==>_GUI_errorDisplay

Func _GUI_errorSet($msg = '', $code = '')
    ;MsgBox(0, $ScriptName &' - _GUI_errorSet', $msg &@CRLF& $code)
    $CASGUI_error_msg = $msg
    $CASGUI_error_code = $code
EndFunc   ;==>_GUI_errorSet

Func _GUI_itemAdd($page, $itemControlID)
    Local $pageMod = Abs($page)
    If $page < 0 Then $pageMod += 100
    
    _ArrayAdd($CASGUI_items, $itemControlID)
    _ArrayAdd($CASGUI_itemsIndex, $pageMod)
    
    $CASGUI_itemsPageSet[$pageMod] = True
EndFunc   ;==>_GUI_itemAdd

Func _GUI_itemHide($itemControlID)
    ;MsgBox(0, $ScriptName &' - _GUI_itemHide', $itemControlID)
    GUICtrlSetState($itemControlID, $GUI_HIDE)
EndFunc   ;==>_GUI_itemHide

Func _GUI_itemHideAll()
    For $v In $CASGUI_items
        _GUI_itemHide($v)
    Next
EndFunc   ;==>_GUI_itemHideAll

Func _GUI_itemPageSet($page = 'null')
    If $page == 'null' Then
        For $i = 0 To UBound($CASGUI_itemsPageSet)-1
            $CASGUI_itemsPageSet[$i] = False
        Next
        Return True
    EndIf
    
    Local $pageMod = Abs($page)
    If $page < 0 Then $pageMod += 100
    
    ;MsgBox(0, '$CASGUI_itemsPageSet[$pageMod]', $pageMod & @CRLF & $CASGUI_itemsPageSet[$pageMod])
    Return $CASGUI_itemsPageSet[$pageMod]
EndFunc   ;==>_GUI_itemPageSet

Func _GUI_itemShow($itemControlID)
    GUICtrlSetState($itemControlID, $GUI_SHOW)
EndFunc   ;==>_GUI_itemShow

Func _GUI_itemShowPage($page)
    Local $pageMod = Abs($page)
    If $page < 0 Then $pageMod += 100
    
    Local $index = 0
    For $v In $CASGUI_itemsIndex
        ;MsgBox(0, '$v', '$v: '& $v & @CRLF &'$page: '& $page)
        If $v = $pageMod Then
            ;MsgBox(0, '_GUI_itemShow', '$index: '& $index & @CRLF &'$CASGUI_itemsIndex: '& $CASGUI_itemsIndex[$index] & @CRLF &'$CASGUI_items: '& $CASGUI_items[$index])
            ;_ArrayDisplay($CASGUI_itemsIndex, '$CASGUI_itemsIndex')
            _GUI_itemShow($CASGUI_items[$index])
        EndIf
        $index += 1
    Next
EndFunc   ;==>_GUI_itemShowAll

Func _GUI_processPage($page)
    _GUI_Create(-1)
    Switch $page
        Case -1
        Case Else
            ;_GUI_errorSet('This is just a test!', '1234')
            Sleep(1000)
            Return True
    EndSwitch
EndFunc
Edited by VertigoRay

Figure IT out!http://vertigion.com

Share this post


Link to post
Share on other sites



/bump ...

Just wanted to see if I could get a response of sorts ...

:)


Figure IT out!http://vertigion.com

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Welcome to the forums!

Overall, it's a good effort. Here are the main problems I saw:

_GUI_errorClear() is being called before _GUI_errorDisplay(), so the control referenced by $CASGUI_error_label doesn't always exist.

You're using GUISetState() instead of GUICtrlSetState().

Try this:

Func _GUI_errorClear()
    ;MsgBox(0, $ScriptName &' - _GUI_errorClear', '!')
;~     GUISetState($CASGUI_error_label, $GUI_HIDE) ; Won't work
    If $CASGUI_error_label Then GUICtrlSetState($CASGUI_error_label, $GUI_HIDE)
EndFunc   ;==>_GUI_errorClear

Func _GUI_errorDisplay()
    ;MsgBox(0, $ScriptName &' - _GUI_errorDisplay', '!')
    $CASGUI_error_label = GUICtrlCreateLabel($CASGUI_error_code & ': ' & $CASGUI_error_msg, 164, 293, 336, 20, 0x0001)
    GUICtrlSetColor(-1, 0xff0000)
;~     GUISetState($GUI_SHOW) ; Already visible - Won't do anything
    GUICtrlSetState($CASGUI_error_label, $GUI_SHOW)
EndFunc   ;==>_GUI_errorDisplay

Even though this worked in my testing, I still don't like the approach. If _GUI_errorDisplay() is called multiple times, the variable will be reused but extra labels will be created.

Since you're not doing any dynamic layouts, my suggestion would be to create every control when you build the GUI and then only show/hide/modify them rather than creating them on-the-fly.

Note that I didn't play with the icons, BMP's, or INI's, so you're on your own there.

Good luck!

@Edit: error_label, not error_code

Edited by Skruge

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Welcome to the forums!

Overall, it's a good effort. Here are the main problems I saw:

_GUI_errorClear() is being called before _GUI_errorDisplay(), so the control referenced by $CASGUI_error_label doesn't always exist.

You're using GUISetState() instead of GUICtrlSetState().

WOW! I was not even looking at these two functions for the error that would break my displays. Thank you so much! It works great now.

Since you're not doing any dynamic layouts, my suggestion would be to create every control when you build the GUI and then only show/hide/modify them rather than creating them on-the-fly.

The idea is to be able to use this as my standard wrapper. It's not using any dynamic pages now, but it may in the future.

Welcome to the forums!

Thank you. :)

Figure IT out!http://vertigion.com

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