Sign in to follow this  
Followers 0
leomoon

GUICtrlOnHover and ExtMsgBox don't play nice together!

13 posts in this topic

Hello,

I wanted to add the GUICtrlOnHover to my program that already has ExtMsgBox but it seems they are not compatible with each other. I made a sample that you can test with both regular MsgBox and ExtMsgBox. When running with MsgBox, the script works fine but if you use ExtMsgBox, it will freeze. Also if you use ExtMsgBox and if you double click on the top left side icon to close it, it will close just fine!

Anybody knows how to make these two work together?

status-hover-test.zip

Share this post


Link to post
Share on other sites



leomoon,

I have just been experimenting and it seems that the problem lies with the GUICtrlOnHover UDF. Now I know you would expect me to say that as I wrote the ExtMsgBox UDF, but I will try and explain why I have come to that conclusion. :lol:

The ExtMsgBox UDF runs in MessageLoop mode - it sets it as soon as the _ExtMsgBox function is called but takes note of the mode being used at that moment. Whenever the function returns, it resets the mode to the original as it clears up. This is perfectly valid behaviour and should cause no problem at all.

I rewrote your script in MessageLoop mode and everything worked in harmony - you got the OnHover statusbar updates and the ExtMsgBox operated normally. However, if I leave your script in OnEvent mode, the same problem arises if I create a GUI within the script and try to switch to MessageLoop mode.

So my conclusion is that the GUICtrlOnHover UDF cannot cope with buttons after a mode change. A simple mode change does not throw an error on its own, it is only when you have a GUIGetMsg loop to detect the button press that the problems occur.

Here are 3 small example scripts to show you what I mean. Firstly a script started in OnEvent mode, switching to GetMessage mode when the second GUI is created - it shows the same symptoms as the script you posted above:

#include <GUIConstantsEx.au3>
#include "GUICtrlOnHover.au3"
#include "ExtMsgBox.au3"

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)

$hGUI = GUICreate("Form1", 266, 261, 248, 523)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")
$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "On_Button")
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc")

$hLabel = GUICtrlCreateLabel("", 10, 50, 200, 20)

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "Over Button")
    EndSwitch
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "")
    EndSwitch
EndFunc

Func On_Button()
    MsgBox(0, "", "Pressed")
EndFunc

Func On_Exit()

    Local $hGUI = GUICreate("Test", 300, 300, 100, 100)
    Local  $hButton = GUICtrlCreateButton("Exit",  10, 10, 80, 30)
    GUISetState()

    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    While 1
        If GUIGetMsg() = $hButton Then Exit
    WEnd

    Opt('GUIOnEventMode', $nOldOpt)

EndFunc

Next exactly the same script written in MessageLoop mode throughout. As you can see it still gives you the correct "hover" functions, but does not fail when the other GUI appears as there is no mode change:

#include <GUIConstantsEx.au3>
#include "GUICtrlOnHover.au3"
#include "ExtMsgBox.au3"

$hGUI = GUICreate("Test", 500, 500)

$hGUI = GUICreate("Form1", 266, 261, 248, 523)

$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc")

$hLabel = GUICtrlCreateLabel("", 10, 50, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            $hGUI = GUICreate("Test", 300, 300, 100, 100)
            $hButton = GUICtrlCreateButton("Exit",  10, 10, 80, 30)
            GUISetState()
            While 1
                If GUIGetMsg() = $hButton Then Exit
            WEnd
        Case $hButton
            MsgBox(0, "", "Pressed")
    EndSwitch

WEnd

Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "Over Button")
    EndSwitch
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "")
    EndSwitch
EndFunc

And finally, the first script rewritten so that the second GUI also uses OnEvent mode - again no mode change so no problem:

#include <GUIConstantsEx.au3>
#include "GUICtrlOnHover.au3"
#include "ExtMsgBox.au3"

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)

$hGUI = GUICreate("Form1", 266, 261, 248, 523)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")
$hButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "On_Button")
_GUICtrl_OnHoverRegister(-1, "_Hover_Proc", "_Leave_Hover_Proc")

$hLabel = GUICtrlCreateLabel("", 10, 50, 200, 20)

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "Over Button")
    EndSwitch
EndFunc

Func _Leave_Hover_Proc($iCtrlID)
    Switch $iCtrlID
        Case $hButton
            GUICtrlSetData($hLabel, "")
    EndSwitch
EndFunc

Func On_Button()
    MsgBox(0, "", "Pressed")
EndFunc

