Here are some macros for automating the insertion of function and file comments, the process of installing them is unfortunately a bit long-winded!

Note: these only work with Visual Studio 6.0. Visual Studio .net uses a much more powerful macro system. You can download .net macros and add-ins from the Internet e.g. try The Code Project.

I use these two macros all the time, it saves typing all the comment stuff and means that I never miss commenting a file or function header as it is so easy to insert them. You should always put a comment above your functions!

There are a number of steps, here goes:

Step 1

Note: Make sure visual studio is closed
Download my macro file comments.dsm and place it in the following directory: C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Macros
The directory you use may be in a slightly different place, whatever look for the Macros directory in the visual studio directories.

Step 2

Open visual studio
Go to the menu tool/customize, select the Add-ins and Macro Files tab. Your new macro file comments should be listed. Tick it.

Step 3

The macro is now loaded, you now have to create a toolbar to put it on. Select the toolbars tab this time and you will see a list of available tool bars, Select New... and type a name you want to call this toolbar. Make sure it is ticked.

Step 4

You will now have a small empty toolbar on the screen. Right click it and select Customise. Select the commands tab. Change the category to macros. You will see some macros listed. FileHeaderCpp is the one for putting the comment at the top of a source file and FunctionHeader is the one for putting a comment at the top of a function. Drag them onto the toolbar, it will ask you to select an icon, I use the smilies.

Step 5

You have to edit the macro code to put your name in it. Go to the tools/macro menu and select the macros one by one and click edit. You will see the code for the macro. Put your name in and edit it as you want....

To use the macros just put your cursor where you want it and click the button.

© 2004-2016 Keith Ditchburn