jercfd Posted April 21, 2009 Share Posted April 21, 2009 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() Link to comment Share on other sites More sharing options...
enaiman Posted April 21, 2009 Share Posted April 21, 2009 GUICtrlSetOnEvent SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
jercfd Posted April 21, 2009 Author Share Posted April 21, 2009 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 21, 2009 Moderators Share Posted April 21, 2009 (edited) 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) EndFuncFor 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 April 21, 2009 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. Link to comment Share on other sites More sharing options...
99ojo Posted April 21, 2009 Share Posted April 21, 2009 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 Link to comment Share on other sites More sharing options...
GaryFrost Posted April 21, 2009 Share Posted April 21, 2009 SmOke_N is correct. Example from the help file: expandcollapse popup#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. Link to comment Share on other sites More sharing options...
jercfd Posted April 22, 2009 Author Share Posted April 22, 2009 So I am forced to use GUIRegisterMsg() and the $WM_* constants when I use the UDFs? Link to comment Share on other sites More sharing options...
monoceres Posted April 22, 2009 Share Posted April 22, 2009 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! Link to comment Share on other sites More sharing options...
sln7w Posted May 4, 2009 Share Posted May 4, 2009 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? Link to comment Share on other sites More sharing options...
Authenticity Posted May 4, 2009 Share Posted May 4, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now