diff 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
line wrap: on
line diff
--- a/dwtestoo.cpp	Thu Dec 22 19:08:39 2022 +0000
+++ b/dwtestoo.cpp	Thu Dec 22 19:20:39 2022 +0000
@@ -18,7 +18,16 @@
 int button_clicked()
 {
     DW::App *app = DW::App::Init();
-    app->MessageBox("Button", DW_MB_OK | DW_MB_WARNING, "Clicked!"); 
+    app->MessageBox("Button", DW_MB_OK | DW_MB_INFORMATION, "Clicked!"); 
+    return TRUE; 
+}
+
+int exit_handler()
+{
+    DW::App *app = DW::App::Init();
+    if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) {
+        app->MainQuit();
+    }
     return TRUE; 
 }
 #endif
@@ -28,7 +37,7 @@
     DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo");
     MyWindow *window = new MyWindow();
     DW::Button *button = new DW::Button("Test window");
-    
+
     window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0);
 #ifdef DW_CPP11
     button->ConnectClicked([app] () -> int 
@@ -37,8 +46,29 @@
             return TRUE; 
         });
 #else
-    button ->ConnectClicked(&button_clicked);
+    button->ConnectClicked(&button_clicked);
 #endif
+
+    DW::MenuBar *mainmenubar = window->MenuBarNew();
+
+    // add menus to the menubar
+    DW::Menu *menu = new DW::Menu();
+    DW::MenuItem *menuitem = menu->AppendItem("~Quit");
+#ifdef DW_CPP11
+    menuitem->ConnectClicked([app] () -> int 
+        { 
+            if(app->MessageBox("dwtest", DW_MB_YESNO | DW_MB_QUESTION, "Are you sure you want to exit?") != 0) {
+                app->MainQuit();
+            }
+            return TRUE;
+        });
+#else
+    menuitem->ConnectClicked(&exit_handler);
+#endif
+
+    // Add the "File" menu to the menubar...
+    mainmenubar->AppendItem("~File", menu);
+
     window->Show();
 
     app->Main();