Jump to content
BBs19

MetroGUI UDF v5.1 - Windows 10 style buttons, toggles, radios, menu etc.

Recommended Posts

17 hours ago, Mannyfresh15 said:

I'm using this UDF now and I think it's great. However, I would like to know if there is a way to set a timeout for the msgbox and also if there is a way to enable the toggle once a function is called or launched. Does anybody know???

 

Hi, there is no timeout function built in, but I don't think that will be a problem. I will add it the next time when I fix some bugs and upload a new version.

I am not sure what u mean by "enable the toggle once a function is called or launched", why wouldn't it be possible to enable it from a function? All you have to do is add "_Metro_ToggleCheck($Toggle1)" to your function.

Share this post


Link to post
Share on other sites
1 hour ago, BBs19 said:

Hi, there is no timeout function built in, but I don't think that will be a problem. I will add it the next time when I fix some bugs and upload a new version.

I am not sure what u mean by "enable the toggle once a function is called or launched", why wouldn't it be possible to enable it from a function? All you have to do is add "_Metro_ToggleCheck($Toggle1)" to your function.

Well let try to explain this...

I'm writing a script which has a function and inside that function is a while loop I want to be able to toggle the toggle in the main GUI on and off while in the loop and cheek if the toggle has changed to turn the toggle function on/off while in there ...I haven't been able to achieve that. However, I can toggle the toggle before such function is called. I hope I have explained my self well enough.

 

P.S. I have achieved it with regular checkbox but a nice toggle would be nice. (: I haven't checked your new checkbox although they look nice. Will try them soon.

Edited by Mannyfresh15

Share this post


Link to post
Share on other sites
15 minutes ago, Mannyfresh15 said:

Well let try to explain this...

I'm writing a script which has a function and inside that function is a while loop I want to be able to toggle the toggle in the main GUI on and off while in the loop and cheek if the toggle has changed to turn the toggle function on/off while in there ...I haven't been able to achieve that. However, I can toggle the toggle before such function is called. I hope I have explained my self well enough.

 

P.S. I have achieved it with checkbox but a nice toggle would be nice. (:

Well then u have to do the same that you would do in your main while loop:

Func _YourFunctionWithWhileLoop()
    While 1
        _Metro_HoverCheck_Loop($Form1);To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    ConsoleWrite("Toggle unchecked!" & @CRLF)
                Else
                    _Metro_ToggleCheck($Toggle1)
                    ConsoleWrite("Toggle checked!" & @CRLF)
                EndIf
        EndSwitch
    WEnd
EndFunc

If you use anything like a msgbox or sleep function etc. that will pause your script, then it won't work. 

Share this post


Link to post
Share on other sites
1 hour ago, BBs19 said:

Well then u have to do the same that you would do in your main while loop:

Func _YourFunctionWithWhileLoop()
    While 1
        _Metro_HoverCheck_Loop($Form1);To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    ConsoleWrite("Toggle unchecked!" & @CRLF)
                Else
                    _Metro_ToggleCheck($Toggle1)
                    ConsoleWrite("Toggle checked!" & @CRLF)
                EndIf
        EndSwitch
    WEnd
EndFunc

If you use anything like a msgbox or sleep function etc. that will pause your script, then it won't work. 

It works!!! However, it gets stuck I have to click it many times sometimes in order to toggle it on/off. I'm not using sleep not anything that would make the script pause... Anyway thank you so much for your help I really appreciated.

 

Share this post


Link to post
Share on other sites
16 hours ago, Mannyfresh15 said:

It works!!! However, it gets stuck I have to click it many times sometimes in order to toggle it on/off. I'm not using sleep not anything that would make the script pause... Anyway thank you so much for your help I really appreciated.

 

Can you show me your code? It is really hard to understand what you are trying to do there, as it is working fine for me.

 

12 hours ago, Mannyfresh15 said:

I also would like to know if there is a way to make the Metro GUIs draggable but not resizable.

There are many different ways to do that, see here: https://www.autoitscript.com/wiki/Moving_and_Resizing_PopUp_GUIs#Moving_a_.24WS_POPUP_GUI

You can also use an internal function of my UDF. Just add this to your script:

$GLOBAL_MAIN_GUI = $Form1 ; ($Form1 should be replaced by the variable name of your created GUI)
GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")


 

Share this post


Link to post
Share on other sites
12 hours ago, BBs19 said:

Can you show me your code? It is really hard to understand what you are trying to do there, as it is working fine for me.

 

There are many different ways to do that, see here: https://www.autoitscript.com/wiki/Moving_and_Resizing_PopUp_GUIs#Moving_a_.24WS_POPUP_GUI

You can also use an internal function of my UDF. Just add this to your script:

$GLOBAL_MAIN_GUI = $Form1 ; ($Form1 should be replaced by the variable name of your created GUI)
GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")


 

Yes here is an example code excuse the DIRTY code since I'm a beginner plus I have borrowed part of it ): Anyway I have notice that "Abort" button has the same problem while in the loop and if I used regular GUI that is not Metro  works just fine. Please let me know if you need a sample code of a regular GUI so you can see it works fine.

#include-once

#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>


#NoTrayIcon

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y


$Form1 = ""


$Checked = False

$timer = ""

$RED = 1

$sec = @SEC

 $Tiempo = ""

$Alarm =  "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck



; Setting Time Variables
$5m =  300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000


$GLOBAL_MAIN_GUI = $Form1 ; ($Form1 should be replaced by the variable name of your created GUI)
GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")


;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app",  484, 209, 255, 124,False)


;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, False) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON , "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON , "Menu")
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle ("Alarm", 10, 147,120,34)
GUICtrlSetTip($Toggle1 , "On/Off")



#Region ### START Koda GUI section ### Form=

$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER)
GUICtrlSetColor($Label1,0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER)
GUICtrlSetColor(-1,0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOr($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
   _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg

ExitLoop
Exit

         case $Button1

            startTimer ()



             Case $Button2

            exit

         Case  $GUI_CLOSE_BUTTON


              ExitLoop
               Exit

    Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)




              Case $Toggle1

         If _Metro_ToggleIsChecked($Toggle1) Then
            _Metro_ToggleUnCheck($Toggle1)
            $Checked = False

        Else
                _Metro_ToggleCheck($Toggle1)

                $Checked = True


            EndIf


                EndSwitch


WEnd




Func startTimer  ()

$Comboread = GUICtrlRead($idComboBox, 0)
if $Comboread = 0 Then

MsgBox($MB_SYSTEMMODAL, "Warning ",  "You Haven't Selected Any Time",10)
Return
Else


if $Comboread =  "5 Minutes" Then $Tiempo = $5m
if $Comboread =  "10 Minutes" Then $Tiempo = $10m
if $Comboread =  "15 Minutes" Then $Tiempo = $15m
if $Comboread =  "30 Minutes" Then $Tiempo = $30m
if $Comboread =  "45 Minutes" Then $Tiempo = $45m
if $Comboread =  "1 Hour" Then $Tiempo = $1h


     ;setting warning labels
      $lbl_text = GUICtrlCreateLabel("Notice", 190, 149, 85, 17,$SS_CENTER)
    ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUICtrlSetColor($lbl_text,0xff0000)  ; Red
GUICtrlSetFont($lbl_text,9,700)
;
 $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER)
