Sign in to follow this  
Followers 0
GeekIT

Problem using menu

11 posts in this topic

Hi everyone  :bye:

I have a quick question about menus in autoit:

Is it normal that I can't use menu's in forms that don't have sub-menu's?

example:

$Form = GUICreate("Test.", 300, 200)
$Menu = GUICtrlCreateMenu("Menu")
While 1
Switch GUIGetMsg()
    Case $Menu
        MsgBox(0,'never works','never works!');    <--- why won't this work?

EndSwitch

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Did you check the example that can be found in the help file for function GUICtrlCreateMenu?

At least line

GUISetState()

is missing.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: Could you please enclose your code in AutoIt code tags (the blue "A" icon in the editor). Enhances readability :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

GeekIT,

You're also missing the WEND stmt to close the while loop.  Try it like this...

#include <GUIConstantsEx.au3>

$Form = GUICreate("Test.", 300, 200)

$Menu = GUICtrlCreateMenu("Menu")
$Menumsg1 = GUICtrlCreateMenuItem('Message # 1', $Menu)
$Menumsg2 = GUICtrlCreateMenuItem('Message # 2', $Menu)
GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Menumsg1
            MsgBox(0, 'never works', 'never works!');    <--- why won't this work?
        Case $Menumsg2
            MsgBox(0, '', 'Of course it works' & @crlf & 'Read the HELP file.');    <--- why won't this work?
    EndSwitch

WEnd

See the Help file for explanation...

kylomas

edit: spelling

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

I assume the missing WEnd statement is just a copy&paste mistake :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

GeekIT,

I can get as far as recognising the click on the menu bar. But as yet I cannot get out of the blocking menu loop - you need to press {ESCAPE} to reenter the script and get the dummy to fire: :(

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#Include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$mFilemenu = GUICtrlCreateMenu("File")
$mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu)
$mSpecialitem = GUICtrlCreateMenu("Special")
$mHelpmenu = GUICtrlCreateMenu("?")
$mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu)

$cMenuDummy = GUICtrlCreateDummy()

GUISetState()

$hMenu = _GUICtrlMenu_GetMenu($hGUI)
$iCount = _GUICtrlMenu_GetItemCount($hMenu) - 1

GUIRegisterMsg(0x0211,"_WM_ENTERMENULOOP") ; WM_ENTERMENULOOP

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $mExititem
            Exit
        Case $cMenuDummy
            MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!")
        Case $mAboutitem
            MsgBox($MB_SYSTEMMODAL, "Solved", "That was hard work!")
    EndSwitch

WEnd

Func _WM_ENTERMENULOOP($hWnd, $iMsg, $wParam, $lParam)

    If $hWnd = $hGUI Then
        For $i = 0 To $iCount

            Local $tRect = _GUICtrlMenu_GetItemRectEx($hGUI, $hMenu, $i)
            Local $aMousePos = MouseGetPos()
            Local $aRes = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $aMousePos[0], "int", $aMousePos[1])
            If Not @error And $aRes[0] Then
                ConsoleWrite("You clicked: " & _GUICtrlMenu_GetItemText($hMenu, $i) & @CRLF)
                GUICtrlSendToDummy($cMenuDummy)
                ExitLoop
            EndIf
        Next
    EndIf

EndFunc
I will keep working on it this afternoon. In the mean time if you have any questions, please ask. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Welcome to AutoIt and the forum!

Did you check the example that can be found in the help file for function GUICtrlCreateMenu?

At least line

GUISetState()

is missing.

yes and i know, is just an example. thanks for the reply (: 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

GeekIT,

You're also missing the WEND stmt to close the while loop.

 

I know, was just explaining my problem. I want to use a menu without sub menu's.

I want it so that you just have to click on the menu button itself and then do something...

Edited by GeekIT
Fixed tags

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

GeekIT,

I can get as far as recognising the click on the menu bar. But as yet I cannot get out of the blocking menu loop - you need to press {ESCAPE} to reenter the script and get the dummy to fire: :(

I will keep working on it this afternoon. In the mean time if you have any questions, please ask. :)

 

Thanks but you don't have to do all that for me (:

I just wanted to know if this was normal. thanks for the help!

Edited by Melba23
Fixed tags

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

GeekIT,

Jos came up with a solution: :)

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#Include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$mFilemenu = GUICtrlCreateMenu("File")
$mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu)
$mSpecialitem = GUICtrlCreateMenuItem("Special", -1)
$mHelpmenu = GUICtrlCreateMenu("?")
$mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $mExititem
            Exit
        Case $mSpecialitem
            MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!")
        Case $mAboutitem
            MsgBox($MB_SYSTEMMODAL, "Solved", "Thank Jos for that!")
    EndSwitch

WEnd
M23

Edit: And so did wraithdu:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#Include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$mFilemenu = GUICtrlCreateMenu("File")
$mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu)
$mSpecialitem = GUICtrlCreateMenu("Special")
$mHelpmenu = GUICtrlCreateMenu("?")
$mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu)

$cMenuDummy = GUICtrlCreateDummy()

GUISetState()

$hMenu = _GUICtrlMenu_GetMenu($hGUI)
$iCount = _GUICtrlMenu_GetItemCount($hMenu) - 1

GUIRegisterMsg(0x0211,"_WM_ENTERMENULOOP") ; WM_ENTERMENULOOP

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $mExititem
            Exit
        Case $cMenuDummy
            MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!")
        Case $mAboutitem
            MsgBox($MB_SYSTEMMODAL, "Solved", "That was hard work!")
    EndSwitch

WEnd

Func _WM_ENTERMENULOOP($hWnd, $iMsg, $wParam, $lParam)

    If $hWnd = $hGUI Then
        For $i = 0 To $iCount

            Local $tRect = _GUICtrlMenu_GetItemRectEx($hGUI, $hMenu, $i)
            Local $aMousePos = MouseGetPos()
            Local $tPOINT = DllStructCreate($tagPOINT)
            $tPOINT.x = $aMousePos[0]
            $tPOINT.y = $aMousePos[1]
            Local $aRes = DllCall("User32.dll", "int", "PtInRect", "struct*", $tRect, "struct", $tPOINT)
            If Not @error And $aRes[0] Then
                ConsoleWrite("You clicked: " & _GUICtrlMenu_GetItemText($hMenu, $i) & @CRLF)
                GUICtrlSendToDummy($cMenuDummy)
                ControlClick($hGUI, "", $hGUI)
                Return 0
            EndIf
        Next
    EndIf

EndFunc
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ah, I see.  :think:  :doh:

Thanks for all the help guys!

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  
Followers 0