ClassWizard: Special-Format Comment Sections

OverviewHow Do I

This article explains where and how ClassWizard edits your source files.

When you add a new class using ClassWizard, special-format comments are placed in your code to mark the sections of the header and implementation files that ClassWizard edits. ClassWizard never modifies code that is outside these commented sections.

ClassWizard creates the following types of comments in your code:

  • Message-Map Comments

  • Virtual Function Comments

  • Data Map Comments

  • Field Map Comments

  • Active Dispatch Map Comments

Message-Map Comments

For most classes, there are two related sections of code that ClassWizard edits: the member-function definitions in the class header file and the message-map entries in the class implementation file.

The ClassWizard comments in the header file look like this:

//{{AFX_MSG(<classname>)
  afx_msg void OnAppAbout();
//}}AFX_MSG

The ClassWizard section in the implementation file is set off with comments that look like this:

//{{AFX_MSG_MAP(<classname>)
  ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
//}}AFX_MSG_MAP

The notes in the ClassWizard section act as placeholders. ClassWizard removes the note from any ClassWizard section in which it writes code.

Virtual Function Comments

As with message handlers, ClassWizard writes code to two locations when you use it to override a virtual function in one of your classes.

The ClassWizard comments in the header file look like the following example for virtual function overrides:

//{{AFX_VIRTUAL(<classname>)
  virtual BOOL InitInstance();
//}}AFX_VIRTUAL

The ClassWizard section in the implementation file has no special comments. Virtual function definitions in the .cpp file look like other function definitions.

Data Map Comments

For dialog boxes, form views, and record views, ClassWizard creates and edits three other sections that are marked with special format comments:

  • Member variable declarations in the class header file:

    //{{AFX_DATA
    ..
    //}}AFX_DATA
    
  • Member variable initialization in the class implementation file:

    //{{AFX_DATA_INIT
    ..
    //}}AFX_DATA_INIT
    
  • Data-exchange macros in the implementation file:

    //{{AFX_DATA_MAP
    ..
    //}}AFX_DATA_MAP
    

Field Map Comments

For record field exchange, ClassWizard creates and edits three other sections that are marked with special format comments:

  • Member variable declarations in the class header file:

    //{{AFX_FIELD
    ..
    //}}AFX_FIELD
    
  • Record exchange function calls in the implementation file:

    //{{AFX_FIELD_MAP
    ..
    //}}AFX_FIELD_MAP
    
  • Member variable initializations in the class header file:

    //{{AFX_FIELD_INIT
    ..
    //}}AFX_FIELD_INIT
    

Active Dispatch Map Comments

For Active method dispatch, ClassWizard creates and edits four other sections that are marked with special format comments:

  • Active events in the class header file:

    //{{AFX_EVENT
    ..
    //}}AFX_EVENT
    
  • Active events in the class implementation file:

    //{{AFX_EVENT_MAP
    ..
    //}}AFX_EVENT_MAP
    
  • Automation declarations in the class header file:

    //{{AFX_DISP
    ..
    //}}AFX_DISP
    
  • Automation mapping in the class implementation file:

    //{{AFX_DISP_MAP
    ..
    //}}AFX_DISP_MAP
    

For more information see Working with Dialog Box Data.