;GUICtrlSetResizing(-1, )
GUICtrlSetColor(-1,0xFFFFFF)

   ; call ("startTimer2 ")


EndIf


;Checking if timer is greater than 0
   If TimerDiff($timer) > 0 Then
$timer = TimerInit()


EndIf




   While( TimerDiff($timer)  < $Tiempo) and (GUIGetMsg() <> $Button2)



;Setting Toggle
_Metro_HoverCheck_Loop($Form1);To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)

                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)

                    $Checked = True
                 EndIf

                 Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)

        EndSwitch



$seconds = TimerDiff($timer)/1000
$diff = $seconds - ($Tiempo/1000)
;
$minutes = Int($diff / 60)
$secondsRem = $diff - ($minutes * 60)
;
$hours = Int($minutes / 60)
$minutes =  $minutes - ($hours * 60)

;
$hours =  $hours * -1
$minutes = $minutes * -1
$secondsRem = $secondsRem * -1

;

$time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
;
GUICtrlSetData($Inputtimer, $time)



;Checks if timer is higher than 3mins and If toggle is on plays Sound
if   TimerDiff($timer) > $Tiempo - 180000 And $Checked = True  Then  _SoundPlay ($Alarm,0) ;MsgBox(0,"Aviso","Alarma",5)


;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

if   TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then  _SoundStop ($Alarm)






; Blinking Text





        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text,0xffffff)
            Else
                GUICtrlSetColor($lbl_text,0xff0000)
            EndIf
            $RED = Not $RED
         EndIf




WEnd





$Readtimer = GUICtrlRead ($Inputtimer,0)
if $Readtimer = "00:00:00" then
 MsgBox($MB_ICONWARNING, "Notice", "Time is Up!",15)

_SoundStop ($Alarm)



Else
 _SoundStop ($Alarm)
GUICtrlSetData($Inputtimer, "00:00:00")
GUICtrlDelete ($lbl_text2)
GUICtrlDelete ($lbl_text)

EndIf



   EndFunc

 

And your

 

$GLOBAL_MAIN_GUI = $Form1 ; ($Form1 should be replaced by the variable name of your created GUI)
GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

Works Just Fine I hope I can get a solution for the toggle and the button problem

Edited by Mannyfresh15

Share this post


Link to post
Share on other sites
21 hours ago, Mannyfresh15 said:

Works Just Fine I hope I can get a solution for the toggle and the button problem

This was somehow causing the problem:

While( TimerDiff($timer)  < $Tiempo) and (GUIGetMsg() <> $Button2)

 

Try with this:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

$Checked = False
$timer = ""
$RED = 1
$sec = @SEC
$Tiempo = ""
$Alarm = "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck

; Setting Time Variables
$5m = 300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app", 484, 209, 255, 124, False)

;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, False) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON, "Menu")
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle("Alarm", 10, 147, 120, 34)
GUICtrlSetTip($Toggle1, "On/Off")

#Region ### START Koda GUI section ### Form=
$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOR($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            startTimer()
        Case $Button2
            Exit
        Case $GUI_CLOSE_BUTTON
            ExitLoop
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $Toggle1
            If _Metro_ToggleIsChecked($Toggle1) Then
                _Metro_ToggleUnCheck($Toggle1)
                $Checked = False
            Else
                _Metro_ToggleCheck($Toggle1)
                $Checked = True
            EndIf
    EndSwitch
WEnd

Func startTimer()

    $Comboread = GUICtrlRead($idComboBox, 0)
    If $Comboread = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning ", "You Haven't Selected Any Time", 10)
        Return
    Else
        If $Comboread = "5 Minutes" Then $Tiempo = $5m
        If $Comboread = "10 Minutes" Then $Tiempo = $10m
        If $Comboread = "15 Minutes" Then $Tiempo = $15m
        If $Comboread = "30 Minutes" Then $Tiempo = $30m
        If $Comboread = "45 Minutes" Then $Tiempo = $45m
        If $Comboread = "1 Hour" Then $Tiempo = $1h
        ;setting warning labels
        $lbl_text = GUICtrlCreateLabel("Notice", 190, 149, 85, 17, $SS_CENTER)
        ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
        GUICtrlSetColor($lbl_text, 0xff0000) ; Red
        GUICtrlSetFont($lbl_text, 9, 700)
        ;
        $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER)
        ;GUICtrlSetResizing(-1, )
        GUICtrlSetColor(-1, 0xFFFFFF)
        ; call ("startTimer2 ")
    EndIf

    ;Checking if timer is greater than 0
    If TimerDiff($timer) > 0 Then
        $timer = TimerInit()
    EndIf

    While (TimerDiff($timer) < $Tiempo)
        ;Setting Toggle
        _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI) ;To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)
                    $Checked = True
                EndIf
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $Button2
                ExitLoop
            Case $GUI_CLOSE_BUTTON
                Exit
        EndSwitch

        $seconds = TimerDiff($timer) / 1000
        $diff = $seconds - ($Tiempo / 1000)
        ;
        $minutes = Int($diff / 60)
        $secondsRem = $diff - ($minutes * 60)
        ;
        $hours = Int($minutes / 60)
        $minutes = $minutes - ($hours * 60)

        ;
        $hours = $hours * -1
        $minutes = $minutes * -1
        $secondsRem = $secondsRem * -1

        $time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
        ;
        GUICtrlSetData($Inputtimer, $time)

        ;Checks if timer is higher than 3mins and If toggle is on plays Sound
        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = True Then _SoundPlay($Alarm, 0) ;MsgBox(0,"Aviso","Alarma",5)

        ;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then _SoundStop($Alarm)

        ; Blinking Text

        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text, 0xffffff)
            Else
                GUICtrlSetColor($lbl_text, 0xff0000)
            EndIf
            $RED = Not $RED
        EndIf

    WEnd

    $Readtimer = GUICtrlRead($Inputtimer, 0)
    If $Readtimer = "00:00:00" Then
        MsgBox($MB_ICONWARNING, "Notice", "Time is Up!", 15)
        _SoundStop($Alarm)
    Else
        _SoundStop($Alarm)
        GUICtrlSetData($Inputtimer, "00:00:00")
        GUICtrlDelete($lbl_text2)
        GUICtrlDelete($lbl_text)
    EndIf

