Ok, this is one of those posts that are more just to document something so the next time I install VS on a computer I remember how to do this and can find the file.
If you don’t use Visual Studio C++ then you should run. Or, prepare to dive into the incredibly boring world of the lengths programmers will go to just to avoid monotonous typing.
I’m all about classes. When you think of classy, think of me. Any time I do anything, I need a .cpp and.h file for it. And I want ’em setup pretty with the current date and stuff. Automagically!
For years I used custom macros I’d made for Visual Assist, but at $279 + $119 yearly it’s a bit hard to continue to justify using VA when VS 2022 has most of its features built in these days.
Yes, you can pay less but rules like the payment “Cannot be reimbursed by a company or organization” and the world’s most annoying licensing system makes it not worth it.
So what’s a lad to do? Well, I finally got off my bum (well, on it, I guess) and learned how to have the same macros with built-in features that VS has had forever. They work a tiny bit different but close enough.
Hint: Don’t even try to use the “Snippets” feature to do this, it won’t work.
How to add
Download this file and place it in your %USERPROFILE%\Documents\Visual Studio 2022\Templates\ItemTemplates\Visual C++ dir.
(or %USERPROFILE%\Documents\Visual Studio 2019\Templates if you’re using VS 2019… I think)
DON’T UNZIP! VS reads it as a zip.
Close and restart Visual Studio.
Then add new classes using the “Add item” menu. Like this shittily produced unlisted video shows: (can you guess the music I used? Why did this even need music? Are you wondering what youtube video I was watching?)
How to change it
Great! Ok, but you probably wanted to customize it with your own name and not give me credit to everything you make. Well, fine, if you must.
To modify it with your own name/email/texts, just unzip the file you downloaded, you’ll see four files inside. Delete the original .zip. (you’ll make your own in a sec)
Edit the .cpp and .h as you like, then zip the four files up again. (I don’t think the name matters, it just has to be in the same directory as before) Restart VS and you should see the changes.
When editing, there are many special words you can use that get replaced automatically (full list here).
Some useful ones:
- $safeitemname$ – (current filename without the .cpp or .h part)
- $projectname$ – The name of the project this is in
- $year$ – Current year (ie, 2022)
- $time$ – The current time in the format DD/MM/YYYY 00:00:00
- $username$ – The current user name
- $registeredorganization$ – The registry key value from HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization
Hint: Edit the MyTemplate.vstemplate file to change the name and some other things. Useful if you want multiple templates, one for component classes, etc.
And that’s it! Suck it, Visual Assist. But also I love you so please get cheaper and less annoying to buy & license.