Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » How to create a modal dialog
How to create a modal dialog [message #2299] |
Fri, 07 April 2006 07:59 ![Go to next message Go to next message](theme/default/images/down.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/112.jpg) |
forlano
Messages: 1202 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
so far we have create widgets in the main window of the application. Sometimes the action requires to open a window dialog to get further input from the user. The dialog can be modal or not modal. In the first case the dialog is on the top of the screen and the main window is temporary inactive. In the second case the user can switch and perform action on the dialog and on the main window as well.
The following code is my last experiment with modal dialoga. It shows a main window with a button that open a modal dialog. This last has been create with the Designer (I can't live without it )
#include <CtrlLib/CtrlLib.h>
#define LAYOUTFILE <Vega/editmask.lay> //substitute the path of your layout file
#include <CtrlCore/lay.h>
void testAction()
{ PromptOK("Hello World!");
}
///////////////////////// class //////////////////////
class ButtonOpenDlg : public WithButtonOpen<TopWindow> {
public:
typedef ButtonOpenDlg CLASSNAME;
ButtonOpenDlg();
};
ButtonOpenDlg::ButtonOpenDlg()
{
CtrlLayout(*this, "");
//btnOpen <<= THISBACK(testAction); //this doesn't work: testAction() is a member of ButtonOpenDlg class
btnOpen.WhenAction = callback(testAction); //testAction() must be OUT of the class
}
///////////////////// end class ////////////////////
void OpenDialog()
{
ButtonOpenDlg a;
a.Run();
}
GUI_APP_MAIN
{ TopWindow w;
Button b;
w.Add(b);
b.SetLabel("button - testAction");
b.SetPos(b.PosLeft(200, 250), b.PosTop(100, 30));
b.WhenAction=callback(OpenDialog);
w.Run();
}
//////////////////////// editmask.lay //////////////////
LAYOUT(ButtonOpen, 280, 208)
ITEM(Button, btnOpen, SetLabel(t_("Open Window")).LeftPosZ(92, 96).TopPosZ(88, 24))
END_LAYOUT
I have noticed that the
btnOpen <<= THISBACK(myCallback);
works only for members of the class. While if you want have access to a function out the class you must use
btnOpen.WhenAction = callback(OpenDialog);
Is this correct? One more question. How to create a non modal dialog?
Thank you,
Luigi
|
|
|
|
|
Re: How to create a modal dialog [message #2305 is a reply to message #2303] |
Fri, 07 April 2006 11:24 ![Go to previous message Go to previous message](theme/default/images/up.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/3.png) |
mirek
Messages: 14003 Registered: November 2005
|
Ultimate Member |
|
|
mr_ped wrote on Fri, 07 April 2006 04:25 | Modal dialogs are evil from UI ergonomy point.
Try to avoid them as much as possible, if you think you "need" modal dialog, you are very likely having some serious problem with your overall UI design, or you are taking a coding shortcut to omit code which would be needed to handle more "alive" windows at the same time. (The latter is understandable as resources are never unlimited, but try to avoid them...)
|
Ahh, well, after 8 years of experiences of dealing with users of my little municipal agenda, I would not draw conclusions so fast.
Modal dialogs have their places in GUI.
(That said, it is as easy to do modal and modeless in U++)
Mirek
|
|
|
Goto Forum:
Current Time: Sun Sep 01 06:55:24 CEST 2024
Total time taken to generate the page: 0.00525 seconds
|