comparison dwtestoo.cpp @ 2882:99311a9091af

C++: Add lambda support via Connect functions on C++11, on older compilers use traditional function pointers instead. Also added inital menu support although it is incomplete as of this commit.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 22 Dec 2022 13:59:46 +0000
parents 0bbfb19022e7
children d301fed4bc23
comparison
equal deleted inserted replaced
2881:ac404083dc6b 2882:99311a9091af
12 } 12 }
13 int OnDelete() override { DW::App *app = DW::App::Init(); app->MainQuit(); return FALSE; } 13 int OnDelete() override { DW::App *app = DW::App::Init(); app->MainQuit(); return FALSE; }
14 int OnConfigure(int width, int height) override { return FALSE; } 14 int OnConfigure(int width, int height) override { return FALSE; }
15 }; 15 };
16 16
17 #ifndef DW_CPP11
18 int button_clicked()
19 {
20 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!");
21 return TRUE;
22 }
23 #endif
24
17 int dwmain(int argc, char* argv[]) 25 int dwmain(int argc, char* argv[])
18 { 26 {
19 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); 27 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo");
20 MyWindow *window = new MyWindow(); 28 MyWindow *window = new MyWindow();
21 DW::Text *text = new DW::Text("Test window"); 29 DW::Button *button = new DW::Button("Test window");
22 30
23 window->PackStart(text, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); 31 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0);
24 text->SetStyle(DW_DT_CENTER | DW_DT_VCENTER, DW_DT_CENTER | DW_DT_VCENTER); 32 #ifdef DW_CPP11
33 button->ConnectClicked([app] () -> int
34 {
35 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!");
36 return TRUE;
37 });
38 #else
39 button ->ConnectClicked(&button_clicked);
40 #endif
25 window->Show(); 41 window->Show();
26 42
27 app->Main(); 43 app->Main();
28 app->Exit(0); 44 app->Exit(0);
29 45