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

Lab 3a: Window closing callback


  1. Description
  2. Copying Visual Studio Project
  3. Adding window-closing callback to CDemoWindow class
  4. Optional: adding window-closing callback using FLUID
  5. Window-closing callback code
  6. Attaching callback to the window
  7. How to submit

Description



Copying Visual Studio Project



Adding window-closing callback to CDemoWindow class



Optional: adding window-closing callback using FLUID


  1. Start FLUID program:

    
        c255labs\external\fluid\fluid.exe
    
    
  2. Open FLUID project:

    
        c255labs\labs\c255_lab03a_win_close\fluid_project\CFluidWindow.fl
    
    
  3. Select Window win_app in the tree view, then double-click on the window to open the properties tab.

  4. Switch to C++ tab and type the callback function name: callback_window_closing (no parameters, just the name alone.)

  5. This callback will be invoked when the user clicks the "X" button to close the window.

  6. Close the properties dialog and select the class CFluidWindow in the FLUID browser tree view.

  7. Use FLUID menu

    
        New/Code/Function-Method
    
    

    and enter the name of the callback function:

        Name(arg): callback_window_closing( Fl_Widget* widg, void* userdata )
    
        Return type: static void
    
  8. Add the callback function body by selecting callback_window_closing in FLUID tree view and then using menu

    
        New/Code/Code...
    
    
  9. Add C++ code:

    
        std::cout << "X button clicked -- exiting the program\n";
        while( Fl::first_window() ) {
            Fl::first_window()->hide();
        }
    
    
  10. For std::cout to compile properly, we must #include <iostream>. Use FLUID menu

    
        Edit/Select None
        New/Code/Declaration...
    
    

    and type

    
        #include <iostream>
    
    
  11. The new #include should be moved to the top of the tree by hitting the F2 key a few times. Keep in mind that you can rearrange the order of items in the FLUID project tree by F2 (up) and F3 (down).

     


Window-closing callback code



Attaching callback to the window



How to submit