PAC

OK,

I'm completely baffled. I've been a programmer dating back to MSC version 8 for DOS.

For the past couple years I've mainly stuck to VC6 because the newer interface is just too full of fluff and non-intutitive for my tastes. But I do have three projects which require either VC2003 or the latest and "greatest"

One thing that has caused me to waste the most amount of time believable lately is the simple process of using the form editor in C++ to add a button/control of some time and THEN REMOVE IT CLEANLY when I'm done.

Often times a programmer just wants to drop in a control, do a little test and then delete it once he's tested some code snippet. Same thing goes with a message handler.

In the VC6 days I could just click on a function in the class view and hit my [DEL] button and poof it was gone/commented out.

Now for the life of me I can't figure out how to do the same task in VC7/8 without manually doing a search and deleting lines of code with the editor by hand. With uneditable intellisense, NCB files, CLW files etc. editing my code like this by hand these days seems like a disaster waiting to happen so I'm very reluctant to just chop things happenstance so I want to know the "official proper" way to do it.

There has to be a simple way, but all my searching, reading through books and looking for help files has proved fruitless to this point.

Anyone know a simple answer to a simple problem




Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Nishant Sivakumar

Unfortunately, due to the IDE unification (C#, VB and C++ all use the same core IDE), some handy C++ specific IDE features got lost in the 2003/2005 releases. Your best option would be to purchase a 3rd party IDE enhancement product like Whole Tomato's Visual Assist - which should bring back a lot of sanity to the VC++ programming environment.

The next release (Orcas) has quite a few improvements for C++ - but that's still an year away. But it's a good thought to have for now :-)






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

PAC

I never looked into a third party too. I'll give Visual assist a look.

Sadly though, I've been hearing the "just wait, we'll get around to that in the next release" ever since MS shipped VS2003 with no form editor for C++.

I tend not to believe it any more. I think the real goal is to let C++ whither and die on the vine so they can try and convince everyone to buy C#, VB and Java stuff.

That's why I still do whatever I can with VC6. Thanks for the reply FWIW Smile






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Simple Samples

I have also used Microsoft C since before VC; I think I started before version 8 of C. VC 2005 is confusing and such in some ways. Your comments however are too general. If you just want to express frustration then you have done that. If you are asking a question then it is not clear to me what you are asking. There is however a page in the VC 2005 documentation for users of prior bersions of VC that explains how to do a few things the new way ; have you seen that






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

PAC

My comments are too general

Ok, I'll be specific, I thought I was.

Open a formview app, or Dialog applciation in VC2005.

Add a button...call it "Test" and give it a resource ID of ID_TEST

Double Click the button and you can add a handler for it. VC2005 adds a functions called OnTest() where you can now add code.

Now, this was just a test. My testing is done. I want to delete this button, the function and all remnants that it ever existed so my app is clean again. Or maybe I want to call it a different name, so I'll create a new one with a better name, copy my code and now I want to get rid of the old one.

HOW DO YOU DO THAT I could do it with VC6 through the ClassWizard by selecting OnTest() and hitting the <del> key, or right-clicking and selecting delete from the popup menu.

I've looked through the MSDN documentation, I've googled it, been a longtime member of ProgrammersHaven, CodeGuru and CodeProject and I haven't been able to figure out how to do this.

If I sound frustrated it's because I've spent a good bit of time trying to figure it out and haven't found anything and since this is such a simple basic need (after all, if you can ADD something, shouldn't you be able to just as easily DELETE something ).

Yes, I have gone through and deleted code by hand, and I hope I got all the references, but with the various entries VC2005 puts in Intellisense, browser files, resource files, message maps, etc. it's very difficult to know if I got it all.

So if you want specifics then there it is. If you know what page of the VC2005 documentation that is on, I'm all eyes.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Software Monkey

Hi,

I share your frustrations about doing this apparently simple task. The thread has gone quiet, did you ever figure out how to do this

After a few days working with Visual Studio 2005 I have decided to revert back to MSDEV6 because it is taking too long to get used to. I simply dont have the time to spare. It looks to me as if Microsoft have deliberately changed as much as possible so that it looks new and interesting.





Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

MI-CHI

I have the same problem. They simply managed to drop the good stuff.

In addition, the code added with the new Wizards is horrible, they just add "public/protected/private" and the variable at the end of the class declaration, without any comment that it was added by the wizard and disregarding whether there is already any section containing the publics/protecteds/privates. It even adds them if the last section was the same access specifier. Due to that fact, it seems virtually impossible to handle deletion, as the automatically added code cannot be identified later.

