AutoHotkey Community

It is currently May 27th, 2012, 8:32 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: April 8th, 2006, 9:43 am 
Offline

Joined: July 23rd, 2005, 2:13 am
Posts: 52
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 April 9th, 2006, 9:55 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2006, 9:56 pm 
Offline

Joined: September 14th, 2005, 5:21 am
Posts: 21
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2006, 11:07 am 
Offline

Joined: July 23rd, 2005, 2:13 am
Posts: 52
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!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 9th, 2006, 11:58 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2006, 7:54 pm 
Offline

Joined: July 23rd, 2005, 2:13 am
Posts: 52
(With pie on my face) Thank you for piecing it together for me again PhiLho I seem to count on you alot.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2006, 9:11 pm 
Offline

Joined: July 23rd, 2005, 2:13 am
Posts: 52
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2006, 9:11 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.).

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Exabot [Bot], sjc1000, specter333 and 70 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group