Sign in to follow this  
Followers 0
AllSystemGo

Problem in GUI

7 posts in this topic

Hi, I'm fairly new with the GUI in Autoit and I guess it's a simple question but I'm stuck and can't figure out why.

#include <Array.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <String.au3>
#include <Math.au3>
#include <Color.au3>
#include <Misc.au3>

#NoTrayIcon

; #######################################################
; AutoIt options
; #######################################################
Opt("GUIOnEventMode", 1) ; Enable OnEvent functions notifications
Opt("TrayAutoPause", 0) ; No pauses when click on tray icon
Opt("TrayMenuMode", 1) ; No default menu
Opt("TrayOnEventMode", 1) ; Enable OnEvent functions notifications for the tray
Opt("WinTitleMatchMode", 1) ; Match the title from the start (default)
Opt("GUIResizeMode", 0) ; So the control will not move during resizing

; ########################################################
; Constants
; ########################################################
Const $PROGRAM_NAME = "Automatisation remplacement PC"
Const $PROGRAM_VERSION = "1.0"
Const $MAC = _GetMACFromIP (@IPAddress1)

; ########################################################
; Global vars & Config vars
; ########################################################
Global $gui_main_width = 300
Global $gui_main_height =  300
Global $gui_bk_color = 0x66aaff

; ########################################################
; Check Instance
; ########################################################
_Singleton("Automatisation PC") ; Check if no other occurrence is running

; ########################################################
; GUI Creation
; ########################################################
$gui_main_title = $PROGRAM_NAME & " V" & $PROGRAM_VERSION
$gui_main = GUICreate($gui_main_title, $gui_main_width, $gui_main_height, -1, -1, $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)

GUISetBkColor($gui_bk_color, $gui_main)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

; ########################################################
; Main Window
; ########################################################

; ########################################################
; Radio Button on the left of the Main Window
; ########################################################
GUIStartGroup()
$repart_1 = GUICtrlCreateRadio("Repartion1", 10, 10, 80, -1)
$repart_2 = GUICtrlCreateRadio("Repartion2", 10, 30, 80, -1)
$repart_3 = GUICtrlCreateRadio("Repartion3", 10, 50, 80, -1)
$repart_4 = GUICtrlCreateRadio("Repartion4", 10, 70, 80, -1)
$repart_5 = GUICtrlCreateRadio("Repartion5", 10, 90, 80, -1)
GUICtrlSetState($repart_1, $GUI_CHECKED)

; ########################################################
; The log Window on the right of the Main Window
; ########################################################
GUICtrlCreateGroup("LOG", 100, 7, 180, 250)

GUICtrlCreateLabel("Choix de repartition", 110, 30)
$checkbox1 = GUICtrlCreateCheckbox("", 255, 25, -1, -1)

GUICtrlCreateLabel("Modification info911.ini", 110, 60)
$checkbox2 = GUICtrlCreateCheckbox("", 255, 55, -1, -1)

GUICtrlCreateLabel("Modification Registry Key", 110, 90)
$checkbox3 = GUICtrlCreateCheckbox("", 255, 85, -1, -1)

GUICtrlCreateLabel("Renommer Nom Machine", 110, 120)
$checkbox4 = GUICtrlCreateCheckbox("", 255, 115, -1, -1)

GUICtrlCreateLabel("Modification listepc.txt", 110, 150)
$checkbox5 = GUICtrlCreateCheckbox("", 255, 145, -1, -1)

GUICtrlCreateGroup("", -99, -99, 1, 1)

; ########################################################
; Setting the state to disable as it used only for show
; ########################################################
GUICtrlSetState($checkbox1, $GUI_DISABLE)
GUICtrlSetState($checkbox2, $GUI_DISABLE)
GUICtrlSetState($checkbox3, $GUI_DISABLE)
GUICtrlSetState($checkbox4, $GUI_DISABLE)
GUICtrlSetState($checkbox5, $GUI_DISABLE)

; ########################################################
; It all start here
; ########################################################
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $repart_1 And BitAND(GUICtrlRead($repart_1), $GUI_CHECKED) = $GUI_CHECKED
            GUICtrlSetState($checkbox1, $GUI_CHECKED)
        Case $msg = $repart_2
            MsgBox(0, "", "Test")
    EndSelect
Wend

Ok I know it's the most optimized code but I was trying out some stuff. So here's my problem right now if a user select any of the Radio button nothing happen. But if they click the X Icon to close the program everything is fine. Can you explain why is that and if I forgot something in my code.

Cheers and thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your using OnEventMode 1 then your using $msg = GUIGetMsg().

GUIGetMsg() will allways return 0 when usin OnEventMode 1

#include <Array.au3>
#include <GUIConstants.au3>
;~#include <GUIStatusBar.au3>
#include <String.au3>
#include <Math.au3>
#include <Color.au3>
#include <Misc.au3>

#NoTrayIcon

