Click here to Skip to main content
Click here to Skip to main content

"ClassWizard" in VS.NET 2003

By , 29 May 2003
 

Introduction

Visual Studio .NET 2003 brings a lot of enhancements but I sometimes miss the good ol' VC6 Class Wizard. Especially when I want to override say OnInitDialog in a CDialog derived class I find it painful to switch to the Class View, find my class in the list and finally right-click to get the Properties. So if you are like me this macro is for you!

How it works

You can use the macro from a .h or a .cpp file. If called from a .cpp file then the macro switches to the corresponding .h file. Then it searches for:

class <Whatever> 
{

If you are used to put the curly brace on the same line as your class declaration then you might have to change the DTE.Find.FindWhat line and remove the\n in it (see code below).

It then closes the Find dialog, synchronizes the Class View with your class and displays the Properties window. You can then click on Events/Messages/Overrides and select the function you wish to override.

Of course I mapped this to Ctrl+W!

The Macro

And here is the code!

Sub ClassWizard()

    Dim a, b As String
    a = DTE.ActiveDocument.FullName()
    tmp = InStr(a, ".cpp")
    If tmp Then
        b = Left(a, Len(a) - 3) + "h"
        DTE.Documents.Open(b, "Text")
    End If

    DTE.ActiveDocument.Selection.StartOfDocument()
    DTE.ExecuteCommand("Edit.Find")
    DTE.Find.FindWhat = "class .*\n\{"
    DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
    DTE.Find.Execute()
    DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()
    
    DTE.ExecuteCommand("View.SynchronizeClassView")
    DTE.ExecuteCommand("View.PropertiesWindow")

End Sub

License

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

About the Author

Nicolas Bonamy
Team Leader
France France
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralEhhhhmemberTak31 May '03 - 1:54 
Did you ever press F4? WTF | :WTF:
GeneralRe: EhhhhmemberNicolas Bonamy31 May '03 - 10:43 
Hi,
 
maybe I missed something in VS.NET 2003 (highly possible) but sorry because on my setup F4 does not do anything. Did you map it to a a function?
 
Regards
GeneralRe: EhhhhmemberTak31 May '03 - 10:52 
Well, I don't have V7.1 yet, but I suppose the F4 function is not gone (it simply does what your macro does, but without the search etc. - way better).
 
I have not explicitly mapped it, but it's more than possible that you have a different keymapping than me. It's mapped to "View.PropertiesWindow"... you should try this, really.
GeneralRe: EhhhhmemberNicolas Bonamy31 May '03 - 20:49 
Tak,
 
I think you have not read what the macros does exactly. If you are in the midlle of a .cpp file and you display the properties window (with F4 or Alt+Enter or whatever) then you are not able to see for example the Events tab where you can ad handlers for the WM_ messages in your dialog/view/frame... This is what the macro does: when you run it the Events/Messages/Overrides buttons do appear and you can go on with your overriding.
 
Regards,
nabocorp
GeneralRe: EhhhhmemberTak1 Jun '03 - 2:43 
Well, you are totally wrong here. I fully read the article and I also got the idea of it, but F4 DOES exactly this. It doesn't matter where you are in the file.
GeneralRe: EhhhhmemberNicolas Bonamy1 Jun '03 - 3:01 
Okay Tak you are surely right. The only thing I know is that it does not work this way in my setup of VS.NET 2003 so I need this macro. It seems that at least 3 other people found the macro useful...
 
Regards,
Nicolas
GeneralRe: EhhhhmemberTak1 Jun '03 - 3:48 
Maybe it's a bug in VS.NET 2003 (as I said, I have 2002). I only can say that pressing F4 does the same as this macro, with all those buttons enabled so I can add message handlers etc.
GeneralRe: EhhhhsussdEUs[CPP]14 Jun '03 - 11:15 
Alt + Enter works at my installation of 2003 ...

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 30 May 2003
Article Copyright 2003 by Nicolas Bonamy
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid