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

Lab 4: Window class header and implementation file


  1. Description
  2. Copying Visual Studio Project
  3. Making the changes
  4. Adding iostream header in FLUID
  5. How to submit

Description


  • 
    // myclass.h
    
    #ifndef MYCLASS_H_INCLUDED
    #define MYCLASS_H_INCLUDED
    
    // class declaration
    class MyClass {
    public:
        MyClass();
        void f();
    };//class MyClass
    
    #endif // MYCLASS_H_INCLUDED    
    
    
  • 
    // myclass.ccp
    
    // class implementation      
    MyClass::MyClass()
    {
        //...
    }
    void MyClass::f()
    {
        //...
    }
    
    

Copying Visual Studio Project



Making the changes


  1. Rename file CDemoWindow.h as CMainWindow.h

  2. Rename file CDemoWindow class as CMainWindow

  3. To separate CMainWindow declaration and implementation, add new source file named CMainWindow.cpp to the project. Store the new file under the src subdirectory:

    
        c255labs\labs\c255_lab04\src\CMainWindow.cpp
    
    
  4. Open CMainWindow.h in text editor, then copy and paste the following code:

    
    // CMainWindow.h
    
    #ifndef _CMAINWINDOW_H_INCLUDED_
    #define _CMAINWINDOW_H_INCLUDED_
    
    #include "../fluid_project/CFluidWindow.h"
    
    class CMainWindow : public CFluidWindow {
    public:
        void show();
    
        // callback functions
        static void callback_window_closing(Fl_Widget* widg, void* userdata_);
    };//class CMainWindow
    
    #endif // _CMAINWINDOW_H_INCLUDED_
    
    
  5. Open CMainWindow.cpp and paste the following code:

    
    // CMainWindow.cpp
    #include "CMainWindow.h"
    
    void CMainWindow::show()
    {
        // Window callbacks:
        win_app->callback( (Fl_Callback*)CMainWindow::callback_window_closing, (void*)(this) );
    
        // Make the window visible:
        win_app->show();
    }
    
    // callback functions
    void CMainWindow::callback_window_closing(Fl_Widget* widg, void* userdata_) {
        std::cout << "X button clicked -- exiting the program\n";
        while( Fl::first_window() ) {
            Fl::first_window()->hide();
        }
    }
    
    

     


Adding iostream header in FLUID



How to submit