EndFunc   ;==>startTimer

 

Edited by BBs19

Share this post


Link to post
Share on other sites

Hi BBs19,

What would be the font setting to use in order to maintain overall consistency with the created controls (checkbox/radio/toggle).
I'd like to for example add a label control but want the text to look the same as your controls.

Share this post


Link to post
Share on other sites
7 hours ago, Dreamfire said:

Hi BBs19,

What would be the font setting to use in order to maintain overall consistency with the created controls (checkbox/radio/toggle).
I'd like to for example add a label control but want the text to look the same as your controls.

 

Hi, the default font is mostly Segoe UI, only Buttons are set to Arial. You can change the default font of course, just look at the the MetroGUI_UDF.au3 file for syntax, the example file i posted is kept pretty easy without much customization:)

Edited by BBs19

Share this post


Link to post
Share on other sites
On 6/12/2016 at 6:18 AM, BBs19 said:

This was somehow causing the problem:

While( TimerDiff($timer)  < $Tiempo) and (GUIGetMsg() <> $Button2)

 

Try with this:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

$Checked = False
$timer = ""
$RED = 1
$sec = @SEC
$Tiempo = ""
$Alarm = "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck

; Setting Time Variables
$5m = 300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app", 484, 209, 255, 124, False)

;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, False) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON, "Menu")
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle("Alarm", 10, 147, 120, 34)
GUICtrlSetTip($Toggle1, "On/Off")

#Region ### START Koda GUI section ### Form=
$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOR($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            startTimer()
        Case $Button2
            Exit
        Case $GUI_CLOSE_BUTTON
            ExitLoop
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $Toggle1
            If _Metro_ToggleIsChecked($Toggle1) Then
                _Metro_ToggleUnCheck($Toggle1)
                $Checked = False
            Else
                _Metro_ToggleCheck($Toggle1)
                $Checked = True
            EndIf
    EndSwitch
WEnd

Func startTimer()

    $Comboread = GUICtrlRead($idComboBox, 0)
    If $Comboread = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning ", "You Haven't Selected Any Time", 10)
        Return
    Else
        If $Comboread = "5 Minutes" Then $Tiempo = $5m
        If $Comboread = "10 Minutes" Then $Tiempo = $10m
        If $Comboread = "15 Minutes" Then $Tiempo = $15m
        If $Comboread = "30 Minutes" Then $Tiempo = $30m
        If $Comboread = "45 Minutes" Then $Tiempo = $45m
        If $Comboread = "1 Hour" Then $Tiempo = $1h
        ;setting warning labels
        $lbl_text = GUICtrlCreateLabel("Notice", 190, 149, 85, 17, $SS_CENTER)
        ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
        GUICtrlSetColor($lbl_text, 0xff0000) ; Red
        GUICtrlSetFont($lbl_text, 9, 700)
        ;
        $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER)
        ;GUICtrlSetResizing(-1, )
        GUICtrlSetColor(-1, 0xFFFFFF)
        ; call ("startTimer2 ")
    EndIf

    ;Checking if timer is greater than 0
    If TimerDiff($timer) > 0 Then
        $timer = TimerInit()
    EndIf

    While (TimerDiff($timer) < $Tiempo)
        ;Setting Toggle
        _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI) ;To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)
                    $Checked = True
                EndIf
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $Button2
                ExitLoop
            Case $GUI_CLOSE_BUTTON
                Exit
        EndSwitch

        $seconds = TimerDiff($timer) / 1000
        $diff = $seconds - ($Tiempo / 1000)
        ;
        $minutes = Int($diff / 60)
        $secondsRem = $diff - ($minutes * 60)
        ;
        $hours = Int($minutes / 60)
        $minutes = $minutes - ($hours * 60)

        ;
        $hours = $hours * -1
        $minutes = $minutes * -1
        $secondsRem = $secondsRem * -1

        $time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
        ;
        GUICtrlSetData($Inputtimer, $time)

        ;Checks if timer is higher than 3mins and If toggle is on plays Sound
        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = True Then _SoundPlay($Alarm, 0) ;MsgBox(0,"Aviso","Alarma",5)

        ;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then _SoundStop($Alarm)

        ; Blinking Text

        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text, 0xffffff)
            Else
                GUICtrlSetColor($lbl_text, 0xff0000)
            EndIf
            $RED = Not $RED
        EndIf

    WEnd

    $Readtimer = GUICtrlRead($Inputtimer, 0)
    If $Readtimer = "00:00:00" Then
        MsgBox($MB_ICONWARNING, "Notice", "Time is Up!", 15)
        _SoundStop($Alarm)
    Else
        _SoundStop($Alarm)
        GUICtrlSetData($Inputtimer, "00:00:00")
        GUICtrlDelete($lbl_text2)
        GUICtrlDelete($lbl_text)
    EndIf

EndFunc   ;==>startTimer

 

You're badass! all those problems have been taken care of thanks to you (:

Now I just got into a little problem setting up a picture as a background will make overlapping controls not work check my example below

 

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

$Checked = False
$timer = ""
$RED = 1
$sec = @SEC
$Tiempo = ""
$Alarm = "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck

; Setting Time Variables
$5m = 300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000

InetGet ("http://imgur.com/download/C5CE14x/" ,@TempDir & "\Samplepic.jpg")

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app", 484, 209, 255, 124, False)

$Pic1 = GUICtrlCreatePic(@TempDir & "\Samplepic.jpg", 10, 0, 460, 119, $SS_NOTIFY,$GUI_WS_EX_PARENTDRAG)
;GuiCtrlSetState(-1,$GUI_DISABLE) If I uncomment this others controls will work but drag will not. ):
;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON, "Menu")
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle("Alarm", 10, 147, 120, 34)
GUICtrlSetTip($Toggle1, "On/Off")

