Jump to content
Sign in to follow this  
Particle

Using GUICtrlCreateMenu as a MenuItem

Recommended Posts

Particle

Is it possible to have something like this:

$MenuItem = GUICtrlCreateMenu("Send to Tray")

be used as if it were a MenuItem without having any menu items under it? So far trying it using GuiGetMsg and a Switch didn't work...

Share this post


Link to post
Share on other sites
enaiman

Guess you are after something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 151, 97, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUICtrlCreateMenu("")
$HelpM = GUICtrlCreateMenuItem("Click Me", -1)
GUICtrlSetOnEvent(-1, "ClickMe")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc
Func ClickMe()
    MsgBox(0, "?", "Your wish is my command :D")
EndFunc

Pay attention to GUICtrlCreateMenuItem with the menu ID -1


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

Share this post


Link to post
Share on other sites
Particle

That's pretty good. I was trying to look for one where I didn't have to use Opt("GUIOnEventMode", 1). There's an empty menubox to the left of it though, is there a way without having that either?

Share this post


Link to post
Share on other sites
Authenticity

#include <WindowsConstants.au3>

GUIRegisterMsg($WM_INITMENUPOPUP, "_WM_INITMENUPOPUP")

Dim $hGUI = GUICreate("Test", 100, 100)
Dim $hMenu1, $hMenu2

$hMenu1 = GUICtrlGetHandle(GUICtrlCreateMenu("Menu1"))
$hMenu2 = GUICtrlGetHandle(GUICtrlCreateMenu("Menu2"))

GUISetState()

Do
Until GUIGetMsg() = -3

GUIDelete()
Exit

Func _WM_INITMENUPOPUP($hwnd, $iMsg, $iwParam, $ilParam)

    Switch $iwParam
        Case $hMenu1
            MsgBox(0x40, "Menu1", "Menu1")
        Case $hMenu2
            MsgBox(0x40, "Menu2", "Menu2")
    EndSwitch

    Return "GUI_RUNDEFMSG"
EndFunc

Edited by Authenticity

Share this post


Link to post
Share on other sites
GEOSoft

You can also place a MenuItem on the main menu bar by not specifying a Menu

$Mnu_Item = GUICtrlCreateMenuItem("My Item","")

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!"

Share this post


Link to post
Share on other sites
Will66

You can also place a MenuItem on the main menu bar by not specifying a Menu

$Mnu_Item = GUICtrlCreateMenuItem("My Item","")
doesn't work for me?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

Dim $guiTitle="Lets Talk"
Dim $sHTML

$hGUI = GUICreate($guiTitle, 800, 600,-1,-1,$WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"_CLOSEClicked")
GUISetFont (8,-1,"Arial")
Opt("GUIOnEventMode",1)
Opt("GUIResizeMode", 1)

;$btn = _GUICtrlButton_Create($hGUI, "Browse", 10, 10, 50, 20)
;GUICtrlSetOnEvent(-1, "_browsePressed")

;GUICtrlCreateMenu("")
;$HelpM = GUICtrlCreateMenuItem("Click Me", -1)
;GUICtrlSetOnEvent(-1, "_browsePressed")

;GUICtrlCreateMenu("")
;$HelpM2 = GUICtrlCreateMenuItem("Click Me", -1)
;GUICtrlSetOnEvent(-1, "_browsePressed")
$Mnu_Item = GUICtrlCreateMenuItem("My Item","")


GUISetState ()

While 1
    Sleep(100)
WEnd


    Func _CLOSEClicked()
            GUIDelete($hGUI)
            Exit
    EndFunc

Share this post


Link to post
Share on other sites
GEOSoft

I'll have another look at it. I just did it a few days ago so I'll look up that code snippet.


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!"

Share this post


Link to post
Share on other sites
GEOSoft

Now I remember. It requires that at lease one primary menu be there so I set a blank

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>

Dim $guiTitle="Lets Talk"
Dim $sHTML

$hGUI = GUICreate($guiTitle, 800, 600,-1,-1,$WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"_CLOSEClicked")
GUISetFont (8,-1,"Arial")
Opt("GUIOnEventMode",1)
Opt("GUIResizeMode", 1)

;$btn = _GUICtrlButton_Create($hGUI, "Browse", 10, 10, 50, 20)
;GUICtrlSetOnEvent(-1, "_browsePressed")

GUICtrlCreateMenu("")
$HelpM = GUICtrlCreateMenuItem("Click Me", -1)
GUICtrlSetOnEvent(-1, "_browsePressed")

GUISetState ()

While 1
    Sleep(100)
WEnd


    Func _CLOSEClicked()
            GUIDelete($hGUI)
            Exit
    EndFunc

Func _browsePressed()
     Msgbox(0, "Result", "Menu Clicked")
EndFunc

It works for me using a message loop instead of that antique OnEvent code that is still around only because people can't shake the habit.


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!"

Share this post


Link to post
Share on other sites
Will66

thanx, I can live with that.

One more thing would make it complete is getting the checkbox to display...doable?

$browse=GUICtrlCreateMenu ("")
        GUICtrlCreateMenuitem ("Browse",-1)
       ;GUICtrlSetOnEvent(-1, "TablesMenu_clicked")
        $x=GUICtrlCreateMenuitem ("Browse2",-1)
    GUICtrlSetState(-1, $GUI_CHECKED);check submenu item

Share this post


Link to post
Share on other sites
GEOSoft

thanx, I can live with that.

One more thing would make it complete is getting the checkbox to display...doable?

$browse=GUICtrlCreateMenu ("")
        GUICtrlCreateMenuitem ("Browse",-1)
      ;GUICtrlSetOnEvent(-1, "TablesMenu_clicked")
        $x=GUICtrlCreateMenuitem ("Browse2",-1)
    GUICtrlSetState(-1, $GUI_CHECKED);check submenu item
I don't think that's possible when the menuItem is in the top level but perhaps someone else will have that answer.

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!"

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.