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++ Library support » U++ Widgets - General questions or Mixed problems » Where to add event function in theide
Where to add event function in theide [message #21449] Thu, 21 May 2009 09:41 Go to next message
samsam598 is currently offline  samsam598
Messages: 4
Registered: May 2009
Junior Member
Sorry for the silly question since I can't find the answer after tried quite a while:

I was wondering where to add event function to a widget,say a button in theide when using the from designer?

Thanks for your help.
Regards,
Sam

[Updated on: Thu, 21 May 2009 09:46]

Report message to a moderator

Re: Where to add event function in theide [message #21459 is a reply to message #21449] Thu, 21 May 2009 16:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Layout designer creates only the layout, it knows nothing about the final class.

There is a helper for adding THISBACKs (which is I guess rough equivalent to 'even function') in theide - just press Alt+T. Anyway, I am a little bit afraid not many use it now (I do not), maybe it would need some refinement, maybe adding handlers normally (with Assist and Alt+C) is good enough...

Mirek
Re: Where to add event function in theide [message #21473 is a reply to message #21459] Fri, 22 May 2009 03:22 Go to previous messageGo to next message
samsam598 is currently offline  samsam598
Messages: 4
Registered: May 2009
Junior Member
Thanks so much for your help.I mean,for example,when one clicks a button named btnOK,something happens:

void btnOK_Click()
{
PromptOK("Button btnOK is clicked.");
}

In the ide,when I create a form with a button,I can not find out where to add the above code.

ALT+T or Assist(ALT+C) all tried but it does not help.

Regards,
Sam
Re: Where to add event function in theide [message #21478 is a reply to message #21473] Fri, 22 May 2009 10:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
samsam598 wrote on Thu, 21 May 2009 21:22

Thanks so much for your help.I mean,for example,when one clicks a button named btnOK,something happens:

void btnOK_Click()
{
PromptOK("Button btnOK is clicked.");
}

In the ide,when I create a form with a button,I can not find out where to add the above code.

ALT+T or Assist(ALT+C) all tried but it does not help.

Regards,
Sam


I see.

First of all, do you already have dialog class?

http://www.ultimatepp.org/reference$Layout.html

(beware, above example shows how to create your dialog class, not your case).

Anyway, as long as you have such class, simply put

myOKbutton = callback(btnOK_Click);

into constructor.

Note that in 99.99% cases, you will rather want to call a method of dialog, not global level function. That is what Alt+T is designed for. Also, as soon as you type THISBACK(, Assist++ will offer a list of methods...

Another relevant example:

http://www.ultimatepp.org/examples$Button.html

Just in this case, no layout is used. Anyway, using designed layout has very similar effect to adding "button" member variable and "Add(button.VCenterPos(20).HCenterPos(200));"...

Mirek
Re: Where to add event function in theide [message #21485 is a reply to message #21478] Fri, 22 May 2009 14:54 Go to previous messageGo to next message
samsam598 is currently offline  samsam598
Messages: 4
Registered: May 2009
Junior Member
Sorry,sorry,so sorry to keep asking...

In both case you've described,I fully understood the poit.My problem is that in the designer I create a button ,and I gave it a name (in column "variable/id?") *btnOK*.Then I change to head file and cpp file where there is no such a variable named btnOK inside the entire file,no only any classes,so how can I call

btnOK=callback(btnOKClick);//where is variable *btnOK*?

This is the problem I met.
Thanks a million.

Regards,
Sam
Re: Where to add event function in theide [message #21486 is a reply to message #21485] Fri, 22 May 2009 15:29 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
By using the Layout editor you create just a template, a recipe if you will, for creating a window or a widget that will have that layout and those fields. It is a definition, speaking in C terms. You need a declaration.

Let’s say you named your template TestLayout. Now you can create a concrete layout by appending "With" to the name of the template:
class testWindows: WithTestLayout<TopWindow>


Now you have a class with that layout and it will contain your "btnOK". Yet you can search in the code and you won’t find that explicit declaration anywhere.

In one of your methods from the class, usually the constructor, you can say:
btnOK=callback(btnOKClick);


Or if you want to use a less OOP approach, you can do:
WithTestLayout<StaticRect> b;
b.btnOk=callback...

Notice this time I used StaticRect. You can apply the layout to anything you want, including Buttons, EditFields and every existing widget, including your own if you have written any custom widgets.

PS: Don't forget to call CtrlLayout. Without it you layout will appear null.
I hope you’ll have more success with layouts in the future. Very powerful once you get used to them.
Re: Where to add event function in theide [message #21487 is a reply to message #21486] Fri, 22 May 2009 15:54 Go to previous messageGo to next message
samsam598 is currently offline  samsam598
Messages: 4
Registered: May 2009
Junior Member
Ah~ Embarassed
Got it and will experence later.Thanks so much for your prompt response!

Btw,may I ask is the GUI native feel and look to the platform like wxWidgtes or just self-drawing like the one Qt does?Furthermore,for a begenner of U++,where should I start,the tutorial or the examples or something else?

Thanks.

Regards,
Sam
Re: Where to add event function in theide [message #21488 is a reply to message #21449] Fri, 22 May 2009 16:10 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
While editing layout file, you can press Ctrl+T to see the actual C++ definition of edited layout.
(although it consist of powerful macros, so it may be somewhat confusing to decode it)

Also you can use preprocess (Alt+F7) on the file where the layout is included and used to see final generated C++ code and get better idea how the layout editor works in U++.
Re: Where to add event function in theide [message #21491 is a reply to message #21487] Fri, 22 May 2009 18:34 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
samsam598 wrote on Fri, 22 May 2009 09:54

Ah~ Embarassed
Got it and will experence later.Thanks so much for your prompt response!

Btw,may I ask is the GUI native feel and look to the platform like wxWidgtes or just self-drawing like the one Qt does?



It is self-drawing. It has flexible skin system and on start, it skins itself to look and feel native (at least as close as possible).

Quote:


Furthermore,for a begenner of U++,where should I start,the tutorial or the examples or something else?



I think you should first go through

Getting Started With Ultimate++

of

http://www.ultimatepp.org/www$uppweb$documentation$en-us.htm l

then play with examples and reference examples.

(the difference is that "examples" example tries to demoU++ in relatively complex apps, while "reference" example focuses on single aspect)

Mirek
Previous Topic: ASSERT(IsMainThread());
Next Topic: Menus on dual monitors (Windows)
Goto Forum:
  


Current Time: Thu Mar 28 12:02:33 CET 2024

Total time taken to generate the page: 0.01227 seconds