However, without going too deep into detail, I am still using VC6 to *edit* (add, change, delete) members, messages and anything the ClassWizard could do. Note that compilation, code edit and all the rest is still done in VS 2005.

To do so, there are two cases:
If you started the project with VC6 and converted it to VS 2005, the ClassWizard sections are already present and there is no problem.

If you do this with a VS 2005 project, it's a bit more difficult:
First, you need to create a new and empty project with VC6 in another folder but with the same settings (e.g. base class names and project name). Then remove the project files and more the DSW/DSP file to the VS 2005 project folder. Open it from there with VC6 and add the VS 2005 source files.

Now comes the tricky part:
In order for the ClassWizard to work, the "//{{AFX_..." sections must be added. The easiest way to add them is to look into an empty VC6 project and insert them at the corresponding places in the VS 2005 project (in the dialog's class .H and .CPP files to be exact). Just copy and paste from the empty project.
A basic scenario in a simple MFC dialog application is:
----------------------snip----------------------
Header file:
->add //{{AFX_DATA(CMyClassDlg)
enum { IDD = IDD_MYCLASS_DIALOG };
->add //}}AFX_DATA

->add //{{AFX_VIRTUAL(CMyClassDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
->add //}}AFX_VIRTUAL

// Generated message map functions
->add //{{AFX_MSG(CMyClassDlg)
virtual BOOL OnInitDialog();
->add //}}AFX_MSG
DECLARE_MESSAGE_MAP()

CPP file:
[in constructor]
->add //{{AFX_DATA_INIT(CMyClassDlg)
->add // NOTE: the ClassWizard will add member initialization here
->add //}}AFX_DATA_INIT

[similar in DoDataExchange()]

BEGIN_MESSAGE_MAP(CMyClassDlg, CDialog)
->add //{{AFX_MSG_MAP(CMyClassDlg)
->add //}}AFX_MSG_MAP
END_MESSAGE_MAP()
----------------------snap----------------------

The details may vary depending on the project, but that shouldn't be a problem for you.

Then launch the Class Wizard and it will ask you to build the CLW file from the sources. Just click on OK.
If there comes an error message indicating that a header file or something similar could not be found, click "No" to abort the CLW file creation. In most cases, some of the class names inside the brackets differ from your base class, correct it and launch ClassWizard again until no errors appear. Then you are ready to go.

Keep in mind that it is recommended to close the project in VS 2005 in the meanwhile to be sure that not two IDEs are accessing the same (re)source files.

Works perfect for me... All the good libraries (STL!) and less bugged intellisense of VS 2005, and the ease of VC6's ClassWizard.

Regards,
MI-CHI




Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

PAC

Wow MI-CHI,

That is a really clever idea. I mean it truly! I honestly never considered trying that. On the one hand it may seem a bit clumsy to add all the AFX... entries, but I've only got about 200 various codebases I've worked over the years to cut and paste from.

Now that I think about it a little there are very few controls that MS has added to the toolbox since VC6, so...why not

I'm going to give this a try.

Thanks for the tip

PAC






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

PAC

Nope, I spent quite a few days seraching google, codeguru, MS knowledgebase, MSDev...you name it and I never did find a way to do it from inside VS2005. It became clear that the resounding silence on the issue is because the ability flat out...doesn't exist.

Everywhere I asked all I got was a bunch of "huh Why would you want to do that " answers. Either that or nonsensical replies like the one above that just want to label me an an MS bashe (I won't hesitate to bash MS when they deserve it, but I do make my living using their products so I figure I have a right).

MI-CHI had a pretty clever idea below. Check it out. I've only been silent because this thread has basically been passed over by everyone else. But I still fight this "bug" daily.

I will say this for 2005...the intellisense breaks less often. That's about the only thing I can think of over VC6 though.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Simple Samples

PAC wrote:

In the VC6 days I could just click on a function in the class view and hit my [DEL] button and poof it was gone/commented out.

That is incorrect. In VC 6 when we remove a handler, it shows a message box telling us we must delete the code. It removes the function from the header but it does nothing with the body. If a handler is added and then immediately deleted then the body will still be there.

I am not sure about VC 2005, but I am nearly certain that it will comment out the body. It does not remove the body entirely and I think people would complain if it did. Would you be forgiving if VC deleted code that you did not intend to delete; what if you make a simple mistake and delete a handler you did not intend to delete and then the code is gone If you catch the problem immediately you can probably undo the change but if you don't realize the mistake soon enough you could be out of luck and then you would be complaining even louder.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

PAC

In your own words..."That is INCORRECT"

Before you point out my mistakes you should do a little research. There is no way to delete a handler in VC2005 C/C++. If there is a way, it's not located anywhere in the help files, documentation, menus or toolbars. Not only that, no one on these forums has found one either (if they have, they are keeping it to themself).

Furthermore, you are only partially correct in your "correction". VC6 does a lot more than delete the function from the header. It also removes the MFC handlers that manage the message mapping, which is the most important part, after all.

VC6 doesn't actually delete the body of the function, but it DOES add

//DEL

Before every line in your newly deleted function and it even goes so far as to select the body too so one more press of the [del] key finishes the process. This is better than deleting it because it gives you one last chance to "save the code" if you want to use it elsewhere.

Isn't it lovely when people are so quick to point out mistakes by others in such a sloppy manner

But basically you just plain miss the point entirely. If you are using MFC and add a handler, there are more entries than just the function prototype and the body. Deleting those other more obtruse entries is just as important and since the code wizard put that stuff there in the first place, it's only logical that the code wizard should give us a way to remove it and "clean up after itself".






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Simple Samples

PAC wrote:
HOW DO YOU DO THAT I could do it with VC6 through the ClassWizard by selecting OnTest() and hitting the <del> key, or right-clicking and selecting delete from the popup menu.

Right-click the button then select properties. In the top of the properties box is a Control Events button that has a lightning bolt icon; click it. The BN_CLICKED event will have the event function name on the right. In the drop-down for that is the command to delete the function. When the function is deleted, the body is commented out but not removed.

I don't know why I did not answer this before. This probably would have been answered by someone else if the question had not been marked as answered.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Simple Samples

PAC wrote:
Before you point out my mistakes you should do a little research.

I am trying to help you. It is not my intent to make you wrong.

PAC wrote:
There is no way to delete a handler in VC2005 C/C++. If there is a way, it's not located anywhere in the help files, documentation, menus or toolbars. Not only that, no one on these forums has found one either (if they have, they are keeping it to themself).

See Adding Event Handlers for Dialog Box Controls. It does not mention deletion of controls, but I think it gets close enough to how it is done.

PAC wrote:
Furthermore, you are only partially correct in your "correction". VC6 does a lot more than delete the function from the header. It also removes the MFC handlers that manage the message mapping, which is the most important part, after all.

If I said that VC 6 only deletes the function from the header then yes that is incorrect. I only said however that the body of the function is not deleted; I said nothing about the message map entry.

PAC wrote:
VC6 doesn't actually delete the body of the function, but it DOES add

//DEL

Before every line in your newly deleted function and it even goes so far as to select the body too so one more press of the [del] key finishes the process. This is better than deleting it because it gives you one last chance to "save the code" if you want to use it elsewhere.

If that is done for you using VC 6, then look for a macro or add-in that does that for you.

PAC wrote:
Isn't it lovely when people are so quick to point out mistakes by others in such a sloppy manner

If it is something you have overlooked, will you admit your mistake

PAC wrote:
But basically you just plain miss the point entirely.

Here is an important point for you to remember. Most of the questions answered here are answered by volunteers. I get nothing from helping you except the possibility to help.

PAC wrote:
If you are using MFC and add a handler, there are more entries than just the function prototype and the body. Deleting those other more obtruse entries is just as important and since the code wizard put that stuff there in the first place, it's only logical that the code wizard should give us a way to remove it and "clean up after itself".

I have programmed in the day when I had to use a keypunch device to punch holes in cards that had 80 characters per card. I have worked in the day when programmers might get only a few opportunities a day to do a compile and/or test; sometimes only one turnaround a day. Programming is so vastly advanced compared to those days. I appeciate the improvements and I want more. The features you are asking for are there well enough but even if they were not I don't consider that to be such a big inconvenience.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Simple Samples

Nishant Sivakumar wrote:

Unfortunately, due to the IDE unification (C#, VB and C++ all use the same core IDE), some handy C++ specific IDE features got lost in the 2003/2005 releases.

I don't know about VC 2003 but for VC 2005 the features discussed in this thread do exist.






Re: Visual C++ General Is it just me? Deleting handlers and functions w/VC2005 impossible

Royoni

Simple Samples wrote:

PAC wrote:
HOW DO YOU DO THAT I could do it with VC6 through the ClassWizard by selecting OnTest() and hitting the <del> key, or right-clicking and selecting delete from the popup menu.

Right-click the button then select properties. In the top of the properties box is a Control Events button that has a lightning bolt icon; click it. The BN_CLICKED event will have the event function name on the right. In the drop-down for that is the command to delete the function. When the function is deleted, the body is commented out but not removed.

I don't know why I did not answer this before. This probably would have been answered by someone else if the question had not been marked as answered.

I found it and thank you so much!!! Smile