Home » U++ TheIDE » U++ TheIDE: Layout (Forms) Designer » GUI with Menu bar and 5 Labels/Text Boxes
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24648 is a reply to message #24631] |
Tue, 26 January 2010 11:45 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
1- Starting with Gui16 (You could also start with a new package with a main window, as this is a more suitable start to an application).
2- Add 'typedef xxx CLASSNAME' and MenuBar member to the class (see comments below for explanations)
3- Initialise the MenuBar in the class constructor
4- Add callback handling functions for menu, sub-menus and menu items.
5- Done. There is a small problem that the layout is now the wrong size but you can adjust this in the .lay file designer. It can also be done in code but I've left that out for simpliciy.
The final code:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <Gui16/dlg.lay>
#include <CtrlCore/lay.h>
struct MyApp : public WithDlgLayout<TopWindow> {
typedef MyApp CLASSNAME; // This makes the THISBACK macro work
MenuBar menu; // This is your menu bar
MyApp() {
CtrlLayout(*this, "MyDialog");
AddFrame(menu); // To make a menu bar you must add the frame before setting the callback
menu.Set(THISBACK(MainMenu)); // Set the menu callback
}
// Main menu bar
void MainMenu(Bar &bar) {
bar.Add("File", THISBACK(FileMenu));
bar.Add("About", THISBACK(AboutMenu));
}
// File sub-menu
void FileMenu(Bar &bar) {
bar.Add("Exit", THISBACK(Exit));
}
// About sub-menu
void AboutMenu(Bar &bar) {
bar.Add("About", THISBACK(About));
}
// About menu handler
void About() {
// Show about stuff
}
// Exit menu handler
void Exit() {
if(PromptOKCancel("Exit MyApp?"))
Break(); // Closes window with 'Cancel'
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
I think the error you made before was leaving out the Exit() function.
[Updated on: Tue, 26 January 2010 11:49] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Wed May 15 04:03:16 CEST 2024
Total time taken to generate the page: 0.04715 seconds
|