Mercurial > dwindows
comparison dwtestoo.cpp @ 2889:4b075e64536c
C++: Add some simple menu code to see if things are working.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 22 Dec 2022 19:20:39 +0000 |
parents | d301fed4bc23 |
children | 5a6bf6bd3001 |
comparison
equal
deleted
inserted
replaced
2888:ec0d34798706 | 2889:4b075e64536c |
---|---|
16 | 16 |
17 #ifndef DW_CPP11 | 17 #ifndef DW_CPP11 |
18 int button_clicked() | 18 int button_clicked() |
19 { | 19 { |
20 DW::App *app = DW::App::Init(); | 20 DW::App *app = DW::App::Init(); |
21 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); | 21 app->MessageBox("Button", DW_MB_OK | DW_MB_INFORMATION, "Clicked!"); |
22 return TRUE; | |
23 } | |
24 | |
25 int exit_handler() | |
26 { | |
27 DW::App *app = DW::App::Init(); | |
28 if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | |
29 app->MainQuit(); | |
30 } | |
22 return TRUE; | 31 return TRUE; |
23 } | 32 } |
24 #endif | 33 #endif |
25 | 34 |
26 int dwmain(int argc, char* argv[]) | 35 int dwmain(int argc, char* argv[]) |
27 { | 36 { |
28 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); | 37 DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); |
29 MyWindow *window = new MyWindow(); | 38 MyWindow *window = new MyWindow(); |
30 DW::Button *button = new DW::Button("Test window"); | 39 DW::Button *button = new DW::Button("Test window"); |
31 | 40 |
32 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); | 41 window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); |
33 #ifdef DW_CPP11 | 42 #ifdef DW_CPP11 |
34 button->ConnectClicked([app] () -> int | 43 button->ConnectClicked([app] () -> int |
35 { | 44 { |
36 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); | 45 app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); |
37 return TRUE; | 46 return TRUE; |
38 }); | 47 }); |
39 #else | 48 #else |
40 button ->ConnectClicked(&button_clicked); | 49 button->ConnectClicked(&button_clicked); |
41 #endif | 50 #endif |
51 | |
52 DW::MenuBar *mainmenubar = window->MenuBarNew(); | |
53 | |
54 // add menus to the menubar | |
55 DW::Menu *menu = new DW::Menu(); | |
56 DW::MenuItem *menuitem = menu->AppendItem("~Quit"); | |
57 #ifdef DW_CPP11 | |
58 menuitem->ConnectClicked([app] () -> int | |
59 { | |
60 if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) { | |
61 app->MainQuit(); | |
62 } | |
63 return TRUE; | |
64 }); | |
65 #else | |
66 menuitem->ConnectClicked(&exit_handler); | |
67 #endif | |
68 | |
69 // Add the "File" menu to the menubar... | |
70 mainmenubar->AppendItem("~File", menu); | |
71 | |
42 window->Show(); | 72 window->Show(); |
43 | 73 |
44 app->Main(); | 74 app->Main(); |
45 app->Exit(0); | 75 app->Exit(0); |
46 | 76 |