AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help a beginner with Gui Menu

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
afterburner



Joined: 23 Jul 2005
Posts: 52

PostPosted: Sat Apr 08, 2006 8:43 am    Post subject: Help a beginner with Gui Menu Reply with quote

How do I place a Menu bar on a GUI? Here is my code and it does not work:
Code:
Gui, Add, GroupBox, x3 y14 w894 h8 ,
Gui, Show, x61 y35 h659 w902, test
Menu, FileMenu, Add, &Open, MenuHandler
Menu, FileMenu, Add, E&xit, MenuHandler
Menu, HelpMenu, Add, &About, MenuHandler
Menu, MyMenuBar, Add, &File, :FileMenu
Return

GuiClose:
ExitApp
I used the samples from the help files.

Last edited by afterburner on Sun Apr 09, 2006 8:55 am; edited 2 times in total
Back to top
View user's profile Send private message
Hotfoot



Joined: 14 Sep 2005
Posts: 21

PostPosted: Sat Apr 08, 2006 8:56 pm    Post subject: Reply with quote

I would suggest downloading and using SmartGUI from the Catalog of Scripts section. It will help you create a GUI without coding on your own. You can look at the code afterwards and learn from it.
Back to top
View user's profile Send private message
afterburner



Joined: 23 Jul 2005
Posts: 52

PostPosted: Sun Apr 09, 2006 10:07 am    Post subject: Reply with quote

I d/l SmartGUI, it's awesome. Yet I did not see any info about how to create a Menu Bar control. I used the code out of the help files but it gives me an error on the first line of the Menu stuff. So what have I misunderstood this time? Help!
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Apr 09, 2006 10:58 am    Post subject: Re: Help a beginner with Gui Menu Reply with quote

afterburner wrote:
I used the samples from the help files.
You forgot the most important line...
Code:
Gui, Add, GroupBox, x3 y14 w894 h8 ,
Gui, Show, x61 y35 h659 w902, test
Menu, FileMenu, Add, &Open, MenuHandler
Menu, FileMenu, Add, E&xit, MenuHandler
Menu, HelpMenu, Add, &About, MenuHandler
Menu, MyMenuBar, Add, &File, :FileMenu
Gui Menu, MyMenuBar
Return

GuiClose:
ExitApp

MenuHandler:
   MsgBox %A_ThisMenuItem% (%A_ThisMenuItemPos%)
Return

_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
afterburner



Joined: 23 Jul 2005
Posts: 52

PostPosted: Sun Apr 09, 2006 6:54 pm    Post subject: Reply with quote

(With pie on my face) Thank you for piecing it together for me again PhiLho I seem to count on you alot.
Back to top
View user's profile Send private message
afterburner



Joined: 23 Jul 2005
Posts: 52

PostPosted: Sun Apr 09, 2006 8:11 pm    Post subject: Reply with quote

More questions:
    1. Is the word "MenuHandler" part of AutoHotkey syntax or is that user defined?
    2. What syntax woud I use if I wanted more than one item on the menu bar? (File, Edit, View, Help)
    3. Will I need a word/MenuHandler for each item on the menu bar if I have more than one item?
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Apr 10, 2006 8:11 am    Post subject: Reply with quote

1) No, you can name it the way you want.
2) See below.
3) Not necessarily, I shown that you can use built-in variables to know which menu item was called (by name or by pos).
Code:
/* SampleMenu.ahk
A simple application menu I keep as skeleton.
*/
; Print sub-menu
Menu mFP, Add, &on file, MenuHandling
Menu mFP, Add, &on printer, MenuHandling

; File menu
Menu mF, Add, &Open, MenuHandling
Menu mF, Add, &Save, MenuHandling
Menu mF, Add
Menu mF, Add, &Print, :mFP
Menu mF, Add
Menu mF, Add, &Exit, MenuHandling

; Edit menu
Menu mE, Add, &Undo`tCtrl+Z, MenuHandling
Menu mE, Add
Menu mE, Add, &Cut`tCtrl+X, MenuHandling
Menu mE, Add, C&opy`tCtrl+C, MenuHandling
Menu mE, Add, &Paste`tCtrl+V, MenuHandling
Menu mE, Add, &Delete`tDel, MenuHandling
Menu mE, Add, Select &All`tCtrl+A, MenuHandling

; Help menu
Menu mH, Add, &About..., MenuHandling
Menu mH, Add
Menu mH, Add, &Topics, MenuHandling

; The main menu bar for the application
Menu menuBar, Add, &File, :mF
Menu menuBar, Add, &Edit, :mE
Menu menuBar, Add, &Help, :mH

; Attach it to GUI
Gui Menu, menuBar
; Fill GUI with something
;~ Gui Add, GroupBox, xm ym-11 w200 h7
Gui Add, Button, xm+100 ym+50 gSubmit, OK
Gui Add, Button, ym+50 gGuiEscape, Cancel
; Show it!
Gui Show, w200 h100
Return

MenuHandling:
   MsgBox %A_ThisMenu%: %A_ThisMenuItem% (%A_ThisMenuItemPos%)
   If (A_ThisMenu = "mF" && A_ThisMenuItemPos = 6)   ; Exit
      ExitApp
Return

Submit:
   MsgBox You got it!
Return

GuiClose:
GuiEscape:
ExitApp
I suggest to use by pos rather by name, because names are hard to manage (& accelerator, tab with shortcut) and may change (localization, etc.).
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group