#Region ### START Koda GUI section ### Form=
$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER,$GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER,$GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOR($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            startTimer()
        Case $Button2
            Exit
        Case $GUI_CLOSE_BUTTON
            ExitLoop
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $Toggle1
            If _Metro_ToggleIsChecked($Toggle1) Then
                _Metro_ToggleUnCheck($Toggle1)
                $Checked = False
            Else
                _Metro_ToggleCheck($Toggle1)
                $Checked = True
             EndIf

            Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    Exit

    EndSwitch

    EndSwitch
WEnd

Func startTimer()

    $Comboread = GUICtrlRead($idComboBox, 0)
    If $Comboread = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning ", "You Haven't Selected Any Time", 10)
        Return
    Else
        If $Comboread = "5 Minutes" Then $Tiempo = $5m
        If $Comboread = "10 Minutes" Then $Tiempo = $10m
        If $Comboread = "15 Minutes" Then $Tiempo = $15m
        If $Comboread = "30 Minutes" Then $Tiempo = $30m
        If $Comboread = "45 Minutes" Then $Tiempo = $45m
        If $Comboread = "1 Hour" Then $Tiempo = $1h
        ;setting warning labels
        $lbl_text = GUICtrlCreateLabel("Attention!", 180, 149, 80, 17, $SS_CENTER,$GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
        GUICtrlSetColor($lbl_text, 0xff0000) ; Red
        GUICtrlSetFont($lbl_text, 9, 700)
        ;
        $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER,$GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, )
        GUICtrlSetColor(-1, 0xFFFFFF)
        ; call ("startTimer2 ")
    EndIf

    ;Checking if timer is greater than 0
    If TimerDiff($timer) > 0 Then
        $timer = TimerInit()
    EndIf

    While (TimerDiff($timer) < $Tiempo)
        ;Setting Toggle
        _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI) ;To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)
                    $Checked = True
                EndIf
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $Button2
                ExitLoop
            Case $GUI_CLOSE_BUTTON
                Exit
        EndSwitch

        $seconds = TimerDiff($timer) / 1000
        $diff = $seconds - ($Tiempo / 1000)
        ;
        $minutes = Int($diff / 60)
        $secondsRem = $diff - ($minutes * 60)
        ;
        $hours = Int($minutes / 60)
        $minutes = $minutes - ($hours * 60)

        ;
        $hours = $hours * -1
        $minutes = $minutes * -1
        $secondsRem = $secondsRem * -1

        $time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
        ;
        GUICtrlSetData($Inputtimer, $time)

        ;Checks if timer is higher than 3mins and If toggle is on plays Sound
        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = True Then _SoundPlay($Alarm, 0) ;MsgBox(0,"Aviso","Alarma",5)

        ;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then _SoundStop($Alarm)

        ; Blinking Text

        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text, 0xffffff)
            Else
                GUICtrlSetColor($lbl_text, 0xff0000)
            EndIf
            $RED = Not $RED
        EndIf

    WEnd

    $Readtimer = GUICtrlRead($Inputtimer, 0)
    If $Readtimer = "00:00:00" Then
        MsgBox($MB_ICONWARNING, "Notice", "Time is Up!", 15)
        _SoundStop($Alarm)
    Else
        _SoundStop($Alarm)
        GUICtrlSetData($Inputtimer, "00:00:00")
        GUICtrlDelete($lbl_text2)
        GUICtrlDelete($lbl_text)
    EndIf

EndFunc   ;==>startTimer

 

I having Problems with this:

$Pic1 = GUICtrlCreatePic(@TempDir & "\Samplepic.jpg", 10, 0, 460, 119, $SS_NOTIFY,$GUI_WS_EX_PARENTDRAG)
;GuiCtrlSetState(-1,$GUI_DISABLE) If I uncomment this others controls will work but drag will not. ):

 I don't wanna sound like if I'm getting advantage of you but I really would like to get some help on this because I have no problem with regular GUI but I really want to use Metro GUIs and you know you're the expert. (: 

Edited by Mannyfresh15

Share this post


Link to post
Share on other sites
On 13.6.2016 at 9:41 PM, Mannyfresh15 said:

You're badass! all those problems have been taken care of thanks to you (:

Now I just got into a little problem setting up a picture as a background will make overlapping controls not work check my example below

$Pic1 = GUICtrlCreatePic(@TempDir & "\Samplepic.jpg", 10, 0, 460, 119, $SS_NOTIFY,$GUI_WS_EX_PARENTDRAG)
;GuiCtrlSetState(-1,$GUI_DISABLE) If I uncomment this others controls will work but drag will not. ):

 I don't wanna sound like if I'm getting advantage of you but I really would like to get some help on this because I have no problem with regular GUI but I really want to use Metro GUIs and you know you're the expert. (: 

 

Try this:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

$Checked = False
$timer = ""
$RED = 1
$sec = @SEC
$Tiempo = ""
$Alarm = "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck

; Setting Time Variables
$5m = 300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000

InetGet("http://imgur.com/download/C5CE14x/", @TempDir & "\Samplepic.jpg")

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app", 484, 209, 255, 124, False)

$Pic1 = GUICtrlCreatePic(@TempDir & "\Samplepic.jpg", 10, 0, 460, 119, 0, $GUI_WS_EX_PARENTDRAG)

;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON, "Menu")
;======================================================================================================================================================================


;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle("Alarm", 10, 147, 120, 34)
GUICtrlSetTip($Toggle1, "On/Off")

