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  |
 |
forlano
Messages: 1207 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
|
|
|
Goto Forum:
Current Time: Sat Apr 26 13:39:35 CEST 2025
Total time taken to generate the page: 0.00303 seconds
|