Func On_Exit()

    Local $hGUI = GUICreate("Test", 300, 300, 100, 100)
    Global $hButton = GUICtrlCreateButton("Exit",  10, 10, 80, 30)
    GUICtrlSetOnEvent(-1, "On_Exit_Button")
    GUISetState()

EndFunc

Func On_Exit_Button()
    Exit
EndFunc

As you can see it works perfectly. :x

So I hope you can see why I conclude that the problem is the GUICtrlOnHover UDF not being able to cope with a mode change in the script. I see 3 possible solutions:

- 1. Rewrite your script to use MessageLoop mode - the problem vanishes. :P

- 2. Make a modified version of ExtMsgBox to run in OnEvent mode. You are on your own here, the current UDF follows normal AutoIt conventions and I am not going to recode it. :nuke:

- 3. Ask MrCreatoR to make his GUICtrlOnHover UDF compatible with mode changes. Although I have not looked in detail at the UDF, this might be rather hard to do. :shifty:

My recommendation - use MessageLoop mode for your script - everything works perfectly in harmony then! :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Wow your replies are better than a book!!!

I just rewrote the GUI using MessageLoop mode. Everything works well except I can't stop a running function now. I think I read in the wiki in order to stop a function you have to use:

Opt("GUIOnEventMode", 1)

Share this post


Link to post
Share on other sites

Actually I found a sample to interrupt a running function in MessageLoop mode:

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

; Set a HotKey
HotKeySet("x", "_Interrupt")

; Declare a flag
$fInterrupt = 0

$hGUI = GUICreate("Test", 500, 500)

$hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30)
$hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30)

; Create a dummy control for the Accelerator to action when pressed
$hAccelInterupt = GUICtrlCreateDummy()
; Set an Accelerator key to action the dummy control
Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ]
GUISetAccelerators($AccelKeys)

GUISetState()

; Intercept Windows command messages with out own handler
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_1
            _Func_1()
        Case $hButton_2
            _Func_2()
    EndSwitch
WEnd

Func _Func_1()
    ; Make sure the flag is cleared
    $fInterrupt = 0
    For $i = 1 To 20
        ConsoleWrite("-Func 1 Running" & @CRLF)
        ; Look for the flag
        If $fInterrupt <> 0 Then
            ; The flag was set
            Switch $fInterrupt
                Case 1
                    ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF)
                Case 2
                    ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF)
                Case 3
                    ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF)
            EndSwitch
            Return
        EndIf
        Sleep(100)
    Next
    ConsoleWrite(">Func 1 Ended" & @CRLF)
EndFunc

Func _Func_2()
    For $i = 1 To 3
        ConsoleWrite("+Func 2 Running" & @CRLF)
        Sleep(100)
    Next
    ConsoleWrite(">Func 2 Ended" & @CRLF)
EndFunc

Func _Interrupt()
    ; The HotKey was pressed so set the flag
    $fInterrupt = 2
EndFunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    ; The Func 2 button was pressed so set the flag
    If BitAND($wParam, 0x0000FFFF) =  $hButton_2 Then $fInterrupt = 1
    ; The dummy control was actioned by the Accelerator key so set the flag
    If BitAND($wParam, 0x0000FFFF) =  $hAccelInterupt Then $fInterrupt = 3
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Tnx a lot for your help. :x

Share this post


Link to post
Share on other sites

leomoon,

I wrote the Wiki tutorial - as you have discovered there are examples for both OnEvent and MessageLoop mode. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I rewrote the script using messageloop. The bad thing about messageloop is the way it uses to interrupt functions. Specially when you're copying files.

With OnEvent I easily wrote it that it will pause copying when it's interrupted until the ExtMsgBox is answered. But with messageloop I haven't been able to do the same thing.

Sorry for back and forth writing! I think this post belongs here than in GUICtrlSetOnHover UDF.

Share this post


Link to post
Share on other sites

leomoon,

Between a rock and a hard place, by the sound of it! :x

If you post both sets of code I will take a look and see if I can suggest something. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hello again.

The actual script, after the proceedMbox is answered, it will run a function called listPrepare to collect paths and put them inside an array. Then it will send each path from the array to copyDir fuction.

copyDir will list all the files/folders inside that path and if it's a folder, it will create it; If it's a file, it will send it to another function called copyFile to copy the file with stats...

Now this is a simplified version of that. Instead of 3 functions inside each other, it just calls a for loop.

And it's written using my favorite OnEvent mode. If you run this, as soon as you click cancel when the for loop is running, it will pause the loop until the msgbox is answered.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;Count
#include <GUIConstants.au3>
#Include <GuiButton.au3>
;~ #Include <resources\Count.au3>
;ExtMsgBox
#include <Constants.au3>
#include <resources\ExtMsgBox.au3>