#Region ### START Koda GUI section ### Form=
$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOR($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;~ GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
            DllCall("user32.dll", "int", "ReleaseCapture")
            DllCall("user32.dll", "long", "SendMessage", "hwnd", $GLOBAL_MAIN_GUI, "int", 0x00A1, "int", 2, "int", 0)
        Case $Button1
            startTimer()
        Case $Button2
            Exit
        Case $GUI_CLOSE_BUTTON
            ExitLoop
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $Toggle1
            If _Metro_ToggleIsChecked($Toggle1) Then
                _Metro_ToggleUnCheck($Toggle1)
                $Checked = False
            Else
                _Metro_ToggleCheck($Toggle1)
                $Checked = True
            EndIf

        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    Exit

            EndSwitch

    EndSwitch
WEnd

Func startTimer()

    $Comboread = GUICtrlRead($idComboBox, 0)
    If $Comboread = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning ", "You Haven't Selected Any Time", 10)
        Return
    Else
        If $Comboread = "5 Minutes" Then $Tiempo = $5m
        If $Comboread = "10 Minutes" Then $Tiempo = $10m
        If $Comboread = "15 Minutes" Then $Tiempo = $15m
        If $Comboread = "30 Minutes" Then $Tiempo = $30m
        If $Comboread = "45 Minutes" Then $Tiempo = $45m
        If $Comboread = "1 Hour" Then $Tiempo = $1h
        ;setting warning labels
        $lbl_text = GUICtrlCreateLabel("Attention!", 180, 149, 80, 17, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
        GUICtrlSetColor($lbl_text, 0xff0000) ; Red
        GUICtrlSetFont($lbl_text, 9, 700)
        ;
        $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, )
        GUICtrlSetColor(-1, 0xFFFFFF)
        ; call ("startTimer2 ")
    EndIf

    ;Checking if timer is greater than 0
    If TimerDiff($timer) > 0 Then
        $timer = TimerInit()
    EndIf

    While (TimerDiff($timer) < $Tiempo)
        ;Setting Toggle
        _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI) ;To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)
                    $Checked = True
                EndIf
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $Button2
                ExitLoop
            Case $GUI_CLOSE_BUTTON
                Exit
        EndSwitch

        $seconds = TimerDiff($timer) / 1000
        $diff = $seconds - ($Tiempo / 1000)
        ;
        $minutes = Int($diff / 60)
        $secondsRem = $diff - ($minutes * 60)
        ;
        $hours = Int($minutes / 60)
        $minutes = $minutes - ($hours * 60)

        ;
        $hours = $hours * -1
        $minutes = $minutes * -1
        $secondsRem = $secondsRem * -1

        $time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
        ;
        GUICtrlSetData($Inputtimer, $time)

        ;Checks if timer is higher than 3mins and If toggle is on plays Sound
        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = True Then _SoundPlay($Alarm, 0) ;MsgBox(0,"Aviso","Alarma",5)

        ;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then _SoundStop($Alarm)

        ; Blinking Text

        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text, 0xffffff)
            Else
                GUICtrlSetColor($lbl_text, 0xff0000)
            EndIf
            $RED = Not $RED
        EndIf

    WEnd

    $Readtimer = GUICtrlRead($Inputtimer, 0)
    If $Readtimer = "00:00:00" Then
        MsgBox($MB_ICONWARNING, "Notice", "Time is Up!", 15)
        _SoundStop($Alarm)
    Else
        _SoundStop($Alarm)
        GUICtrlSetData($Inputtimer, "00:00:00")
        GUICtrlDelete($lbl_text2)
        GUICtrlDelete($lbl_text)
    EndIf

EndFunc   ;==>startTimer

 

12 hours ago, pndhcm280- said:

How can i change the font in the menu ?

qUEJYLQ.png

I forgot to add that option, i will add it with the next update. Just open the MetroGUI_UDF.au3 file and change the "$Font = ":

Func _Internal_CreateMButton($Text, $Left, $Top, $Width, $Height, $BG_Color = $GUIThemeColor, $Font_Color = $FontThemeColor, $Font = "Arial", $Fontsize = 9, $FontStyle = 1, $FrameColor = "0xFFFFFF")

You can change a lot of things in the UDF file, for some things i don't want to add an option as it makes it too complicated to set 10 parameters to create a simple button etc.

Share this post


Link to post
Share on other sites
11 minutes ago, BBs19 said:

 

Try this:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI_UDF.au3>

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

$Checked = False
$timer = ""
$RED = 1
$sec = @SEC
$Tiempo = ""
$Alarm = "C:\Users\Admin\Downloads\BOMB_SIREN-BOMB_SIREN-247265934.wav" ;Replace this with your own .wav file. you already knew this what the heck

; Setting Time Variables
$5m = 300000
$10m = 600000
$15m = 900250
$30m = 1800500
$45m = 2700750
$1h = 3601000

InetGet("http://imgur.com/download/C5CE14x/", @TempDir & "\Samplepic.jpg")

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

;Create resizable Metro GUI
$GLOBAL_MAIN_GUI = _Metro_CreateGUI("My app", 484, 209, 255, 124, False)

$Pic1 = GUICtrlCreatePic(@TempDir & "\Samplepic.jpg", 10, 0, 460, 119, 0, $GUI_WS_EX_PARENTDRAG)

;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Add/create control buttons to the gui
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
;GUICtrlSetTip($GUI_MAXIMIZE_BUTTON , "Minimizar")
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
GUICtrlSetTip($GUI_MENU_BUTTON, "Menu")
;======================================================================================================================================================================


;Create  Buttons
$Button1 = _Metro_CreateButton("start", 206, 177, 75, 25)
$Button2 = _Metro_CreateButton("Abort", 380, 177, 75, 25)

;Create Toggle
$Toggle1 = _Metro_CreateToggle("Alarm", 10, 147, 120, 34)
GUICtrlSetTip($Toggle1, "On/Off")

