IanN1990 Posted January 7, 2017 Share Posted January 7, 2017 (edited) Hey Is anyone able to explain why the follow code is not working? #NoTrayIcon #include <GuiMenu.au3> $Form2 = GUICreate("") GUISetState(@SW_SHOW) $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Update") _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Send Email") _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Auto Sync") _GUICtrlMenu_CheckMenuItem($hMenu, 1) _GUICtrlMenu_CheckMenuItem($hMenu, 2) $MenuResult1 = _GUICtrlMenu_TrackPopupMenu($hMenu, $Form2, -1, -1, 1, 1, 2) ConsoleWrite($MenuResult1) $iNotify is set to 2. So it should return the menu item identifier selected but instead it always returns 0. What is complexing me further is i have code very similar to this running perfectly in two other applications Edited January 8, 2017 by IanN1990 Link to comment Share on other sites More sharing options...
BrewManNH Posted January 7, 2017 Share Posted January 7, 2017 Post runnable code that demonstrates the problem. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
IanN1990 Posted January 7, 2017 Author Share Posted January 7, 2017 I did post a runnable example, admittedly a little basic. It made a gui appear and the menu at your mouse, if you clicked any menu item it returns 0. #NoTrayIcon #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Update") _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Send Email") _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Auto Sync") _GUICtrlMenu_CheckMenuItem($hMenu, 1) _GUICtrlMenu_CheckMenuItem($hMenu, 2) $Form2 = GUICreate("") $Test = GUICtrlCreateButton("Test", 0, 0, 250, 250) GUISetState(@SW_SHOW) While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE Exit Case $idMsg = $Test $MenuResult1 = _GUICtrlMenu_TrackPopupMenu($hMenu, $Form2, -1, -1, 1, 1, 2) ConsoleWrite($MenuResult1 & @CRLF) EndSelect WEnd Here is a more flashy example Link to comment Share on other sites More sharing options...
careca Posted January 8, 2017 Share Posted January 8, 2017 (edited) The help file shows a very different code than yours for _GUICtrlMenu_TrackPopupMenu I suggest you take a look at it. Again. How does the script know which item you are clicking? BTW: What's wrong with GUICtrlCreateContextMenu? Edited January 8, 2017 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
IanN1990 Posted January 8, 2017 Author Share Posted January 8, 2017 I agree its different from the helpfile but in a different script it works perfectly. _GUICtrlMenu_TrackPopupMenu From the helpfile "If $iNotify is set to 2, the return value is the menu item identifier of the item that the user selected. If the user cancels the menu without making a selection or if an error occurs, then the return value is zero." So that can only mean an error is happening but i don't see where? GUICtrlMenu_TrackPopUpMenu generates the popup and pauses the scripts until a return is given. Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2017 Share Posted January 8, 2017 IanN1990, Can you post a working example similar to the above? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
IanN1990 Posted January 8, 2017 Author Share Posted January 8, 2017 Figured it out this morning #NoTrayIcon #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Update", 0) ;Added 0 _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Send Email", 1) ;Added 1 _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Auto Sync", 2) ;Added 2 _GUICtrlMenu_CheckMenuItem($hMenu, 1) _GUICtrlMenu_CheckMenuItem($hMenu, 2) $Form2 = GUICreate("") $Test = GUICtrlCreateButton("Test", 0, 0, 250, 250) GUISetState(@SW_SHOW) While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE Exit Case $idMsg = $Test $MenuResult1 = _GUICtrlMenu_TrackPopupMenu($hMenu, $Form2, -1, -1, 1, 1, 2) ConsoleWrite($MenuResult1 & @CRLF) EndSelect WEnd pixelsearch 1 Link to comment Share on other sites More sharing options...
IanN1990 Posted January 8, 2017 Author Share Posted January 8, 2017 (edited) 13 hours ago, careca said: BTW: What's wrong with GUICtrlCreateContextMenu? I am using that at the moment, the problem is you cant control where the menu appears. _GUICtrlMenu_TrackPopUpMenu does give this ability. Edited January 8, 2017 by IanN1990 Link to comment Share on other sites More sharing options...
careca Posted January 8, 2017 Share Posted January 8, 2017 What do you mean where it appears? Coordinates relative to mouse? Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
IanN1990 Posted January 9, 2017 Author Share Posted January 9, 2017 (edited) Here is a picture As you can see, you can click any part of the button but the menu appears off to the side of it. This way the menu doesn't block buttons below it. I would like to change the font of the context menu (but i fear this is going to be a up-hill battle) Edited January 9, 2017 by IanN1990 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