Sign in to follow this  
Followers 0
JohnH

Set action for a menu item

3 posts in this topic

Hi everyone,

I'm pretty new to AutoIt but I'm trying to learn new stuff.

So, here it's my problem:

I have created a main menu with Koda (screenshot attached).

$Form1_1 = GUICreate("Form1", 993, 701, 192, 114)
$MenuItem1 = GUICtrlCreateMenu("&About")
$MenuItem3 = GUICtrlCreateMenu("&Info")
$MenuItem2 = GUICtrlCreateMenu("&Help")
$MenuItem4 = GUICtrlCreateMenu("&Exit")

I have 4 functions that should be executed when you press the above buttons (f1 for about.. f4 for exit):

Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "window")
GUICtrlSetOnEvent($MenuItem1, "f1")
GUICtrlSetOnEvent($MenuItem2, "f2")
GUICtrlSetOnEvent($MenuItem3, "f3")
GUICtrlSetOnEvent($MenuItem4, "f4")

But, when I execute the script and click on those buttons nothing happens.

I've omitted something here, but can't figure yet what exactly...

Thanks in advance...

Share this post


Link to post
Share on other sites



#Include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

HotKeySet("{F1}", "function1")
HotKeySet("{F2}", "function2")
HotKeySet("{F3}", "function3")
HotKeySet("{F4}", "function4")

$Form1_1 = GUICreate("Form1", 993, 701, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "function4")

$filemenu = GUICtrlCreateMenu("&Menu")

$MenuItem1 = GUICtrlCreateMenuItem("&About", $filemenu)
GUICtrlSetOnEvent($MenuItem1, "function1")

$MenuItem2 = GUICtrlCreateMenuItem("&Info", $filemenu)
GUICtrlSetOnEvent($MenuItem2, "function2")

$MenuItem3 = GUICtrlCreateMenuItem("&Help", $filemenu)
GUICtrlSetOnEvent($MenuItem3, "function3")

$MenuItem4 = GUICtrlCreateMenuItem("&Exit", $filemenu)
GUICtrlSetOnEvent($MenuItem4, "function4")

GUISetState(@SW_SHOW)

While 1
    Sleep( 100 )

WEnd

Func function1()
    MsgBox(0, "test", "hello 1")
EndFunc

Func function2()
    MsgBox(0, "test", "hello 2")
EndFunc

Func function3()
    MsgBox(0, "test", "hello 3")
EndFunc

Func function4()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Thanks for the quick reply, Tec.

I've resolved the problem.

Cheers,

John

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