#Region ### START Koda GUI section ### Form=
$Label1 = GUICtrlCreateLabel("My Timer", 45, 119, 366, 33, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor($Label1, 0xFFFFFF)
GUICtrlSetFont(-1, 16, 0, 0, "Impact")

; Create a combobox control.
$idComboBox = GUICtrlCreateCombo("Select Time", 110, 181, 90, 21)
GUICtrlSetTip(-1, "Select Time")
; Add additional items to the combobox.
GUICtrlSetData($idComboBox, "5 Minutes|10 Minutes|15 Minutes|30 Minutes|45 Minutes|1 Hour", "Select Time")
;
$Label2 = GUICtrlCreateLabel("How much Time?", 4, 183, 100, 25, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inputtimer = GUICtrlCreateInput("00:00:00", 380, 147, 75, 20, BitOR($SS_CENTER, $ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;~ GUIRegisterMsg(0x0201, "INTERNAL_WM_LBUTTONDOWN")

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
            DllCall("user32.dll", "int", "ReleaseCapture")
            DllCall("user32.dll", "long", "SendMessage", "hwnd", $GLOBAL_MAIN_GUI, "int", 0x00A1, "int", 2, "int", 0)
        Case $Button1
            startTimer()
        Case $Button2
            Exit
        Case $GUI_CLOSE_BUTTON
            ExitLoop
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $Toggle1
            If _Metro_ToggleIsChecked($Toggle1) Then
                _Metro_ToggleUnCheck($Toggle1)
                $Checked = False
            Else
                _Metro_ToggleCheck($Toggle1)
                $Checked = True
            EndIf

        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    Exit

            EndSwitch

    EndSwitch
WEnd

Func startTimer()

    $Comboread = GUICtrlRead($idComboBox, 0)
    If $Comboread = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning ", "You Haven't Selected Any Time", 10)
        Return
    Else
        If $Comboread = "5 Minutes" Then $Tiempo = $5m
        If $Comboread = "10 Minutes" Then $Tiempo = $10m
        If $Comboread = "15 Minutes" Then $Tiempo = $15m
        If $Comboread = "30 Minutes" Then $Tiempo = $30m
        If $Comboread = "45 Minutes" Then $Tiempo = $45m
        If $Comboread = "1 Hour" Then $Tiempo = $1h
        ;setting warning labels
        $lbl_text = GUICtrlCreateLabel("Attention!", 180, 149, 80, 17, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
        GUICtrlSetColor($lbl_text, 0xff0000) ; Red
        GUICtrlSetFont($lbl_text, 9, 700)
        ;
        $lbl_text2 = GUICtrlCreateLabel("Timer will stop in:", 250, 150, 125, 20, $SS_CENTER, $GUI_WS_EX_PARENTDRAG)
        ;GUICtrlSetResizing(-1, )
        GUICtrlSetColor(-1, 0xFFFFFF)
        ; call ("startTimer2 ")
    EndIf

    ;Checking if timer is greater than 0
    If TimerDiff($timer) > 0 Then
        $timer = TimerInit()
    EndIf

    While (TimerDiff($timer) < $Tiempo)
        ;Setting Toggle
        _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI) ;To make sure that the hover effects still work
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Toggle1
                If _Metro_ToggleIsChecked($Toggle1) Then
                    _Metro_ToggleUnCheck($Toggle1)
                    $Checked = False
                Else
                    _Metro_ToggleCheck($Toggle1)
                    $Checked = True
                EndIf
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $Button2
                ExitLoop
            Case $GUI_CLOSE_BUTTON
                Exit
        EndSwitch

        $seconds = TimerDiff($timer) / 1000
        $diff = $seconds - ($Tiempo / 1000)
        ;
        $minutes = Int($diff / 60)
        $secondsRem = $diff - ($minutes * 60)
        ;
        $hours = Int($minutes / 60)
        $minutes = $minutes - ($hours * 60)

        ;
        $hours = $hours * -1
        $minutes = $minutes * -1
        $secondsRem = $secondsRem * -1

        $time = StringFormat("%02d", $hours) & ":" & StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem)
        ;
        GUICtrlSetData($Inputtimer, $time)

        ;Checks if timer is higher than 3mins and If toggle is on plays Sound
        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = True Then _SoundPlay($Alarm, 0) ;MsgBox(0,"Aviso","Alarma",5)

        ;Checks if timer is higher than 3mins and If toggle is off checked stops Sound

        If TimerDiff($timer) > $Tiempo - 180000 And $Checked = False Then _SoundStop($Alarm)

        ; Blinking Text

        If @SEC <> $sec Then
            $sec = @SEC
            If $RED Then
                GUICtrlSetColor($lbl_text, 0xffffff)
            Else
                GUICtrlSetColor($lbl_text, 0xff0000)
            EndIf
            $RED = Not $RED
        EndIf

    WEnd

    $Readtimer = GUICtrlRead($Inputtimer, 0)
    If $Readtimer = "00:00:00" Then
        MsgBox($MB_ICONWARNING, "Notice", "Time is Up!", 15)
        _SoundStop($Alarm)
    Else
        _SoundStop($Alarm)
        GUICtrlSetData($Inputtimer, "00:00:00")
        GUICtrlDelete($lbl_text2)
        GUICtrlDelete($lbl_text)
    EndIf

EndFunc   ;==>startTimer

 

 

 

Once again you're badass... It worked like a charm!  Man, you really know what you're doing... Thanks for everything.

Share this post


Link to post
Share on other sites

@BBs19 I found something that can be considered a bug in some cases: if you set the $AllowResize option to false when creating a GUI and then use the _GUI_DragAndResizeUpdate it will override the $AllowResize option to true, in some scenarios this may not be intended.

Other bug is that when you do a WinMove() on the just created GUI changing its size before you call GUISetState(@SW_SHOW) the white border is drawn with the old size of the window (please see attached picture)

Thanks!

Regards

error gui.JPG

Edited by KarlosTHG
Added new bug

Share this post


Link to post
Share on other sites
20 hours ago, KarlosTHG said:

@BBs19 I found something that can be considered a bug in some cases: if you set the $AllowResize option to false when creating a GUI and then use the _GUI_DragAndResizeUpdate it will override the $AllowResize option to true, in some scenarios this may not be intended.

Other bug is that when you do a WinMove() on the just created GUI changing its size before you call GUISetState(@SW_SHOW) the white border is drawn with the old size of the window (please see attached picture)

Thanks!

Regards

Hi, as the name says, the function is intended for resize and drag, therefore i don't know why you would use it if you set $AllowResize to false. I didn't add a seperate function to enable drag only, but i can sure do that if that is what you were trying to do. 

The other one I can't explain, because i don't know how WinMove works in Windows and why it is not resizing the border correctly if the window is not set visible first. But I don't know why it would be a problem... If you set the size/pos while creating, then u won't have the problem. You can also use GUISetState(@SW_HIDE) first, then resize and then set @SW_SHOW. 

 

7 hours ago, t0nZ said:

First of all I love this UDF !

One question: what about Combo controls ?

 

That is too much work man :D I think it would be possible, but it wouldn't be 100% a modern style, as it requires scrollbars and those look bad on older Windows versions. Creating a custom scrollbar is not on my todo list...

Besides that, imo comboboxes look pretty modern on Windows 8 and above. 

 

Share this post


Link to post
Share on other sites

OK got it.

It's true, actually the combobox is not much used in windows 10, there are a few examples with a very small number of items, I have counted a maximum of seven items and without scrollbars, maybe Microsoft has abandoned scrollbars in comboboxes ?

autoplayhero.png

Maybe you can think a combobox limited to ten items and without scrollbars, only an idea I can survive without....:sweating:

Anyway thank you for the good job.

Edited by t0nZ

Share this post


Link to post
Share on other sites

hi @BBs19, I'm still working with your awesome UDF, and found some things:

  1. The window cannot be minimized by clicking it on the taskbar as other windows do.
  2. When you try to assign a color to a button background you can not use the hex value directly, it is necessary to pass it as a string, I just found this by reviewing the code.

Thanks man!

Share this post


Link to post
Share on other sites
5 hours ago, KarlosTHG said:

hi @BBs19, I'm still working with your awesome UDF, and found some things:

  1. The window cannot be minimized by clicking it on the taskbar as other windows do.
  2. When you try to assign a color to a button background you can not use the hex value directly, it is necessary to pass it as a string, I just found this by reviewing the code.

Thanks man!

1. Yes this seems to be the case with all WS_POPUP windows. I haven't noticed this before. I will consider creating the non resizable GUI the same way like the the resizable one (preventing the borders from being drawn). However im not sure how this will impact compatibility, I still haven't tested my UDF on all Windows versions. The WS_POPUP version is more reliable than the borderless GUI version.

2. The GDIPlus functions work with ARGB colors. example: "0xFF000000". So the usual RGB hex colors of the Autoit functions don't work here anyways. I can add a workaround to make it work with hex colors, i just didn't see any need for it.

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

  • Similar Content

    • By Yodavish
      My AutoIt script works fine, for the most part, however, if it goes idle for roughly 30 minutes, it will won't be able to send data to a 3rd party application window titled, "Case #". 
      The problem lies within the function "SendFusion", it's able to see the handle for the "WinActivate" and "WinWaitActivate" (I've also tried putting in 10 seconds in the WinWaitActivate as well, doesn't work). However, if we have been idle, it will always fail to send data afterward. On what I've tried so far:
      "Send" function with the data and a {ENTER} i.e. Send($CaseTxt & "{ENTER}"), this won't even hit the enter key  ControlSetText, tried passing the handle from WinActivate, using the title "Case #" that was copied directly from the Autoit Window Info, hard coding the title, Using CLASS:WindowsForms10... always returns a 0 ControlCommand (same as above) always returns a 0 ControlGetFocus always returns a 0 ControlFocus, always returns a 0 Creating a new and simple Au3 script that just sends data to "Case #", also fails NOTE: If I close the Au3 script and just scan the data directly into the "Case #" or even type it, it works fine with no issues. I'm confused as to why it would not work after a long idle period?
      Below are the essential parts of the script, I can provide the entire thing if needed. Any suggestions would be greatly appreciated!
      #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <Process.au3> #include <Misc.au3> #include <IE.au3> ;--------------------------------------------------------------- ; Only one instance can run ;--------------------------------------------------------------- If _Singleton("gross.exe", 1) = 0 Then MsgBox($MB_SYSTEMMODAL, "Warning", "Gross.exe is already running. Please exit the existing version first (check the icons in the lower right corner of your screen) before running it again.") Exit EndIf ;--------------------------------------------------------------- ; AutoIt Options ;--------------------------------------------------------------- Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt("WinWaitDelay", 0) ; Alters how long a script should briefly pause after a successful window-related operation. Time in milliseconds to pause (default=250). Opt("WinTextMatchMode", 1) ; Alters the method that is used to match window text during search operations. 2 = Quick mode Opt("SendKeyDelay", 0) ; Alters the length of the brief pause in between sent keystrokes. A value of 0 removes the delay completely. Time in milliseconds to pause (default=5). if ($fusionWindowTitle="NONE" or $fusionCaseNumWinTitle="NONE" or $appWindowTitle="NONE" or $winActivateTimeout="NONE" or $winCloseTimeout="NONE" or $winWaitTimeout="NONE" or $pdfViewerWidth="NONE" or $pdfViewerHeight="NONE" or $pdfViewerLeft="NONE" or $pdfViewerWindowName="NONE" or $pdfViewerExeName="NONE" or $pdfUrl="NONE" or $pdfDownloadCommand="NONE") Then Msgbox(0,"ERROR", "gross.ini is missing or does not contain all settings. Please contact Help Desk with this information") Exit -1 EndIf ;--------------------------------------------------------------- ; application settings/constants ;--------------------------------------------------------------- Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") Global Const $[VARIABLE] = IniRead("gross.ini", "default", "[TitleOfVariable]", "NONE") ;--------------------------------------------------------------- ; create the main window ;--------------------------------------------------------------- Local $mainWindow = GUICreate($appWindowTitle, 380, 190) ; create the main GUI window GUISetOnEvent($GUI_EVENT_CLOSE, "handleCloseClick") ; when the click the windows close button call handleCloseClick() WinSetOnTop($appWindowTitle, '', 1) ; Sets main GUI always on top ;--------------------------------------------------------------- ; create the controls on the main window ;--------------------------------------------------------------- Local $okButton = GUICtrlCreateButton("OK", 160, 160, 54,24) ; create OK button GUICtrlSetOnEvent($okButton, "validateInput") ; when they click ok, call handleInputProcessRequest() GUICtrlCreateLabel("Scan Input", 10, 10) ; create a label Global $inputScan = GUICtrlCreateInput("", 10,134,358) ; create the input scan box GUICtrlSetOnEvent($inputScan, "validateInput") ; when they press enter in the scan input box, call handleInputProcessRequest() GUICtrlSetState($inputScan,$GUI_FOCUS) ; automatically sets focus on the input field GUISetState(@SW_SHOW) ; main GUI loop that runs at all times ;--------------------------------------------------------------- While 1 ;---------------------------------------------------------- ; If sumatraPDF active, resets focus back to GUI ;---------------------------------------------------------- If WinActive($pdfViewerWindowName) Then consoleWrite('While Loop sumatraPDF was active' & @CRLF) setMainWindow() ;---------------------------------------------------------- ; After data sent to ProTracker, check for mismatch ; save button to trigger the event handler when clicked ;---------------------------------------------------------- ElseIf WinActive($proTrackerWindowTitle) Then $ie = _IEAttach("ProTracker") $mismatchButton = _IEGetObjByName($ie, $proTrackerMisMatchButtonId) $oEvent = ObjEvent($mismatchButton, "mismatchButton_") If @error Then setMainWindow() ;--------------------------------------------------------------------- ; If Fusion is prompting for the case #, focus back to main GUI input ; If second GUI 'Unknown' detect do nothing ;--------------------------------------------------------------------- ElseIf WinExists($fusionWindowTitle) and WinExists($fusionCaseNumWinTitle) and Not WinActive($mainWindow) and Not WinExists('Unknown Input') Then setMainWindow() EndIF ;--------------------------------------------------------------------- ; Checks if $processFlag = Done, if so, shows PDF viewer and clears ; processFlag for next iteration ;--------------------------------------------------------------------- IF WinExists($pdfViewerWindowName) and $processFlag == 'Done' Then WinSetState ($pdfViewerWindowName, '', @SW_SHOW) $processFlag = '' setMainWindow() EndIF Sleep(100) ; Sleep to reduce CPU usage WEnd Func handleInputProcessRequest($input) $processFlag = True Local $hTimer = TimerInit() consoleWrite('> handleInputProcessRequest: ' & @CRLF) Local $idInput = identifyInput($input) ; Select a proccess to run based on id input Select Case $idInput = "container" ; regex that captures only the case number $caseTxt = StringUpper(StringRegExpReplace($strippedInputData, '\??(\w*\d*-\d*|\d*).*$','$1')) If WinExists($fusionWindowTitle) and WinExists($fusionCaseNumWinTitle) Then sendProTracker(StringUpper($strippedInputData)) sendFusion($caseTxt) ; gets pdf for sumatraPDF in seperate script, since that function is the slowest Run("viewPDF.exe " & $caseTxt) ;getSumatraPDF($caseTxt) $lastCaseNum = $caseTxt Else ; Checks to make sure the previous "Container" case num is the same ; to the current Container case num, before sending to ProTracker If($lastCaseNum <> $caseTxt) Then ; If not the same case number send alert sound SoundPlay("error.wav") Else sendProTracker($strippedInputData) EndIf EndIf Case $idInput = "user" sendProTracker($strippedInputData) Case $idInput = "cassette" sendProTracker(StringUpper($strippedInputData)) Case $idInput = "unknown" selectUnknown() EndSelect Local $fDiff = TimerDiff($hTimer) $processFlag = 'Done' consoleWrite('> handleInputProcessRequest Completed Total time: ' & $fDiff & ' ' &@CRLF&@CRLF&@CRLF) EndFunc Func sendFusion($caseTxt)     Local $hTimer = TimerInit()     consoleWrite('+ sendFusion initiated: ' & $caseTxt & @CRLF)     If $caseTxt = "" Then         MsgBox(0, "Error", "Not a valid case number")     Else         ;$fusionCaseNumWinTitle = "Case #"         $retVal1 = WinActivate($fusionCaseNumWinTitle, "")         consoleWrite("ReturnValue WinActivate " & $retVal1 & @CRLF)         $retVal2 = WinWaitActive($fusionCaseNumWinTitle,"",$winActivateTimeout)         consoleWrite("ReturnValue WinWaitActive: " & $retVal2 & @CRLF)         $retVal3 = ControlSetText($fusionCaseNumWinTitle, "", "", $caseTxt)         ;$retVal3 = ControlCommand($fusionCaseNumWinTitle, "", "", "EditPaste", $caseTxt)         consoleWrite("ReturnValue ControlSetText: " & $retVal3 & @CRLF)         ;Send($caseTxt & "{ENTER}")         WinWaitClose($fusionCaseNumWinTitle, "", $winCloseTimeout)         consoleWrite('+ sendFusion WinWaitClose: ' & @CRLF)     EndIf     Local $fDiff = TimerDiff($hTimer)     ConsoleWrite('+ sendFusion Completed Total time:' & $fDiff & ' ' & @CRLF) EndFunc
      Console logs from the SciTLE
      Window (x86) Info matches the correct handle for the WinActivate and WinWaitActivate

      Window Control (x86) Info, I've tried the CLASS, the ID, also I just noticed that the "handle" in "Control" and "Window" appear to be different as well.

       
      So far the only work-around is to close down the 3rd party application and the AutoIt script, re-open them and it works all completely fine. But this is a pain for the end-user since it's all touch screen and it slows down their workflow, which they can be extremely sensitive about.
       
    • By antonioj84
      I am not able to use the $GUI_READ_EXTENDED with the  Metro UDF,  any work around ?
      Local $aPos[2] = [$Radio1, $Radio2] For $Radio In $aPos If GUICtrlRead($Radio) = $GUI_UNCHECKED Then ContinueLoop IniWrite($sGUIstate_IniFile, "Data", "POS", GUICtrlRead($Radio, $GUI_READ_EXTENDED)) ;; return the text of the menu item ExitLoop Next  
    • By taylansan
      Hello All, 
      If you're interested in the story, read below. Otherwise, just jump to the end of the post. 
      Story: 
      Sometimes my computer goes crazy with Windows update. I tried to turn it off with "services.msc", but couldn't close the it. So, I did some research online that it's triggered by Update Orchestration and Task Scheduler and Windows Update. I also checked that all three processes are triggered by svchost.exe.

      So, I tried to make a script to close this process. I found some useful functions ProcessList and _ProcessGetName using the help documents and coded something as below: 
      #include <MsgBoxConstants.au3> #include <Process.au3> Local $aProcessList = ProcessList() For $i = 1 To $aProcessList[0][0] $iPid = $aProcessList[$i][1] $sName = _ProcessGetName($iPid) MsgBox($MB_SYSTEMMODAL, "The process", "PID: " & $iPid & @CRLF & "NAME: " & $sName) If $sName = "svchost.exe" Then ;ProcessClose($iPid) ;I don't know if this is the process I want to close EndIf Next But the problem is; there are so many svchost.exe exists in the process list. I can't close all of them, some of them are essential to run Windows (well, accidentally I terminated some of them and ended up with a blue screen  
      ---------------
      Well, how can I know the process name like "Service Host: Update Orchestration" (not the scvhost)?
      It's not only with the .exe file, just to the name shown in Windows. 
    • By Yodavish
      I have this AutoIt script that works on Windows 7. However, when I test it on Windows 10, the objEvent will not execute the function it's supposed to call. So I have a webpage the script will check if it is active, then it will search if a popup button exist (elementId), if so, assign it to the event handler so that when that button is clicked, then handler function will move the focus back to the main GUI again.
      If WinActive("Website Title - Internet Explorer") Then    $ie = _IEAttach("Website Title")    $objElement= _IEGetObjById ($ie, "elementId")    local $oEvent = ObjEvent($objElement, "_MY_EVENT_HANDLER_") EndIf Func _MY_EVENT_HANDLER_onclick($oEvtObj)     msgbox(0,"Alert Window", "Button Clicked!") setMainWindow() ; sets focus back to main GUI EndFunc  
      I've verified, on Windows 10, that it does see the object element. But it will not trigger the event. Could it be related to some timing issues due to Windows 10 Internet Explorer over Windows 7 Internet Explorer? 
      Windows 7 IE version 11.0.9600.19507
      Windows 10 IE version 11.418.18362.0
      AutoIt v 3.3
       
×
×
  • Create New...