; #######################################################
; AutoIt options
; #######################################################
;~ Opt("GUIOnEventMode", 1) ; Enable OnEvent functions notifications ; <-------- Problem 
Opt("TrayAutoPause", 0) ; No pauses when click on tray icon
Opt("TrayMenuMode", 1) ; No default menu
Opt("TrayOnEventMode", 1) ; Enable OnEvent functions notifications for the tray
Opt("WinTitleMatchMode", 1) ; Match the title from the start (default)
Opt("GUIResizeMode", 0) ; So the control will not move during resizing

; ########################################################
; Constants
; ########################################################
Const $PROGRAM_NAME = "Automatisation remplacement PC"
Const $PROGRAM_VERSION = "1.0"
;~ Const $MAC = _GetMACFromIP (@IPAddress1)

; ########################################################
; Global vars & Config vars
; ########################################################
Global $gui_main_width = 300
Global $gui_main_height =  300
Global $gui_bk_color = 0x66aaff

; ########################################################
; Check Instance
; ########################################################
_Singleton("Automatisation PC") ; Check if no other occurrence is running

; ########################################################
; GUI Creation
; ########################################################
$gui_main_title = $PROGRAM_NAME & " V" & $PROGRAM_VERSION
$gui_main = GUICreate($gui_main_title, $gui_main_width, $gui_main_height, -1, -1, $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)

GUISetBkColor($gui_bk_color, $gui_main)
;~ GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

; ########################################################
; Main Window
; ########################################################

; ########################################################
; Radio Button on the left of the Main Window
; ########################################################
GUIStartGroup()
$repart_1 = GUICtrlCreateRadio("Repartion1", 10, 10, 80, -1)
$repart_2 = GUICtrlCreateRadio("Repartion2", 10, 30, 80, -1)
$repart_3 = GUICtrlCreateRadio("Repartion3", 10, 50, 80, -1)
$repart_4 = GUICtrlCreateRadio("Repartion4", 10, 70, 80, -1)
$repart_5 = GUICtrlCreateRadio("Repartion5", 10, 90, 80, -1)
GUICtrlSetState($repart_1, $GUI_CHECKED)

; ########################################################
; The log Window on the right of the Main Window
; ########################################################
GUICtrlCreateGroup("LOG", 100, 7, 180, 250)

GUICtrlCreateLabel("Choix de repartition", 110, 30)
$checkbox1 = GUICtrlCreateCheckbox("", 255, 25, -1, -1)

GUICtrlCreateLabel("Modification info911.ini", 110, 60)
$checkbox2 = GUICtrlCreateCheckbox("", 255, 55, -1, -1)

GUICtrlCreateLabel("Modification Registry Key", 110, 90)
$checkbox3 = GUICtrlCreateCheckbox("", 255, 85, -1, -1)

GUICtrlCreateLabel("Renommer Nom Machine", 110, 120)
$checkbox4 = GUICtrlCreateCheckbox("", 255, 115, -1, -1)

GUICtrlCreateLabel("Modification listepc.txt", 110, 150)
$checkbox5 = GUICtrlCreateCheckbox("", 255, 145, -1, -1)

GUICtrlCreateGroup("", -99, -99, 1, 1)

; ########################################################
; Setting the state to disable as it used only for show
; ########################################################
GUICtrlSetState($checkbox1, $GUI_DISABLE)
GUICtrlSetState($checkbox2, $GUI_DISABLE)
GUICtrlSetState($checkbox3, $GUI_DISABLE)
GUICtrlSetState($checkbox4, $GUI_DISABLE)
GUICtrlSetState($checkbox5, $GUI_DISABLE)

; ########################################################
; It all start here
; ########################################################
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()  ;<--- This will return 0 when GUIOnEventMode is set to 1
   
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $repart_1 
            MsgBox(0, "", "Test 1",1)
        Case $msg = $repart_2
            MsgBox(0, "", "Test 2",1)
        Case $msg = $repart_3 
            MsgBox(0, "", "Test 3",1)
        Case $msg = $repart_4
            MsgBox(0, "", "Test 4",1)
        Case $msg = $repart_5
            MsgBox(0, "", "Test 5",1)               
    EndSelect
Wend

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

It works beautifully.. Thank you my friend

Cheers!

Share this post


Link to post
Share on other sites

BTW What is it used for that GUIOnEventMode??? I don't think I get the explaination in the help file.

Share this post


Link to post
Share on other sites

Your welcome, the GuiOnEvent is just another way of working with the gui, you either use one or the other , but not both at the same time in 1 script. :) The Help file does explain it , but it depends on a users needs to which mode suites them.

Same thing this time in GUIOnEventMode 1:

#include <Array.au3>
#include <GUIConstants.au3>
;~ #include <GUIStatusBar.au3>
#include <String.au3>
#include <Math.au3>
#include <Color.au3>
#include <Misc.au3>