;Opt sets
Opt("GUIOnEventMode", 1)

;Variables
Global $proceedMbox, $startBtn, $cancelBtn, $mainFrm, $progressbar, $currentFileLbl
$Flg = False

_mainGui()

Func _mainGui()
    $mainFrm = GUICreate("Sample", 466, 74)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onBtn")
    $startBtn = GUICtrlCreateButton("Start", 384, 8, 75, 25)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $cancelBtn = GUICtrlCreateButton("Cancel", 384, 40, 75, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $progressbar = GUICtrlCreateProgress(8, 8, 369, 33)
    $currentFileLbl = GUICtrlCreateLabel("%:", 8, 48, 60, 17)
    GUISetState()
    While 1
        If $Flg = True Then
            _startCount()
            If $proceedMbox = 6 Then
                GUICtrlSetState($startBtn, $GUI_DISABLE)
                GUICtrlSetState($cancelBtn, $GUI_ENABLE)
                ;Start Count
                For $i = 0 to 100 step 1
                    Sleep(100)
                    GUICtrlSetData($progressbar, $i & " percent.")
                    GUICtrlSetData($currentFileLbl, $i & " percent.")
                Next
                sleep(500)
                For $i = 100 to 0 step -1
                    Sleep(100)
                    GUICtrlSetData($progressbar, $i & " percent.")
                    GUICtrlSetData($currentFileLbl, $i & " percent.")
                Next
                Sleep(500)
            Else
                GUICtrlSetState($startBtn, $GUI_ENABLE)
                GUICtrlSetState($cancelBtn, $GUI_DISABLE)
                $Flg = False
            EndIf
        Else
            Sleep(200)
        EndIf
    WEnd
EndFunc

Func _onBtn()
    Switch @GUI_CTRLID
        Case $GUI_EVENT_CLOSE
            If (MsgBox(4+8192, 'Exit?', 'Exit?')) = 6 Then Exit
        Case $startBtn
            $Flg = True
        Case $cancelBtn
            If $proceedMbox = 1 Then
                If (MsgBox(4+8192, 'Cancel?', 'Cancel?')) = 6 Then Exit
            Else
                If (MsgBox(4+8192, 'Exit?', 'Exit?')) = 6 Then Exit
            EndIf
    EndSwitch
EndFunc

Func _startCount()
    $proceedMbox = MsgBox(4+8192, 'Start?', 'Start?')
EndFunc
Edited by leomoon

Share this post


Link to post
Share on other sites

And here is the same code written in messageloop. I can't make it pause like the one above:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;Count
#include <GUIConstants.au3>
#Include <GuiButton.au3>
#include <Constants.au3>

$Flg = False
$proceedMbox = 0

$mainFrm = GUICreate("Sample", 466, 74)
$startBtn = GUICtrlCreateButton("Start", 384, 8, 75, 25)
$cancelBtn = GUICtrlCreateButton("Cancel", 384, 40, 75, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
$progressbar = GUICtrlCreateProgress(8, 8, 369, 33)
$currentFileLbl = GUICtrlCreateLabel("%:", 8, 48, 60, 17)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            If (MsgBox(4+8192, 'Exit?', 'Exit?')) = 6 Then Exit
        Case $cancelBtn
            If $proceedMbox = 1 Then
                If (MsgBox(4+8192, 'Cancel?', 'Cancel?')) = 6 Then Exit
            Else
                If (MsgBox(4+8192, 'Exit?', 'Exit?')) = 6 Then Exit
            EndIf
        Case $startBtn
            $Flg = True
            If $Flg = True Then
                If (MsgBox(4+8192, 'Start?', 'Start?')) = 6 Then
                    $proceedMbox = 1
                    GUICtrlSetState($startBtn, $GUI_DISABLE)
                    GUICtrlSetState($cancelBtn, $GUI_ENABLE)
                    ;Start Count
                    For $i = 0 to 100 step 1
                        Sleep(100)
                        GUICtrlSetData($progressbar, $i & " percent.")
                        GUICtrlSetData($currentFileLbl, $i & " percent.")
                    Next
                    sleep(500)
                    For $i = 100 to 0 step -1
                        Sleep(100)
                        GUICtrlSetData($progressbar, $i & " percent.")
                        GUICtrlSetData($currentFileLbl, $i & " percent.")
                    Next
                    Sleep(500)
                Else
                    GUICtrlSetState($startBtn, $GUI_ENABLE)
                    GUICtrlSetState($cancelBtn, $GUI_DISABLE)
                    $Flg = False
                EndIf
            Else
                Sleep(200)
            EndIf
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

leomoon,

I can get it to interrupt, but it makes the script overly complicated to my mind. :shifty:

I have been experimenting further and it seems the problem stems from the fact that when the GUICtrlOnHover UDF is used in OnEvent mode it really does not like being held up in a function on exit, regardless of the current mode. There are a look of hooks, etc within the UDF so I can only imagine that they do not enjoy such things. It is certainly over my head as to why it happens - I barely understand the UDF in the first place. :nuke:

From your original script it seems that you are only using the UDF to get a hint into the status bar when the cursor is over a button. If that is so, then we can remove the need for the UDF entirely, which will solve the proximate, if not the ultimate, problem. :x

Here is a short script showing how it might work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "ExtMsgBox.au3"

Opt("GUIOnEventMode", 1)

Global $aButtons[4]

$hGUI = GUICreate("Test", 500, 500)

$hGUI = GUICreate("Form1", 266, 261, 248, 523)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")
$aButtons[0] = GUICtrlCreateButton("Test 0", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "On_Button")
$aButtons[1] = GUICtrlCreateButton("Test 1", 10, 60, 80, 30)
$aButtons[2] = GUICtrlCreateButton("Test 2", 10, 110, 80, 30)
$aButtons[3] = GUICtrlCreateButton("Test 3", 10, 160, 80, 30)

$hLabel = GUICtrlCreateLabel("", 10, 230, 200, 20)

GUISetState()

While 1
    Sleep(10)
    _Hover_Check() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Func On_Button()
    MsgBox(0, "", "Pressed")
EndFunc

Func On_Exit()
    If _ExtMsgBox(0, "Yes|No", "", "Exit?") = 1 Then Exit
EndFunc

Func _Hover_Check() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; Where is the cursor
    $aCInfo = GUIGetCursorInfo($hGUI)
    ; See if it is over a button
    For $i = 0 To 3
        If $aCInfo[4] = $aButtons[$i] Then
            ; If so then write the hint - we check if we need to update to avoid flickering
            If GUICtrlRead($hLabel) <> GUICtrlRead($aButtons[$i]) Then GUICtrlSetData($hLabel, GUICtrlRead($aButtons[$i]))
            ExitLoop
        EndIf
    Next
    ; If we were not over a button then clear the hint
    If $i = 4 Then GUICtrlSetData($hLabel, "")
EndFunc

If you feel that this might be a possible solution, then I shall look into how we might make the function a little more elegant. :P

M23

Edit:

Perhaps like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "ExtMsgBox.au3"

Opt("GUIOnEventMode", 1)

Global $aButtons[4][2] = [[9999, "Hint 0"], [9999, "Hint 1"], [9999, "Hint 2"], [9999, "Hint 3"]]

$hGUI = GUICreate("Test", 500, 500)

$hGUI = GUICreate("Form1", 266, 261, 248, 523)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")
$aButtons[0][0] = GUICtrlCreateButton("Test 0", 10, 10, 80, 30)
GUICtrlSetOnEvent(-1, "On_Button")
$aButtons[1][0] = GUICtrlCreateButton("Test 1", 10, 60, 80, 30)
$aButtons[2][0] = GUICtrlCreateButton("Test 2", 10, 110, 80, 30)
$aButtons[3][0] = GUICtrlCreateButton("Test 3", 10, 160, 80, 30)

$hLabel = GUICtrlCreateLabel("", 10, 230, 200, 20)

GUISetState()

AdlibRegister("_Hover_Check")

While 1
    Sleep(10)
WEnd

Func On_Button()
    MsgBox(0, "", "Pressed")
EndFunc

Func On_Exit()
    If _ExtMsgBox(0, "Yes|No", "", "Exit?") = 1 Then Exit
EndFunc

Func _Hover_Check()
    ; Where is the cursor
    $aCInfo = GUIGetCursorInfo($hGUI)
    ; See if it is over a button
    For $i = 0 To 3
        If $aCInfo[4] = $aButtons[$i][0] Then
            ; If so then write the hint - we check if we need to update to avoid flickering
            If GUICtrlRead($hLabel) <> $aButtons[$i][1] Then GUICtrlSetData($hLabel, $aButtons[$i][1])
            ExitLoop
        EndIf
    Next
    ; If we are not over a button then clear the hint
    If $i = 4 Then GUICtrlSetData($hLabel, "")
EndFunc
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

leomoon,

Glad you found it useful. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Here is another sample I just wrote. It's the same sample I posted above (#8). I just added a sample status bar hint.

So this sample is written in OnEvent mode and is a good example for interrupting a running function. Also is a good example for people who want to make status hint.

You also need Melba23's awesome ExtMsgBox UDF cuz the original AutoIt one is not good!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#Include <GuiButton.au3>
;ExtMsgBox
#include <Constants.au3>
#include <ExtMsgBox.au3>

;Opt sets
Opt("GUIOnEventMode", 1)

;Variables
Global $proceedMbox, $startBtn, $cancelBtn, $mainFrm, $progressbar, $currentFileLbl, $sBar
$Flg = False

_mainGui()

Func _mainGui()
    $mainFrm = GUICreate("Sample", 466, 95)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onBtn")
    $startBtn = GUICtrlCreateButton("Start", 384, 8, 75, 25)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $cancelBtn = GUICtrlCreateButton("Cancel", 384, 40, 75, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $progressbar = GUICtrlCreateProgress(8, 8, 369, 33)
    $currentFileLbl = GUICtrlCreateLabel("%:", 8, 48, 60, 17)
    $sBar = _GUICtrlStatusBar_Create($mainFrm)
    Dim $sBarW[2] = [393, -1]
    _GUICtrlStatusBar_SetParts($sBar, $sBarW)
    _GUICtrlStatusBar_SetText($sBar, "", 1)
    _GUICtrlStatusBar_SetText($sBar, "Idle.",0)
    AdlibRegister("_hoverCheck")
    GUISetState()
    While 1
        If $Flg = True Then
            _startCount()
            If $proceedMbox = 1 Then
                GUICtrlSetState($startBtn, $GUI_DISABLE)
                GUICtrlSetState($cancelBtn, $GUI_ENABLE)
                _GUICtrlStatusBar_SetText($sBar, 'Counting...',0)
                ;Start Count
                For $i = 0 to 100 step 1
                    Sleep(100)
                    GUICtrlSetData($progressbar, $i & " percent.")
                    GUICtrlSetData($currentFileLbl, $i & " percent.")
                Next
                sleep(500)
                For $i = 100 to 0 step -1
                    Sleep(100)
                    GUICtrlSetData($progressbar, $i & " percent.")
                    GUICtrlSetData($currentFileLbl, $i & " percent.")
                Next
                Sleep(500)
            Else
                GUICtrlSetState($startBtn, $GUI_ENABLE)
                GUICtrlSetState($cancelBtn, $GUI_DISABLE)
                $Flg = False
            EndIf
        Else
            Sleep(200)
        EndIf
    WEnd
EndFunc

Func _onBtn()
    Switch @GUI_CTRLID
        Case $GUI_EVENT_CLOSE
            If (_ExtMsgBox($MB_ICONQuery, 'Yes|No', 'Oops!', 'Exit?'&@CRLF, 0, $mainFrm)) = 1 Then Exit
        Case $startBtn
            $Flg = True
        Case $cancelBtn
            If $proceedMbox = 1 Then
                _GUICtrlStatusBar_SetText($sBar, 'Paused.',0)
                If (_ExtMsgBox($MB_ICONQuery, 'Yes|No', 'Oops!', 'Cancel?'&@CRLF, 0, $mainFrm)) = 1 Then
                    Exit
                Else
                    _GUICtrlStatusBar_SetText($sBar, 'Counting...',0)
                EndIf
            Else
                If (_ExtMsgBox($MB_ICONQuery, 'Yes|No', 'Oops!', 'Exit?'&@CRLF, 0, $mainFrm)) = 1 Then Exit
            EndIf
    EndSwitch
EndFunc

Func _startCount()
    $proceedMbox = _ExtMsgBox($MB_ICONQuery, 'Yes|No', 'Oops!', 'Start?'&@CRLF, 0, $mainFrm)
EndFunc

Func _hoverCheck()
    If $proceedMbox <> 1 Then
        $aGetCursor = GUIGetCursorInfo($mainFrm)
        If $aGetCursor[4] = $startBtn Then
            _GUICtrlStatusBar_SetText($sBar, 'Hint: Start button.',0)
        ElseIf $aGetCursor[4] = $cancelBtn Then
            _GUICtrlStatusBar_SetText($sBar, 'Hint: Cancel button.',0)
        Else
            _GUICtrlStatusBar_SetText($sBar, 'Idle.',0)
        EndIf
    EndIf
EndFunc
Edited by leomoon

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