在VS2005上使用C++开发遇到的一个问题:通过MFC添加消息/事件,产生错误提示"无法执行添加/移除操作,因为代码元素是只读的"。

查了很多资料,也试了很多办法,都解决不了。目前只能通过手动添加,这实在不是好办法。 

下面是网上收集的解决办法,我一一试过,都不行,因人而异吧。

解决方案:
1、重启VC/VS2005;

2、打开Resource.h文件看看,有些定义重复了,可以手动改掉,保存,编辑器重新加载;

3、关闭解决方案,删除ncb文件重新添加即可;

4、实在不行就手动添加消息处理;

5、查看.h和.cpp文件的属性,有可能是只读的,修改属性后就可以了;

6、把你要添加事件的对话框相应的类文件(*.h和*.cpp)给关了就可以了;  

下面一段解决办法引用自http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105469

1、 Check out the whole original project from source control
2、 Copy the project to a new directory
3、 Clean it entirely (remove ncb, aps, intermediate directories)
4、 Remove all source control references - *.scc, *.vspscc files
5、 Edit the vcproj file in a text editor and remove Scc references:
     In my file the lines looked like:
     SccProjectName="SAK"
     SccAuxPath="SAK"
     SccLocalPath="SAK"
     SccProvider="SAK"
     Sometimes there are paths here instead of "SAK"
6、 Open the cleaned project, but don't build (don't know if this has any effect)
7、 Dialogs were now showing Control Handlers and I could add new ones
8、 Add all handlers needed (I didn't bother with filling them out)
9、 Do a diff on the directories and copy changed files back to the original location. 

有人说这是VS的bug, MicroSoft说在SP1已经解决,但是有人说还是有问题,在VS2008也会出现这个问题,至今没有统一的办法,根本原因也不明,可说是VS的瑕疵。

更多信息请参考http://forums.msdn.microsoft.com/en-US/vcgeneral/thread/0aa8e651-85cd-4e47-8718-ca45dcd64481/

Posted on 2008-09-02 23:47  奔波在路上  阅读(1095)  评论(0编辑  收藏  举报