#NoTrayIcon

; #######################################################
; AutoIt options
; #######################################################
Opt("GUIOnEventMode", 1) ; Enable OnEvent functions notifications
Opt("TrayAutoPause", 0) ; No pauses when click on tray icon
Opt("TrayMenuMode", 1) ; No default menu
Opt("TrayOnEventMode", 1) ; Enable OnEvent functions notifications for the tray
Opt("WinTitleMatchMode", 1) ; Match the title from the start (default)
Opt("GUIResizeMode", 0) ; So the control will not move during resizing

; ########################################################
; Constants
; ########################################################
Const $PROGRAM_NAME = "Automatisation remplacement PC"
Const $PROGRAM_VERSION = "1.0"
;~ Const $MAC = _GetMACFromIP (@IPAddress1)

; ########################################################
; Global vars & Config vars
; ########################################################
Global $gui_main_width = 300
Global $gui_main_height =  300
Global $gui_bk_color = 0x66aaff

; ########################################################
; Check Instance
; ########################################################
_Singleton("Automatisation PC") ; Check if no other occurrence is running

; ########################################################
; GUI Creation
; ########################################################
$gui_main_title = $PROGRAM_NAME & " V" & $PROGRAM_VERSION
$gui_main = GUICreate($gui_main_title, $gui_main_width, $gui_main_height, -1, -1, $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX)

GUISetBkColor($gui_bk_color, $gui_main)
GUISetOnEvent($GUI_EVENT_CLOSE, "EventHappened")

; ########################################################
; Main Window
; ########################################################

; ########################################################
; Radio Button on the left of the Main Window
; ########################################################
GUIStartGroup()
$repart_1 = GUICtrlCreateRadio("Repartion1", 10, 10, 80, -1)
GUICtrlSetOnEvent(-1, 'EventHappened')
$repart_2 = GUICtrlCreateRadio("Repartion2", 10, 30, 80, -1)
GUICtrlSetOnEvent(-1, 'EventHappened')
$repart_3 = GUICtrlCreateRadio("Repartion3", 10, 50, 80, -1)
GUICtrlSetOnEvent(-1, 'EventHappened')
$repart_4 = GUICtrlCreateRadio("Repartion4", 10, 70, 80, -1)
GUICtrlSetOnEvent(-1, 'EventHappened')
$repart_5 = GUICtrlCreateRadio("Repartion5", 10, 90, 80, -1)
GUICtrlSetOnEvent(-1, 'EventHappened')
GUICtrlSetState($repart_1, $GUI_CHECKED)

; ########################################################
; The log Window on the right of the Main Window
; ########################################################
GUICtrlCreateGroup("LOG", 100, 7, 180, 250)

GUICtrlCreateLabel("Choix de repartition", 110, 30)
$checkbox1 = GUICtrlCreateCheckbox("", 255, 25, -1, -1)

GUICtrlCreateLabel("Modification info911.ini", 110, 60)
$checkbox2 = GUICtrlCreateCheckbox("", 255, 55, -1, -1)

GUICtrlCreateLabel("Modification Registry Key", 110, 90)
$checkbox3 = GUICtrlCreateCheckbox("", 255, 85, -1, -1)

GUICtrlCreateLabel("Renommer Nom Machine", 110, 120)
$checkbox4 = GUICtrlCreateCheckbox("", 255, 115, -1, -1)

GUICtrlCreateLabel("Modification listepc.txt", 110, 150)
$checkbox5 = GUICtrlCreateCheckbox("", 255, 145, -1, -1)

GUICtrlCreateGroup("", -99, -99, 1, 1)

; ########################################################
; Setting the state to disable as it used only for show
; ########################################################
GUICtrlSetState($checkbox1, $GUI_DISABLE)
GUICtrlSetState($checkbox2, $GUI_DISABLE)
GUICtrlSetState($checkbox3, $GUI_DISABLE)
GUICtrlSetState($checkbox4, $GUI_DISABLE)
GUICtrlSetState($checkbox5, $GUI_DISABLE)

; ########################################################
; It all start here
; ########################################################
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
Wend

Func EventHappened() 
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $repart_1 
            MsgBox(0, "", "Test 1",1)
        Case @GUI_CtrlId = $repart_2
            MsgBox(0, "", "Test 2",1)
        Case @GUI_CtrlId = $repart_3 
            MsgBox(0, "", "Test 3",1)
        Case @GUI_CtrlId = $repart_4
            MsgBox(0, "", "Test 4",1)
        Case @GUI_CtrlId = $repart_5
            MsgBox(0, "", "Test 5",1)               
    EndSelect
EndFunc

Good Luck

&

Cheers

Share this post


Link to post
Share on other sites

My experience is: If your script is big, the performance will be better using GUIOnEventMode 1

Share this post


Link to post
Share on other sites

Thank you guys. The help is greatly appreciated.

Cheers

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