Sign in to follow this  
Followers 0
Flood

Menu in Onevent mode

4 posts in this topic

Hello,

I am trying to put all my script in a gui. But i cannot figure out to code the menu in Onevent mode. All the exemple i find in the help and the forum are in Message loop mode.

Here is a simplified version of my gui.

CODE
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=b:\mystuff\script\messcripts\outilteck\outilteklimited.kxf

$OutilTekForm = GUICreate("OutilTekForm", 174, 245, -1, -1)

GUISetOnEvent($GUI_EVENT_CLOSE, "OutilTekFormClose")

;GUISetOnEvent($GUI_EVENT_MINIMIZE, "OutilTekFormMinimize")

;GUISetOnEvent($GUI_EVENT_MAXIMIZE, "OutilTekFormMaximize")

;GUISetOnEvent($GUI_EVENT_RESTORE, "OutilTekFormRestore")

$GPOGroup = GUICtrlCreateGroup(" GPO ", 24, 24, 129, 65)

$GPOSwitch = GUICtrlCreateButton("GPO Switch", 40, 48, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "GPOSwitchClick")

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

$Deep_FreezeGroup = GUICtrlCreateGroup(" Deep Freeze ", 24, 96, 129, 105)

$ActiverButton = GUICtrlCreateButton("Activer", 40, 120, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "ActiverButtonclick")

$DesactiverButton = GUICtrlCreateButton("Désactiver", 40, 160, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "DesactiverButtonclick")

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

$MenuItem1 = GUICtrlCreateMenu("&File")

$MenuItem3 = GUICtrlCreateMenuItem("Quit", $MenuItem1)

$MenuItem2 = GUICtrlCreateMenu("?")

$MenuItem4 = GUICtrlCreateMenuItem("About", $MenuItem2)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

Sleep(100)

WEnd

Func ActiverButtonclick()

MsgBox(4096, "Test", "You Clicked the Activer button", 10)

EndFunc

Func DesactiverButtonclick()

MsgBox(4096, "Test", "You Clicked the Desactiver button", 10)

EndFunc

Func GPOSwitchClick()

MsgBox(4096, "Test", "You Clicked the GPOSwitch button", 10)

EndFunc

Func OutilTekFormClose()

Exit

EndFunc

Thank's

Flood

Share this post


Link to post
Share on other sites



Hello,

I am trying to put all my script in a gui. But i cannot figure out to code the menu in Onevent mode. All the exemple i find in the help and the forum are in Message loop mode.

Here is a simplified version of my gui.

CODE
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=b:\mystuff\script\messcripts\outilteck\outilteklimited.kxf

$OutilTekForm = GUICreate("OutilTekForm", 174, 245, -1, -1)

GUISetOnEvent($GUI_EVENT_CLOSE, "OutilTekFormClose")

;GUISetOnEvent($GUI_EVENT_MINIMIZE, "OutilTekFormMinimize")

;GUISetOnEvent($GUI_EVENT_MAXIMIZE, "OutilTekFormMaximize")

;GUISetOnEvent($GUI_EVENT_RESTORE, "OutilTekFormRestore")

$GPOGroup = GUICtrlCreateGroup(" GPO ", 24, 24, 129, 65)

$GPOSwitch = GUICtrlCreateButton("GPO Switch", 40, 48, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "GPOSwitchClick")

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

$Deep_FreezeGroup = GUICtrlCreateGroup(" Deep Freeze ", 24, 96, 129, 105)

$ActiverButton = GUICtrlCreateButton("Activer", 40, 120, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "ActiverButtonclick")

$DesactiverButton = GUICtrlCreateButton("Désactiver", 40, 160, 99, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_VCENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))

GUICtrlSetOnEvent(-1, "DesactiverButtonclick")

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

$MenuItem1 = GUICtrlCreateMenu("&File")

$MenuItem3 = GUICtrlCreateMenuItem("Quit", $MenuItem1)

$MenuItem2 = GUICtrlCreateMenu("?")

$MenuItem4 = GUICtrlCreateMenuItem("About", $MenuItem2)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

Sleep(100)

WEnd

Func ActiverButtonclick()

MsgBox(4096, "Test", "You Clicked the Activer button", 10)

EndFunc

Func DesactiverButtonclick()

