IanN1990

_GUICtrlMenu_CreatePopup Always returning 0 [Solved]

10 posts in this topic

#1 ·  Posted (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 :huh:

Edited by IanN1990

Share this post


Link to post
Share on other sites



#2 ·  Posted

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 Gude
How 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

Share this post


Link to post
Share on other sites

#3 ·  Posted

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 :) 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The help file shows a very different code than yours for

_GUICtrlMenu_TrackPopupMenu

I suggest you take a look at it. Again. :P

How does the script know which item you are clicking?

 

BTW: What's wrong with GUICtrlCreateContextMenu?

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites

#5 ·  Posted

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by IanN1990

Share this post


Link to post
Share on other sites

#9 ·  Posted

What do you mean where it appears? Coordinates relative to mouse?


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Here is a picture :)

Example.png

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 by IanN1990

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