Jump to content
Sign in to follow this  
jercfd

Use GUIOnEventMode for _GUICtrlMenu

Recommended Posts

jercfd

How can I make the following controls return an event when clicked on? I don't want to use WM_COMMAND for handling the events. If possible, I would like to find out how to use GUIOnEventMode to return an event from the following controls below.

_GUICtrlMenu_CreateMenu()

_GUICtrlMenu_InsertMenuItem()

Share this post


Link to post
Share on other sites
jercfd

I tried that but it isn;t working.

$hGUI = GUICreate("TEST", 640, 480, -1, -1)
$hFileMenu = _GUICtrlMenu_CreateMenu()
$hFileMenu_Open = _GUICtrlMenu_InsertMenuItem($hFileMenu, 0, "&Open" & @TAB & "Ctrl+O")
GUICtrlSetOnEvent($hFileMenu_Open, "Test")
_GUICtrlMenu_SetMenu($hGUI, $hMenu)

func Test()
    consolewrite("returned"&@CRLF)
EndFunc

Share this post


Link to post
Share on other sites
SmOke_N

I tried that but it isn;t working.

$hGUI = GUICreate("TEST", 640, 480, -1, -1)
$hFileMenu = _GUICtrlMenu_CreateMenu()
$hFileMenu_Open = _GUICtrlMenu_InsertMenuItem($hFileMenu, 0, "&Open" & @TAB & "Ctrl+O")
GUICtrlSetOnEvent($hFileMenu_Open, "Test")
_GUICtrlMenu_SetMenu($hGUI, $hMenu)

func Test()
    consolewrite("returned"&@CRLF)
EndFunc
For the UDF functions (Non-Standard functions, usually preceded by an underscore in the function name), you'll need to use GUIRegisterMsg() and the $WM_* constants. Standard AutoIt functions such as (GUI*anything won't interact with UDF controls). I'm quite certain that _GUICtrlMenu_CreateMenu() has an example on how to do this. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
99ojo

For the UDF functions (Non-Standard functions, usually preceded by an underscore in the function name), you'll need to use GUIRegisterMsg() and the $WM_* constants. Standard AutoIt functions such as (GUI*anything won't interact with UDF controls). I'm quite certain that _GUICtrlMenu_CreateMenu() has an example on how to do this.

Hi,

maybe it is only the missing

Opt("GUIOnEventMode", 1)

;-))

Stefan

Share this post


Link to post
Share on other sites
GaryFrost

SmOke_N is correct.

Example from the help file:

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $iMemo
Global Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout

_Main()

Func _Main()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain

    ; Create GUI
    $hGUI = GUICreate("Menu", 400, 300)

    ; Create File menu
    $hFile = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
    _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
    _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
    _GUICtrlMenu_SetMenu ($hGUI, $hMain)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Loop until user exits
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch _WinAPI_LoWord ($iwParam)
        Case $idNew
            MemoWrite("New")
        Case $idOpen
            MemoWrite("Open")
        Case $idSave
            MemoWrite("Save")
        Case $idExit
            Exit
        Case $idCut
            MemoWrite("Cut")
        Case $idCopy
            MemoWrite("Copy")
        Case $idPaste
            MemoWrite("Paste")
        Case $idAbout
            MemoWrite("About")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

; Write message to memo
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
jercfd

So I am forced to use GUIRegisterMsg() and the $WM_* constants when I use the UDFs?

Share this post


Link to post
Share on other sites
monoceres

So I am forced to use GUIRegisterMsg() and the $WM_* constants when I use the UDFs?

Yep. That's life.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
sln7w

What confuses me about the WM_command is how do you setup more than one? I have been trying to do something similar with multiple combo boxes. There is no reference to the name of event it is listening for. Do BOTH combo boxes send messages to this WM_Command? Can someone provide a good explanation as to what WM_command is?

Share this post


Link to post
Share on other sites
Authenticity

It's an event, it's get called with different data posted from different controls on your window. Get yourself "Microsoft® Win32® Programmer's Reference " or bookmark MSDN site because "no one" knows everything and you should not memorize every possible event that exists, or structure or API functions definitions. ;] Over reacting on ma side.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.