Course list http://www.c-jump.com/bcc/

Lab 20: FLTK Menu classes


  1. Description
  2. Copying Visual Studio Project
  3. Adding a menu bar in FLUID
  4. Adding menu callback functions
  5. How to submit

Description



Copying Visual Studio Project



Adding a menu bar in FLUID


  1. Start FLUID program and open project

    
        c255labs\labs\c255_lab20_menu\fluid_project\CFluidWindow.fl
    
    
  2. Select Window win_app object in the tree view.

  3. To add a menu bar, a menu, and the menu items, use FLUID menus

    
        New/Menus/Menu_Bar...
        New/Menus/Submenu... -- name your submenu "File"
        New/Menus/MenuIem... -- name your submenu item "Save"
        New/Menus/MenuIem... -- name your submenu item "Load"
        New/Menus/MenuIem... -- name your submenu item "Quit"
    
    

    (You can also click on the window designer, then right-click and choose same options from the context menu.)

    If menu bar appears in the window as a small rectangle, drag it to the top of the window and resize to fit accross the top.

    When a submenu is added to the menu bar, its properties window is displayed. Switch to the properties/GUI tab and change the label text.

    Switch to the Properties/C++ tab and name the menu items as

    
        menu_save
        menu_load
        menu_quit
    
    

    Note that a submenu is added by selecting the menu bar, and the menu items are added when the correspecting submenu object is selected.

    Alternatively, you can duplicate the existing menu item in the project tree by selecting it and then hitting CTRL+C, CTRL+V to copy and paste the new item. Double-click the item to display and update its properties.

  4. Save FLUID project and generate C++ code by

    
        File/Write Code...
    
    

     


Adding menu callback functions


  1. Open solution

    
        c255labs\labs\c255_lab20_menu\c255_lab20.sln
    
    

    in Visual Studio.

  2. Download the new versions of

  3. Compile and test the program.

  4. Use WinMerge to compare the old and the new versions of CMainWindow.h. Notice new callback functions for "Load" and "Save". There are two new #includes in support of the standard file chooser dialog:

    
        #include <string>
        #include <FL/Fl_Native_File_Chooser.H>
    
    

    There is also a new global function declaration at the end of the file:

    
        std::string select_file( std::string prompt );
    
    
  5. Compare the old and the new versions of CMainWindow.cpp:

     


How to submit