Rantanplan Posted September 24, 2010 Share Posted September 24, 2010 I have the problem that my application stops when selecting a menu (disabled or enabled - does no matter) In sample code there is a menu, which is disabled after pressing "OK". By selecting the disabled "File"-menu or the enabled "Help"-menu during running of the Function "_doSomething(), the execution just stops. I want to know now how it is possible to get an information that a menu (NOT a Menuitem!) was selected. Can anybody help me with this topic? Thx Rantanplan expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Global $randomLabel,$filemenu _Main() Func _Main() Local $fileitem, $recentfilesmenu, $separator1 Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton Local $msg, $file #forceref $separator1 GUICreate("GUI menu", 300, 200) $filemenu = GUICtrlCreateMenu("File") $fileitem = GUICtrlCreateMenuItem("Open...", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu) $separator1 = GUICtrlCreateMenuItem("", $filemenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("?") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20) $randomLabel = GUICtrlCreateLabel("XX",50,50) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $fileitem $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu) Case $msg = $exititem ExitLoop Case $msg = $okbutton _doSomething() Case $msg = $aboutitem MsgBox(0, "About", "GUI Menu Test") EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Func _doSomething() Local $i,$n GUICtrlSetState($filemenu,$GUI_DISABLE) For $i = 1 To 50 Step 1 $n = Random(1,100,1) GUICtrlSetData($randomLabel,$n) Sleep(300) Next GUICtrlSetState($filemenu,$GUI_ENABLE) EndFunc Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted September 24, 2010 Share Posted September 24, 2010 i didnt get your point can you explain more so i can help you thanks and i'm waiting your reply Link to comment Share on other sites More sharing options...
wakillon Posted September 24, 2010 Share Posted September 24, 2010 i didnt get your point can you explain more so i can help you thanks and i'm waiting your replyHe want get an information that a menu (NOT a Menuitem!) was selected.but i don't find any solution... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Rantanplan Posted September 24, 2010 Author Share Posted September 24, 2010 i didnt get your point can you explain more so i can help you thanks and i'm waiting your replyHello cobako, just compile the script and run it. By pressing "OK" you will see some numbers appear. While those numbers change, select the disabled menu "File". You will see that the numbers are not changing any more. The focus is stolen. If you click on the number which is displayed now, the focus is taken back to the "number-changing-prog". Now I just want to know, if there is any chance to get the event, that the menu is chosen. Thx Rantanplan Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted September 24, 2010 Share Posted September 24, 2010 ok got it i will try somethings then come back Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted September 24, 2010 Share Posted September 24, 2010 my edit will Notify u when menu clicked here you are expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt('MustDeclareVars', 1) Global $randomLabel,$filemenu _Main() Func _Main() Local $fileitem, $recentfilesmenu, $separator1 Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton Local $msg, $file #forceref $separator1 GUICreate("GUI menu", 300, 200) $filemenu = GUICtrlCreateMenu("File") $fileitem = GUICtrlCreateMenuItem("Open...", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu) $separator1 = GUICtrlCreateMenuItem("", $filemenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("?") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20) $randomLabel = GUICtrlCreateLabel("XX",50,50) GUISetState() GUIRegisterMsg(0x0211,"WM_ENTERMENULOOP") While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $fileitem $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu) Case $msg = $exititem ExitLoop Case $msg = $okbutton _doSomething() Case $msg = $aboutitem MsgBox(0, "About", "GUI Menu Test") EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Func _doSomething() Local $i,$n GUICtrlSetState($filemenu,$GUI_DISABLE) For $i = 1 To 50 Step 1 $n = Random(1,100,1) GUICtrlSetData($randomLabel,$n) Sleep(300) Next GUICtrlSetState($filemenu,$GUI_ENABLE) EndFunc Func WM_ENTERMENULOOP() MsgBox(0,"Menu","Menu Clicked") EndFunc if you want to get notify when an menu has been exited ,use this code GUIRegisterMsg(0x0212,"WM_EXITMENULOOP") Func WM_EXITMENULOOP() MsgBox(0,"Menu","Menu has been exited") EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2010 Moderators Share Posted September 24, 2010 (edited) Rantanplan,You can tell the menu has been clicked by registering the WM_ENTERMENULOOP message and then reset the focus to the main GUI like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt('MustDeclareVars', 1) Global $randomLabel,$filemenu, $hGUI, $fMenuDisable = False _Main() Func _Main() Local $fileitem, $recentfilesmenu, $separator1 Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton Local $msg, $file #forceref $separator1 $hGUI = GUICreate("GUI menu", 300, 200) $filemenu = GUICtrlCreateMenu("File") $fileitem = GUICtrlCreateMenuItem("Open...", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu) $separator1 = GUICtrlCreateMenuItem("", $filemenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $helpmenu = GUICtrlCreateMenu("?") $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu) $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20) $randomLabel = GUICtrlCreateLabel("XX",50,50) GUISetState() GUIRegisterMsg(0x0211,"_WM_ENTERMENULOOP") ; WM_ENTERMENULOOP While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $fileitem $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)") If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu) Case $msg = $exititem ExitLoop Case $msg = $okbutton _doSomething() Case $msg = $aboutitem MsgBox(0, "About", "GUI Menu Test") EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Func _doSomething() Local $i,$n $fMenuDisable = True For $i = 1 To 50 Step 1 $n = Random(1,100,1) GUICtrlSetData($randomLabel,$n) Sleep(300) Next $fMenuDisable = False EndFunc Func _WM_ENTERMENULOOP() ConsoleWrite("Menu Clicked" & @CRLF) If $fMenuDisable Then ControlFocus($hGUI, "", $randomLabel) EndFuncPlease ask if you have any questions. M23Edit: I see cobako beat me to it. But please do NOT use a MsgBox in a registered message handler. As it says in the Help file:"Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!" Edited September 24, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ProgrammingBrain Posted September 24, 2010 Share Posted September 24, 2010 Melba23 you welcome and i added MsgBox for example only Link to comment Share on other sites More sharing options...
wakillon Posted September 24, 2010 Share Posted September 24, 2010 @MelbaHe want "get an information that a menu (NOT a Menuitem!) was selected."your solution doesn't precise which menu is selected ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 24, 2010 Moderators Share Posted September 24, 2010 wakillon,He want "get an information that a menu (NOT a Menuitem!) was selected."Which is exactly what the script does. your solution doesn't precise which menu is selected!But that was not part of the question! The OP wanted to prevent the menu bar stealing focus from the main GUI and stopping the running function. By looking to see if the $fMenuDisable flag is set, the script resets the focus to the main GUI when the menu bar is clicked and the function is running. This prevents the function from pausing. Once the function is terminated, the menu bar behaves as normal.Anyway, let us see if the OP is happy with what he has got so far. If not, then you can delve further into MSDN to try and find how to get the specific menu item which was clicked! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Rantanplan Posted September 24, 2010 Author Share Posted September 24, 2010 Hello all! Thank you very much for solving that problem in such a short time. I can now get back to a stable state in the prog, cause now I have the message that a menu was used captured. Thx Rantanplan Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 25, 2010 Moderators Share Posted September 25, 2010 Hi again,If anyone is interested, I have namaged to solve the "which menu item was pressed" problem: expandcollapse popup#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 EndFuncM23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wakillon Posted September 25, 2010 Share Posted September 25, 2010 Waou !Trop fort M23 ! Thanks AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts 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