How to: Enable Block Commenting

Using CTRL+K, CTRL+C, or CTRL+K, CTRL+U in Visual Studio, you can comment or uncomment selected text. To enable block commenting, you need to implement the Service::getCommentFormat method, as described in the following procedure:

To enable block commenting

  1. Open service.h and add a declaration of the getCommentFormat method:

    class Service : public CommentService
    {
    protected:
      override const CommentFormat* getCommentFormat() const; 
      override const ColorInfo*     getColorInfo()     const;
      override const TokenInfo*     getTokenInfo()     const;
    };
    
  2. The method returns a pointer to a CommentFormat structure, which is defined in stdservice.h as follows:

    struct CommentFormat
    {
      const char* lineStart;
      const char* blockStart;
      const char* blockEnd;
      bool useLineComments; 
    };
    

    The lineStart member is the character sequence that starts line comments; set this value to NULL if line comments are not supported. The block comment start and comment end characters are represented by the blockStart and blockEnd members of the structure. Set the useLineCommentsflag to TRUE if line comment characters are preferred to block comments. This is used when the user selects a block of lines, which can be commented using either line or block comments. For example, C++-style comments are defined like this:

    override const CommentFormat* Service::getCommentFormat() const
    {
      static CommentFormat commentFormat =  { "//", "/*", "*/", true  };
      return &commentFormat;
    }
    

See Also

Concepts

Using the Babel Package