Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Layout (Forms) Designer » GUI with Menu bar and 5 Labels/Text Boxes
GUI with Menu bar and 5 Labels/Text Boxes [message #24631] Tue, 26 January 2010 03:10 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I am new to U++, seems like a great project.

I have tried all the GUI in the tutorial folder (Gui01 to 22) and have the GUI Tutorial:
http://www.ultimatepp.org/srcdoc$CtrlLib$Tutorial$en-us.html

I am having a problem with Menu bar and 5 Labels/Text Boxes.
I have one GUI that has a Menu bar with all the menu items with sub menus and links. Another GUI that uses the .lay format has 5 Labels and editable text boxes.

The GUI with the Menu I am having a problem adding the Labels/text boxes.

The GUI with the Labels/text boxes I am having a problem adding the Menu.

None of the Gui01 to 22 has both Menu and Labels/Text boxes.
An example that does this would be appreciated.

edit: Starting with the tutorial Gui16 how could a Menu bar be added?

I am getting errors like this:
error C2039: 'Exit' : is not a member of 'Upp::TopWindow'
error C2276: '&' : illegal operation on bound member function xpression

Or starting with Gui07 how could you add the Labels and text boxes?

[Updated on: Tue, 26 January 2010 07:25]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24646 is a reply to message #24631] Tue, 26 January 2010 11:27 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

Post your code here, or testcase.
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24648 is a reply to message #24631] Tue, 26 January 2010 11:45 Go to previous messageGo to next message
mrjt is currently offline  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

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24649 is a reply to message #24646] Tue, 26 January 2010 12:17 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
This is Gui07 modified
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Gui16/dlg.lay>
#include <CtrlCore/lay.h>

struct MyApp : public WithDlgLayout<TopWindow> {
	MenuBar menu;
	MyApp() {
		AddFrame(menu);
		CtrlLayout(*this, "MyDialog");
	}
	
	void GetP1() {
		PromptOK("GetP1 activated!");
	}

	void GetP2() {
		PromptOK("GetP2 activated!");
	}

	void Exit() {
		if(PromptOKCancel("Exit MyApp?"))
			Break();
	}

	void FileMenu(Bar& bar) {
		bar.Add("Open File", THISBACK(Exit));
		bar.Add("Clear File", THISBACK(Exit));
		bar.Add("Exit", THISBACK(Exit));
	}

	void PointsMenu(Bar& bar) {
		bar.Add("Get Point 1", THISBACK(GetP1));
		bar.Add("Get Point 2", THISBACK(GetP2));
		bar.Add("GoTo Point 1", THISBACK(Exit));
		bar.Add("GoTo Point 2", THISBACK(Exit));
	}

	void SubMenu(Bar& bar) {
		bar.Add("Exit", THISBACK(Exit));
	}

	void MainMenu(Bar& bar) {
		bar.Add("File", THISBACK(FileMenu));
		bar.Add("Settings", THISBACK(SubMenu));
		bar.Add("Points", THISBACK(PointsMenu));
		bar.Add("Calculate", THISBACK(SubMenu));
	}


};

GUI_APP_MAIN
{
	MyApp().Run();
}


This is Gui16 modified, it worked with the Labels/Text boxes until I added the Menu code
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyAppWindow : TopWindow {
	MenuBar menu;

	void GetP1() {
		PromptOK("GetP1 activated!");
	}

	void GetP2() {
		PromptOK("GetP2 activated!");
	}

	void Exit() {
		if(PromptOKCancel("Exit MyApp?"))
			Break();
	}

	void FileMenu(Bar& bar) {
		bar.Add("Open File", THISBACK(Exit));
		bar.Add("Clear File", THISBACK(Exit));
		bar.Add("Exit", THISBACK(Exit));
	}

	void PointsMenu(Bar& bar) {
		bar.Add("Get Point 1", THISBACK(GetP1));
		bar.Add("Get Point 2", THISBACK(GetP2));
		bar.Add("GoTo Point 1", THISBACK(Exit));
		bar.Add("GoTo Point 2", THISBACK(Exit));
	}

	void SubMenu(Bar& bar) {
		bar.Add("Exit", THISBACK(Exit));
	}

	void MainMenu(Bar& bar) {
		bar.Add("File", THISBACK(FileMenu));
		bar.Add("Settings", THISBACK(SubMenu));
		bar.Add("Points", THISBACK(PointsMenu));
		bar.Add("Calculate", THISBACK(SubMenu));
	}

	typedef MyAppWindow CLASSNAME;

	MyAppWindow() {
		Title("Neilson"); //.Sizeable();
		AddFrame(menu);
		menu.Set(THISBACK(MainMenu));
	}
};

GUI_APP_MAIN
{
	MyAppWindow app;
	app.SetRect(0, 0, 260, 120);
	app.Run();
}

and the .lay file
LAYOUT(DlgLayout, 208, 132)
	ITEM(Label, dv___0, SetLabel(t_("Point 1")).LeftPosZ(8, 40).TopPosZ(8, 19))
	ITEM(EditField, dv___1, LeftPosZ(48, 156).TopPosZ(76, 19))
	ITEM(EditString, text, LeftPosZ(48, 156).TopPosZ(8, 19))
	ITEM(Option, option, SetLabel(t_("Option")).LeftPosZ(8, 108).TopPosZ(104, 15))
	ITEM(LineEdit, dv___4, LeftPosZ(48, 156).TopPosZ(28, 19))
	ITEM(LineEdit, dv___5, LeftPosZ(48, 156).TopPosZ(52, 19))
	ITEM(Label, dv___6, SetLabel(t_("Point 2")).LeftPosZ(8, 40).TopPosZ(28, 19))
	ITEM(Label, dv___7, SetLabel(t_("Distance")).LeftPosZ(8, 40).VSizePosZ(52, 61))
END_LAYOUT


I also tried from examples Puzzles and EyeCare that have both a menu and addid graphics.
With Puzzles after stripping some of the code there were errors re "unresolved externals".
With EyeCare I am still removing code so I can understand it.
icon13.gif  Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24650 is a reply to message #24649] Tue, 26 January 2010 12:22 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks mrjt for the code, I will try it.

edit: I tried your code and it worked OK.
Saved me a bunch of hours trying to find the problem.

[Updated on: Tue, 26 January 2010 12:30]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24653 is a reply to message #24650] Tue, 26 January 2010 13:15 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Here is a small .jpg of the GUI I use in Java, undecorated and always on top.
I use this to interact with a NASA WorldWind Java app.
I connect with a socket so any language will work.
I am porting several small apps from Java to C++, U++ seems like an ideal way to do it.

Thanks again mrjt for the help!

index.php?t=getfile&id=2168&private=0
  • Attachment: GuiJava.jpg
    (Size: 6.64KB, Downloaded 1302 times)
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24880 is a reply to message #24653] Tue, 02 February 2010 22:06 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I have most of my Java code ported to C++ that uses this GUI.
http://www.ultimatepp.org/forum/index.php?t=msg&th=4895& amp;start=0&

There are three things I have not figured out how to do using u++ and TheIDE.

I am using code like mrjt posted above for the GUI.

1. How can the initial position be set to (6,60) rather than centered.

2. How can this be set to always on top.

3. How to set it undecorated and still be able to drag it.

I can do this in Java with Eclipse and C++ with MSVC++ but need to know how this is done with u++.



Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24903 is a reply to message #24880] Wed, 03 February 2010 18:10 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

nlneilson wrote on Wed, 03 February 2010 03:06


1. How can the initial position be set to (6,60) rather than centered.


If you about dialogs: use NoCenter() method of child windows, then set the positions on screen (maybe, SetRect(...)).

nlneilson wrote on Wed, 03 February 2010 03:06


2. How can this be set to always on top.


Search for TopMost() method in TopWindow class.

nlneilson wrote on Wed, 03 February 2010 03:06


3. How to set it undecorated and still be able to drag it.


Sorry, what do you mean? Popup?

Best regards,
Anton

[Updated on: Wed, 03 February 2010 18:10]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24906 is a reply to message #24903] Wed, 03 February 2010 20:20 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks for the response Sc0rch but I was hoping for an answer that explains how this is done or pointing me to an example that does any of the three. I have spent several hours on these.

mrjt posted some code in this thread message #24648, that is basically what I am using.

I searched the complete u++ directory to find an example that sets the position of the top window, topmost, and undecorated. I found nothing that actually shows how it is done

For undecorated in Java look at the .jpg in a previous post in this thread. message #24653 (2 posts above yours)
The top bar is removed for "undecorated"

In Java this is how it can be done.

frame.setLocation(5, 46);
frame.setAlwaysOnTop(true);
frame.setUndecorated(true);

An actual example (or the actual code) of how these 3 are done in u++ would be appreciated.
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24909 is a reply to message #24906] Wed, 03 February 2010 21:23 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
For always on top this works and where it is placed.
    MyApp() {
        CtrlLayout(*this, "Neilson1");
	TopMost(true, true);

When I answer a post this is how I do it (if I can).
The CODE that works AND where it is to be placed.

Now if I can get the same (code and placement) for:

1. Set initial position for upper left corner of the GUI.

2. Set undecorated (no top bar).

Note: The top bar is usually picked to drag. When undecorated (no top bar) getting the vacant space in the menu bar to be "picked" for dragging was a bit of work in Java. Somebody must have done this in u++.
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24911 is a reply to message #24909] Thu, 04 February 2010 03:32 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Anton!!

Your post pointed me in the right direction.

I downloaded the u++ package several days ago and did not have access to the internet until I just got back so was getting frustrated not having an example to follow.
I just downloaded the GUI Tutorial, it would be good if that was attached to the Help file that is with TheIDE or at least included in the download package.

SetRect(...) does work and over rides the size set in the .lay file. It takes 4 parameters, 2 for the position and 2 for the size where Java takes 2, frame.setLocation(5, 46); The NoCenter() is not necessary.

    MyApp() {
	CtrlLayout(*this, "Neilson1");
	TopMost(true, true);
	SetRect(6, 78, 264, 140);


I copied the GUI Tutorial into the upp directory and did a search for "decorated" in that directory. The only things that came up were:
String DecoratedItem
wbemErrNondecoratedObject
Neither of these seemed to apply.

MSVC has a box to check for this and in Java:
frame.setUndecorated(true);

So unless it is called something else this may not be implemented in upp/TheIDE, at least I found no examples that have it.



Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24912 is a reply to message #24911] Thu, 04 February 2010 07:46 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

nlneilson wrote on Thu, 04 February 2010 08:32


SetRect(...) does work and over rides the size set in the .lay file. It takes 4 parameters, 2 for the position and 2 for the size where Java takes 2, frame.setLocation(5, 46); The NoCenter() is not necessary.



Well, glad to help. Sorry, but I haven't time for examples =(

About NoCenter(): if you can't change the position of dialog, use this method. Just remember for future =)

Best regards and sorry for my English,
Anton
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24913 is a reply to message #24912] Thu, 04 February 2010 09:43 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
You can use:
TopWindow& TopWindow::FrameLess(bool b = true)

Dragging from the menubar is AFAIK not supported, you'll need some workaround for that.
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24918 is a reply to message #24912] Thu, 04 February 2010 14:53 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Anton.

Sc0rch wrote on Thu, 04 February 2010 07:46

Well, glad to help. Sorry, but I haven't time for examples =(

Best regards and sorry for my English,



Your English is fine. What is important is getting the concept of the problem/solution across which you have done. My hang up many times is unlearning something I am used to. Before I used setLocation(10, 60) with 2 parameters.

As for an example that would not take much time if you had:
SetRect(10, 60, 200, 400);
with the 4 parameters that would have been clearer.

You pointed me in the right direction with the correct function, that is what is important.

Thanks
Neil
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24919 is a reply to message #24913] Thu, 04 February 2010 15:15 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks cbpporter.
cbpporter wrote on Thu, 04 February 2010 09:43


TopWindow& TopWindow::FrameLess(bool b = true)



That solves the third problem.

Space is important for a display in an aircraft. I have one app for GPS Tracking that has only a button that pulls up menu items and one text box on the same line. Getting rid of the top bar is important.

edit: For dragging Undecorated/FrameLess: While searching how to do it in Java I came across several in C++, I will just find one of those examples again.

Thanks
Neil

index.php?t=getfile&id=2216&private=0
  • Attachment: uppGUI.jpg
    (Size: 111.08KB, Downloaded 1260 times)

[Updated on: Thu, 04 February 2010 16:17]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #24996 is a reply to message #24919] Sat, 06 February 2010 23:18 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I am using a GUI similar to mrjt's post in this thread.
It works good.

How in theIDE do you put separator lines between the menu items and is it practical to change the pull down width?

The left is java and the right is u++.

index.php?t=getfile&id=2232&private=0

edit: I found an example that had menu.Separator();
with the location where it should be placed.
It worked after changing this to bar.Separator();
It would be good if the Help had some of this in an alphabetical listing. Searching the upp directory works if the naming of the functions are similar to other IDEs.
  • Attachment: Menu_sep.jpg
    (Size: 43.30KB, Downloaded 1248 times)

[Updated on: Sun, 07 February 2010 01:20]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #25023 is a reply to message #24996] Sun, 07 February 2010 20:20 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I like the ability to tinker with the dimensions manually for the location and size. For some of my apps this is very important.

With upp I was able to cut the size (left) from similar in java (right).

index.php?t=getfile&id=2237&private=0

I have run into a problem. The app shows on the task bar but it cannot be minimized or closed from the task bar since I made it Frameless (Undecorated).

A search in the u++ directory for TaskBar found several in CtrlLib\TrayIconWin32.cpp and bazaar\UltimatePlayer but I was unable to figure out how to minimize/maximize and close from the TaskBar when the GUI is Frameless.

Can this be done with upp?

  • Attachment: SmallGUI.jpg
    (Size: 23.44KB, Downloaded 1199 times)
Re: GUI with Menu bar and 5 Labels/Text Boxes [message #25025 is a reply to message #25023] Sun, 07 February 2010 21:51 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

You can check how it is realized in the packages:
- EyerCare
- GoogleTranslator

nlneilson wrote on Sun, 07 February 2010 21:20

I like the ability to tinker with the dimensions manually for the location and size. For some of my apps this is very important.

With upp I was able to cut the size (left) from similar in java (right).

index.php?t=getfile&id=2237&private=0

I have run into a problem. The app shows on the task bar but it cannot be minimized or closed from the task bar since I made it Frameless (Undecorated).

A search in the u++ directory for TaskBar found several in CtrlLib\TrayIconWin32.cpp and bazaar\UltimatePlayer but I was unable to figure out how to minimize/maximize and close from the TaskBar when the GUI is Frameless.

Can this be done with upp?



Re: GUI with Menu bar and 5 Labels/Text Boxes [message #25028 is a reply to message #25025] Mon, 08 February 2010 13:48 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks tojocky, but neither of the packages had something I could figure out.

In EyeCare there was use of TrayIcon which is different from what is shown on the TaskBar for all apps that are running which can be right clicked and closed, minimized, etc., when the app made with upp is not Frameless it can but when it is Frameless it cannot.

With EyeCare it had a TrayIcon and when right clicked it has:
Show EyeCare, Ignore eyes, About and Exit, but not always.

Twice it could not be closed even with the TaskManager and starting the computer again it would pop up, NOT GOOD. I did a search of C:\ and found an EyeCare file in C:\WINDOWS\Prefetch.
I deleted that and every thing else in the search that could be deleted, EyeCare.exe could not until I rebooted again.
Tinkering with code re registry keys is something I want to stay clear of for now.
	HKEY hkey;
	if(RegOpenKeyEx(HKEY_CURRENT_USER, regpath, 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) {
		RegDeleteValue(hkey, regname);
		RegCloseKey(hkey);
	}


The GoogleTranslator package does not have a main so was unable to run it. Looking through the code in the .cpp and .h files there was nothing re TrayIcon, tray, TaskBar or task and could find no code that was related, maybe because I don't know what code could be related to the TaskBar.

When the upp app is running it is on the TaskBar, I would like to be able to right click and have the option for closed, minimized, etc. when it is Frameless the same as when it has a frame.

Is there a way of implementing this with upp?

[Updated on: Mon, 08 February 2010 13:52]

Report message to a moderator

Re: GUI with Menu bar and 5 Labels/Text Boxes [message #25029 is a reply to message #25028] Mon, 08 February 2010 19:00 Go to previous messageGo to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
edit: Searching in this forum for TaskBar showed 15 but only 2 were remotely related.
16 February 2006 message #1048
"when the MenuBar is visible the taskbar shows an empty button for it"
This is no help.

07 May 2008 message #15793
"When I minimize it and then click on the taskbar to bring it back to the foreground, it is no longer maximized."
This is no help either. His problem was with two screens but clicking on the task bar did work and it probably was not Frameless.

Searching for Frameless in this forum:
08 June 2009 message #21838
Quote:

Anyway, if I understood you correctly, yes it's possible to hide the main title bar of the window. For this purpose, e.g. in the Windows operating system, you can change Window Style to not include WS_CAPTION. In U++ we use TopWindow class. It have SyncCaption0 method that changes window styles. FrameLess method can be placed in window constructor. In my opinion, it is not very flexible, because you don't have system menu in this mode and must implement own areas for window placement, close, maximize, minimize buttons, etc.

SetSkin method changes how U++ widget(s) (inherited from Ctrl) looks.


"... must implement own areas for window placement, close, maximize, minimize buttons, etc."

This seems to be a similar problem but I do not want any extra buttons but would like to click on the TaskBar to close, minimize, etc.

By not include WS_CAPTION may work for the Win OS but eventually I would like to be Linux compatible also.
Will the "SetSkin" method retain the TaskBar close, minimize, etc for a FrameLess GUI? If so is there code that shows how this is done?

Like this with the Java app. It works this way with the upp GUI unless it is FrameLess.

index.php?t=getfile&id=2238&private=0
  • Attachment: TaskBar.jpg
    (Size: 15.68KB, Downloaded 1196 times)
Previous Topic: How to make Layout Sizeable & Zoomable
Next Topic: Layout editor problem with Ctrl &
Goto Forum:
  


Current Time: Tue Mar 19 06:27:09 CET 2024

Total time taken to generate the page: 0.01129 seconds