Home » Community » Newbie corner » Non-modal - Dialog will not stay open (Can not get non-modal dialog to stay open - Just flashes then closes)
Non-modal - Dialog will not stay open [message #48318] |
Thu, 22 June 2017 00:46  |
Zed1
Messages: 11 Registered: June 2017
|
Promising Member |
|
|
Hi,
I have been reading up on Ultimate++ and really like the look of it.
I have got basic code working but I am struggling with launching non-modal dialogs / windows.
Please look at the code in main.cpp (Hello::AddressList()) this is where I am trying to launch the dialog from.
I can get the dialog to open with Addr.Run(); (modal) but it locks the main window so I can not access and of the menu items etc...
When I call Addr.Open(); (non-modal) the dialog just flashes open then closes immediately.
What am I missing.
Hello.h
#ifndef _Hello_Hello_h
#define _Hello_Hello_h
#include <CtrlLib/CtrlLib.h>
#include "Address.h"
#define IMAGEFILE <Hello/Hello.iml>
#define IMAGECLASS HelloImg
#include <Draw/iml.h>
using namespace Upp;
class Hello : public TopWindow {
public:
typedef Hello CLASSNAME;
Hello();
// Paint override
void Paint(Draw& w) {
w.DrawRect(GetSize(), Color(66, 134, 244)); // <= enter your background color here
}
private:
MenuBar menu;
StatusBar status;
void FileMenu(Bar& bar);
void MainMenu(Bar& bar);
void About();
void AddressList();
void Exit() {
Break();
}
};
#endif
main.cpp
#include "Hello.h"
Hello::Hello() {
Title("Hello World");
Sizeable().Zoomable();
Maximize();
CenterScreen();
Icon(HelloImg::appicon());
AddFrame(menu);
AddFrame(status);
menu.Set(THISBACK(MainMenu));
menu.WhenHelp = status;
status = "Welcome to the Application";
}
void Hello::About() {
status = "About the application";
PromptOK("{{1@5 [@9= This is the]::@2 [A5@0 Ultimate`+`+ Hello world sample}}");
status = "Ready";
}
void Hello::AddressList() {
status = "Manage Addresses";
Address Addr;
// Modal - Can not access main window menu
//if (Addr.Run(this) != IDOK) { // (this) is the owner of the new window
// status = "Ready";
// return;
//}
// Non Modal - Causes dialog to flash open then close immediately
Addr.Open();
status = "Ready";
}
void Hello::FileMenu(Bar& bar) {
bar.Add("&Adress List", THISBACK(AddressList)).Help("Display all addresses");
bar.Add("About..", THISBACK(About)).Help("About the application");
bar.Separator();
bar.Add("E&xit", [=] { Exit(); }).Help("Exit the application");
}
void Hello::MainMenu(Bar& bar) {
menu.Add("&File", THISBACK(FileMenu));
}
GUI_APP_MAIN {
SetLanguage(LNG_ENGLISH);
Hello().Run();
}
Address.h
#ifndef _Hello_Address_h_
#define _Hello_Address_h_
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <Hello/Address.lay>
#include <CtrlCore/lay.h>
class Address : public WithAddressDlg<TopWindow> {
public:
typedef Address CLASSNAME;
Address();
private:
void ShowInfo();
};
#endif
Address.cpp
#include "Address.h"
Address::Address() {
CtrlLayoutCancel(*this, "Addresses"); // With Cancel button
Sizeable().Zoomable();
addressList.AddColumn("Name");
addressList.AddColumn("Surname");
addressList.AddColumn("Address");
addressList.AddColumn("Email");
for (int j = 0; j < 25; j++) {
Vector<Value> q;
for (int i = j; i < j + 4; i++)
q.Add(i);
addressList.Add(q);
}
addressList.WhenLeftDouble = THISBACK(ShowInfo);
}
void Address::ShowInfo() {
PromptOK(String().Cat() << "First Column: " << addressList.Get(0) << ", Second Column: " << addressList.Get(1));
}
Address.lay
LAYOUT(AddressDlg, 800, 300)
ITEM(ArrayCtrl, addressList, HSizePosZ(4, 4).VSizePosZ(4, 40))
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(12, 68).BottomPosZ(9, 23))
END_LAYOUT
Hello.iml
PREMULTIPLIED
IMAGE_ID(appicon)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,99,16,96,16,96,192,7,196,116,157,67,157,218,79,253,71,198,32,49,188,154,176,234,59,13,197,132,205,129,232)
IMAGE_DATA(61,141,166,15,29,67,228,208,205,32,78,47,110,51,48,221,75,140,25,167,254,163,250,25,187,26,220,102,67,194,2,187)
IMAGE_DATA(252,169,255,229,11,218,255,31,59,166,8,198,32,54,54,53,248,204,6,233,123,120,153,1,140,65,108,252,110,164,84,63)
IMAGE_DATA(249,238,167,52,252,40,141,63,106,164,31,74,211,47,53,242,15,126,115,112,235,3,0,83,220,246,108,0,0,0,0,0)
IMAGE_END_DATA(128, 1)
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 13:31:44 CEST 2025
Total time taken to generate the page: 0.00847 seconds
|