Mikeman27294 Posted June 11, 2011 Share Posted June 11, 2011 Hello everyone. I am gurrently working on a small project, and I have not gotten too far in, and I am trying to understand how to get a menubar to work. I have made my menubar, but the problem is that when I click on an item in the menubar assigned to a variable, using the GUIGetMsg function to detect if it is clicked, it does not respond. This is a similar code (I am showing this because it is smaller and easier for me to get my head around) #include <GUIConstantsEX.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> Global $hGUI = GUICreate("Program", @DesktopWidth*0.75, @DesktopHeight*0.75, @DesktopWidth*0.125, @DesktopHeight*0.125, 0x010F0000) GUISetState() ;CREATING THE FILE MENU Local $hFile = _GUICtrlMenu_CreateMenu() Local $hFNew = _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New") Local $hFOpen = _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open") Local $hFSave = _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save") _GUICtrlMenu_InsertMenuItem($hFile, 3, "") Global $hFExit = _GUICtrlMenu_InsertMenuItem($hFile, 4, "&Exit") ;CREATING THE MENUBAR Local $hMenu = _GUICtrlMenu_CreateMenu(1) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "&File", 1, $hFile) _GUICtrlMenu_SetMenu($hGUI, $hMenu) _Main() Func _Main() While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $GUI_EVENT_CLOSE Exit Case $msg[0] = $hFExit Exit EndSelect WEnd EndFunc So when I click on Exit in the file menu, it should exit the program, but it doesnt. I have looked in the help file and the forums but found nothing. Does anybody know where I am going wrong? Thanks. Michael Thompson Link to comment Share on other sites More sharing options...
ahmet Posted June 11, 2011 Share Posted June 11, 2011 GUIGetMsg() works only with controls created using GUICtrlCreate...(). Link to comment Share on other sites More sharing options...
UEZ Posted June 11, 2011 Share Posted June 11, 2011 Try this: expandcollapse popup#include <GUIConstantsEX.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> Global $hGUI = GUICreate("Program", @DesktopWidth*0.75, @DesktopHeight*0.75, @DesktopWidth*0.125, @DesktopHeight*0.125, 0x010F0000) Global Enum $idExit = 1000, $idNew, $idOpen, $idSave ;CREATING THE FILE MENU Local $hFile = _GUICtrlMenu_CreateMenu() Local $hFNew = _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew) Local $hFOpen = _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $idOpen) Local $hFSave = _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $idSave) _GUICtrlMenu_InsertMenuItem($hFile, 3, "") Global $hFExit = _GUICtrlMenu_InsertMenuItem($hFile, 4, "&Exit", $idExit) ;CREATING THE MENUBAR Local $hMenu = _GUICtrlMenu_CreateMenu(1) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "&File", 1, $hFile) _GUICtrlMenu_SetMenu($hGUI, $hMenu) GUISetState() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") _Main() Func _Main() While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $GUI_EVENT_CLOSE Exit Case $msg[0] = $hFExit Exit EndSelect WEnd EndFunc Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam, $lParam Switch $wParam Case $idExit Exit MsgBox(0, "Information", "Closing") Case $idNew MsgBox(0, "Information", "Your new function starts here") Case $idOpen MsgBox(0, "Information", "Your open function starts here") Case $idSave MsgBox(0, "Information", "Your save function starts here") EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
GEOSoft Posted June 11, 2011 Share Posted June 11, 2011 Or this one. #include <GUIConstantsEX.au3> ;#include <GuiMenu.au3> ;; This UDF has limited usage so don't use it when possible #include <WindowsConstants.au3> Global $hGUI = GUICreate("Program", @DesktopWidth*0.75, @DesktopHeight*0.75, @DesktopWidth*0.125, @DesktopHeight*0.125, 0x010F0000) ;CREATING THE FILE MENU Local $hFile = GUICtrlCreateMenu("&File") Local $hFNew = GUICtrlCreateMenuItem("&New", $hFile) Local $hFOpen = GUICtrlCreateMenuItem("&Open", $hFile) Local $hFSave = GUICtrlCreateMenuItem("&Save", $hFile) GUICtrlCreateMenuItem("", $hFile) Global $hFExit = GUICtrlCreateMenuItem("&Exit", $hFile) ;CREATING THE MENUBAR ;Local $hMenu = GUICtrlCreateMenu(1) ; GUICtrlCreateMenuItem($hMenu, 1, "&File", 1, $hFile) ; _GUICtrlMenu_SetMenu($hGUI, $hMenu) GUISetState() _Main() Func _Main() While 1 $msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE, $hFExit Exit Case $hFNew To $hFSave MsgBox(0, "Item Clicked", GUICtrlRead($msg, 1)) EndSwitch WEnd EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Mikeman27294 Posted June 12, 2011 Author Share Posted June 12, 2011 I said thanks earlier but it obviously didnt send. Thanks to all of you, all of your suggestions worked, but in the end, my brother showed me GUICtrlCreateMenu and so that is what I am using, and so I guess that GEOSoft got the best answer as far as coder friendly, but also, I cannot say that without saying that UEZ's code worked a charm, and ahmet's input helped me understand why what I was doing didnt work. Hahaha You are a Bright bunch (), aren't you? Thank you all, now I just need to figure out how to mark this as solved. Link to comment Share on other sites More sharing options...
guinness Posted June 12, 2011 Share Posted June 12, 2011 Or this is an Example if you just want to monitor when GUICtrlCreateMenu is Clicked >> UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Mikeman27294 Posted June 15, 2011 Author Share Posted June 15, 2011 Yeah I got my menu working right now. Thanks though. 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