Sign in to follow this  
Followers 0
PsaltyDS

Alt+F for File menu not working

7 posts in this topic

#1 ·  Posted (edited)

I must be missing something simple. My GUIs have tended to be simplistic and utilitarian. I decided it would be good to spruce up a bit with menu bar functions. First problem to arise from that is most of my GUIs are run in event mode. That doesn't seem to work properly with "&File" to get me Alt-f opens the file menu. It clearly works in the help file demo, but not in my event mode GUI. I would like to have Alt-f open the File menu, and Alt-h open Help (not talking HotKeySet() here).

What am I missing?

; Includes
#include <guiconstants.au3>

; Create GUI interface
Opt("GuiOnEventMode", 1)
$hGUI = GUICreate("GUI Menu Demo", 500, 400)

; Add File menu
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$FileMenu = GUICtrlCreateMenu("&File")
$FileMenuOpen = GUICtrlCreateMenuItem("&Open", $FileMenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
GUICtrlSetOnEvent(-1, "_FileMenuOpen")
$FileMenuSave = GUICtrlCreateMenuItem("&Save", $FileMenu)
GUICtrlSetOnEvent(-1, "_FileMenuSave")
GUICtrlCreateMenuItem("E&xit", $FileMenu)
GUICtrlSetOnEvent(-1, "_Quit")

; Add Help Menu
$HelpMenu = GUICtrlCreateMenu("&Help")
$HelpMenuAbout = GUICtrlCreateMenuItem("About", $HelpMenu)
GUICtrlSetOnEvent(-1, "_HelpMenuAbout")

; Show GUI
GUISetState(@SW_SHOW)

; Await user actions
While 1
    Sleep(20)
WEnd

Func _FileMenuOpen()
    MsgBox(64, "GUI Menu Demo", "Selected File | Open", 2)
EndFunc   ;==>_FileMenuOpen

Func _FileMenuSave()
    MsgBox(64, "GUI Menu Demo", "Selected File | Save", 2)
EndFunc   ;==>_FileMenuSave

Func _HelpMenuAbout()
    MsgBox(64, "GUI Menu Demo", "GUI Menu Demo" & @CRLF & _
            "By: PsaltyDS" & @CRLF & _
            "Version: 0.1  --  Dated: 10 May, 2007", 10)
EndFunc   ;==>_HelpMenuAbout

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Edit: Corrected mistake in description of expected behavior.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites



A blast from the past - it's Kenny with "Do The Bump"

There's a new dance that is going around

Called the Bump

do the Bump.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

PsaltyDS - I'd also like to know, my guess is that GUIGetMsg() has that funcation embedded in it. Thats my guess/shot in the dark as to why.

I suppose we could put in the main loop, if active & _ispressed then display number

Edited by Sardith

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It was pointed out that I DIDN'T say exactly what WAS working... oops.

The example in the 3.2.3.14 help file under GuiCtrlCreateMenu() does correctly in message mode what I can't get working in event mode.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I don't know why really, but you have to set focus on something else...

CODE
; Includes
#include <guiconstants.au3>

; Create GUI interface
Opt("GuiOnEventMode", 1)
$hGUI = GUICreate("GUI Menu Demo", 500, 400)

; Add File menu
$FileMenu = GUICtrlCreateMenu("&File")
$FileMenuOpen = GUICtrlCreateMenuItem("&Open", $FileMenu)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$FileMenuSave = GUICtrlCreateMenuItem("&Save", $FileMenu)
GUICtrlCreateMenuItem("E&xit", $FileMenu)

; Add Help Menu
$HelpMenu = GUICtrlCreateMenu("&Help")
$HelpMenuAbout = GUICtrlCreateMenuItem("About", $HelpMenu)

;Why in the hell I had to have focus on something else... I have no idea!
GUICtrlCreateLabel('',0,0,0,0)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetState(-1, @SW_HIDE)

GUISetOnEvent(-3, '_ExitNow')
GUICtrlSetOnEvent($FileMenuOpen, '_EventHandler')
GUICtrlSetOnEvent($FileMenuSave, '_EventHandler')
GUICtrlSetOnEvent($HelpMenuAbout, '_EventHandler')

; Show GUI
GUISetState(@SW_SHOW)

; Await user actions
While 1
    Sleep(1000000)
WEnd

Func _EventHandler()
    Switch @GUI_CtrlId
        Case $FileMenuOpen
            _FileMenuOpen()
        Case $FileMenuSave
            _FileMenuSave()
        Case $HelpMenuAbout
            _HelpMenuAbout()
    EndSwitch
EndFunc

Func _FileMenuOpen()
    MsgBox(64, "GUI Menu Demo", "Selected File | Open", 2)
EndFunc   ;==>_FileMenuOpen

Func _FileMenuSave()
    MsgBox(64, "GUI Menu Demo", "Selected File | Save", 2)
EndFunc   ;==>_FileMenuSave

Func _HelpMenuAbout()
    MsgBox(64, "GUI Menu Demo", "GUI Menu Demo" & @CRLF & _
            "By: PsaltyDS" & @CRLF & _
            "Version: 0.1  --  Dated: 10 May, 2007", 10)
EndFunc   ;==>_HelpMenuAbout

Func _ExitNow()
    Exit
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Bah! Wtf? I just wrote up a reply to this thread and the board sent me back to the forum index when I hit Add. Bah!!

Anyway, to summarize what I said, this has been bug reported before IIRC (it's a Windows bug). A window's menu controls will not work properly if there are no other controls on the window. So just create a spare label and hide it or something like Smoke suggested (although you don't have to give it focus).

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Bah! Wtf? I just wrote up a reply to this thread and the board sent me back to the forum index when I hit Add. Bah!!

Anyway, to summarize what I said, this has been bug reported before IIRC (it's a Windows bug). A window's menu controls will not work properly if there are no other controls on the window. So just create a spare label and hide it or something like Smoke suggested (although you don't have to give it focus).

Big thanks to SmOke_N and Saunders for figuring out. I don't have a need for a GUI with just a menu and no other controls right now, so the bug was unintentionally invoked! I was just testing a GUI for a new script one piece at time and the menu was as far as I got when I notice it. The only reason the demo didn't have any other controls was an attempt to post the minimal demo needed. Got more than I bargined for... :)

Thanks again, guys!

:D

Edit: Got to a Windows box and tested it. Sure enough, all I added to the GUI was a single NOOP button per SmOke_N, and the menu now works as advertised:

; Add a button
GUICtrlCreateButton("NOOP", 200, 330, 100, 40)

; Show GUI
GUISetState(@SW_SHOW)
Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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