Click here to Skip to main content
15,867,835 members
Articles / Programming Languages / C++

Comment/Uncomment Macro .NET

Rate me:
Please Sign up or sign in to vote.
3.25/5 (4 votes)
22 Aug 2006CPOL3 min read 32.2K   211   11   1
Macros for Visual Studio .NET to simplify the commenting of code.

Introduction

These macros provide a quick way to comment/uncomment a block of code, add a header to a function, and set the layout of a file for VS.NET. With a single click (or key press), a line or a number of lines can be commented or uncommented. With a single click to a highlighted function declaration, a header will be provided giving details of the author, the date it was created, and a description. With a single click, a new .c/.cc/.cpp/.h/.hpp file will be given a standard layout. The layout consists of copyright information, description of the file, and sections for defines, globals, prototypes, header files etc.

The macros are easy to customise, thusly tailored to everybody's unique coding style.

Background

There seems to be a few comment/uncomment macros for MS VC++6 already out there but none seem to handle the file layout or provide an easy way to write a header for a function. However, there seems to be no such macros for VS.NET (or MS VC++ 7 +).

Using the code

The first thing to do is install it. Download the .zip file and extract the contents to wherever you like. I would suggest unzipping to "C:\Program Files\Microsoft Visual Studio 8\VC\VSMacros80". Next, load the macro file into the workspace: Tools->Macros->Load Macro Project. To make the use of these macros easier, I advise creating a new toolbar with these commands on: Tools->Customize->New. Give it a name, e.g., "Comment Helper". Next, click on the Command tab of the open dialog, scroll down to Macros, and scroll down to the bottom of the Commands pane, and choose the four "Macros.CommentHelper" functions:

Loading the macros

Make sure to save your workspace. Assign accelerator keys if you like. The macros are now loaded and easily accessible.

Simply place the cursor on any line and press the Comment Out button, or select several lines and press the button. Hey presto, they are commented out.

Simply place the cursor on any line and press the Comment In button, or select several lines and press the button. Hey presto, they are commented in. The macros will not comment in lines that are not commented out.

Open a new .c/.cc/.cpp/.h/.hpp file, and press the SetFileLayout button, hey presto, instant file layout occurs:

File layout macro

Lastly, adding a header to a function. Double click a function's name in its declaration:

Image 3

Press the AddFunctionHeader button. Enter a description of the function's purpose, and you're done...

Image 4

Points of interest

The code was written with extensibility in mind, and whilst it's far from perfect, it should be easy enough to extend the functions and also modify them to cater for anyone's unique coding style habits.

I had planned on adding the C multi-line style comments, but decided against it on the fact that when these lines are viewed in the Find text pane, it is not clear whether the lines are commented or not. But if each line is commented out with C++ single line comments, then it is very obvious the line is commented out!

History

  • 20th August 2006: Submitted to CodeProject for submission. Currently only supports .c/.cc/.cpp/.h/.hpp files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionError Pin
Carbuncle61915-Feb-07 23:49
Carbuncle61915-Feb-07 23:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.