MsgBox(4096, "Test", "You Clicked the Desactiver button", 10)

EndFunc

Func GPOSwitchClick()

MsgBox(4096, "Test", "You Clicked the GPOSwitch button", 10)

EndFunc

Func OutilTekFormClose()

Exit

EndFunc

Thank's

Flood

Welcome to the AutoIt forums :D

It's not so difficult -

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=b:\mystuff\script\messcripts\outilteck\outilteklimited.kxf
$OutilTekForm = GUICreate("OutilTekForm", 174, 245, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "OutilTekFormClose")
;GUISetOnEvent($GUI_EVENT_MINIMIZE, "OutilTekFormMinimize")
;GUISetOnEvent($GUI_EVENT_MAXIMIZE, "OutilTekFormMaximize")
;GUISetOnEvent($GUI_EVENT_RESTORE, "OutilTekFormRestore")
$GPOGroup = GUICtrlCreateGroup(" GPO ", 24, 24, 129, 65)
$GPOSwitch = GUICtrlCreateButton("GPO Switch", 40, 48, 99, 25, BitOR($BS_DEFPUSHBUTTON, $BS_CENTER, $BS_VCENTER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUICtrlSetOnEvent(-1, "GPOSwitchClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Deep_FreezeGroup = GUICtrlCreateGroup(" Deep Freeze ", 24, 96, 129, 105)
$ActiverButton = GUICtrlCreateButton("Activer", 40, 120, 99, 25, BitOR($BS_DEFPUSHBUTTON, $BS_CENTER, $BS_VCENTER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUICtrlSetOnEvent(-1, "ActiverButtonclick")
$DesactiverButton = GUICtrlCreateButton("Désactiver", 40, 160, 99, 25, BitOR($BS_DEFPUSHBUTTON, $BS_CENTER, $BS_VCENTER), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
GUICtrlSetOnEvent(-1, "DesactiverButtonclick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem3 = GUICtrlCreateMenuItem("Quit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("?")
$MenuItem4 = GUICtrlCreateMenuItem("About", $MenuItem2)
GUISetState(@SW_SHOW)

;menu events. 
;could be a separate func for each control but I decided to use one function here
GUICtrlSetOnEvent($MenuItem3,"howaboutit")
GUICtrlSetOnEvent($MenuItem4,"howaboutit")
#EndRegion ### START Koda GUI section ### Form=b:\mystuff\script\messcripts\outilteck\outilteklimited.kxf

While 1
    Sleep(100)
WEnd

Func ActiverButtonclick()
    MsgBox(4096, "Test", "You Clicked the Activer button", 10)

EndFunc  ;==>ActiverButtonclick


Func DesactiverButtonclick()
    MsgBox(4096, "Test", "You Clicked the Desactiver button", 10)
EndFunc  ;==>DesactiverButtonclick


Func GPOSwitchClick()
    MsgBox(4096, "Test", "You Clicked the GPOSwitch button", 10)
EndFunc  ;==>GPOSwitchClick


Func OutilTekFormClose()
    Exit
EndFunc  ;==>OutilTekFormClose

Func howaboutit()
    
    Switch @GUI_CTRLID
        Case $MenuItem3
            Exit
        Case $MenuItem4
            MsgBox(0,"not much help", "you're on your own.")
    EndSwitch
    
            
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thank you very much Martin for your help. It was easy enuff :D

If i may ask another question:

I was checking the documentation about the switch statement and i dont understand what the @GUI_CTRLID is. It says it is a expression ?

Flood

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thank you very much Martin for your help. It was easy enuff :D

If i may ask another question:

I was checking the documentation about the switch statement and i dont understand what the @GUI_CTRLID is. It says it is a expression ?

Flood

It's just the ID last returned by GuiGetMsg (my understanding). In some cases it's obviously not needed-

switch GuiGetMsg()
  case $but1
     msgbox(0,"you clicked the control with ID ref " & $But1,"It's obvious")

In other cases it might not be so obvious

Switch GuiGetMsg()
  Case $but1 to $but3
   MsgBox(0,You can't catch me like that","You clicked control ref " & @GUI_CTRLID)

Similarly in the function howaboutit, the only way to know what id caused the function to be called is @GUI_CTRLID because all the menuitems call that function.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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