Jump to content

Click on a menu


Recommended Posts

I'm just curious why this doesn't work. Why doesn't the program exit when exit menu is clicked. What am I doing wrong?

#include
#include

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 221, 173, 192, 114)
$exit = GUICtrlCreateMenu("Exit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
         Case $GUI_EVENT_CLOSE
             Exit
         Case $exit
             ;This doesn't get called
             Exit
     EndSwitch
WEnd
Edited by aleksa
Link to comment
Share on other sites

You are not using a MenuItem so GUIGetMsg doesn't get nothing. Create a menu item and all will work good:

#include <GUIConstantsEx.au3>

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 221, 173, 192, 114)
$Menu = GUICtrlCreateMenu("File")
$Menu_Exit = GUICtrlCreateMenuItem("Exit", $Menu)

GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Menu_Exit
            Exit
    EndSwitch
WEnd

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

  • Moderators

aleksa,

You need a MenuItem in the menu: ;)

#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 221, 173, 192, 114)
$Menu = GUICtrlCreateMenu("Exit")
$mExit = GUICtrlCreateMenuItem("Exit", $Menu) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE, $mExit ; Note multiple controls <<<<<<<<<<<<<<<<<<<
               Exit
     EndSwitch
WEnd

Somewhere I once did manage to get a menu to fire directly - I will see if I can find it.:)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

aleksa,

Found it - but it is probably too complex for your needs, so I suggest using a MenuItem as I suggested above: ;)

#include <GUIConstantsEx.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)

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 $mAboutitem
            MsgBox(0, "Solved", "That was hard work!")
    EndSwitch

WEnd

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

    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)
            ExitLoop
        EndIf

    Next

EndFunc

Note that clicking a menu is a modal operation - so you will need to click again to reactivate the script after having clicked a menu with no items. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

×
×
  • Create New...