FLTK logo

[master] 90dbf0c - Fix menu-with-images example w/o using exit()

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 90dbf0c - Fix menu-with-images example w/o using exit() "Albrecht Schlosser" Mar 20, 2021  
 
commit 90dbf0c77dee3370fa878cfc67c681e2675fb2a7
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Sun Mar 21 01:58:54 2021 +0100
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Sun Mar 21 01:58:54 2021 +0100

    Fix menu-with-images example w/o using exit()
    
    Use window->hide() in quit callback instead.

 examples/howto-menu-with-images.cxx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git examples/howto-menu-with-images.cxx examples/howto-menu-with-images.cxx
index 1262ffd..e0be5ca 100644
--- examples/howto-menu-with-images.cxx
+++ examples/howto-menu-with-images.cxx
@@ -4,7 +4,7 @@
 //     How to use Fl_Multi_Label to make menu items with images and labels.
 //
 // Copyright 2017 Greg Ercolano.
-// Copyright 1998-2017 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -16,6 +16,7 @@
 //
 //     https://www.fltk.org/bugs.php
 //
+
 #include <FL/Fl.H>
 #include <FL/Fl_Double_Window.H>
 #include <FL/Fl_Menu_Bar.H>
@@ -90,13 +91,13 @@ static Fl_Pixmap L_redx_pixmap(L_redx_xpm);
 void Menu_CB(Fl_Widget *w, void* data) {
   const char *itemname = (const char*)data;   // "New", "Open", etc
   if ( strcmp(itemname, "Quit") == 0 ) {      // handle Quit
-    exit(0);
+    w->window()->hide();
   } else {                                    // just show a message for other items
     fl_message("'%s' would happen here", itemname);
   }
 }
 
-// ADD AN IMAGE IN FRONT OF ITEM'S TEXT
+// Add an image in front of item's text
 int AddItemToMenu(Fl_Menu_   *menu,                   // menu to add item to
                  const char  *labeltext,              // label text
                  int         shortcut,                // shortcut (e.g. FL_COMMAND+'a')
@@ -137,7 +138,7 @@ int AddItemToMenu(Fl_Menu_   *menu,                   // menu to add item to
 //
 void CreateMenuItems(Fl_Menu_* menu) {
 
-  // Add items with LABLES AND IMAGES using Fl_Multi_Label..
+  // Add items with LABELS AND IMAGES using Fl_Multi_Label..
   AddItemToMenu(menu, "File/New",  FL_COMMAND+'n', Menu_CB, (void*)"New",  &L_document_pixmap);
   AddItemToMenu(menu, "File/Open", FL_COMMAND+'o', Menu_CB, (void*)"Open", &L_folder_pixmap, FL_MENU_DIVIDER);
   AddItemToMenu(menu, "File/Quit", FL_COMMAND+'q', Menu_CB, (void*)"Quit", &L_redx_pixmap);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.