Error message in MFC / RC on VS2008 - the "Add / Remove" operation is not possible because the code element "Cxxxx" is read-only "

I searched on the Internet and get conflicting answers that cannot solve the problem for me. I created a dialog box and then clicked it to create a class for me. Unfortunately, he poorly named the class and file, so I renamed the file. Now the visual studio will not allow me to do anything through gui for the dlg resource - for example, to connect a button even for a handler, etc. I get a message box:

"It is not possible to add / remove an operation because the code element" Cxxxx "is read-only"

This is a real problem, because adding handlers and things manually through code is tedious, and one of the developers simply cannot do this - he needs a graphical interface for managing events.

I tried deleting the ncb file and rebuilding the project, but no luck. MS did not seem to fix this problem after 4 years or so (based on searches I saw on the Internet.

I cannot add variables, event handlers, or anything else useful with the MFC gui application wizard. I can only do this by editing the cpp and h files.

Does anyone have any suggestions?

+7
source share
7 answers

I added existing files to the VS2008 project and there was a problem. I fixed it by deleting the .suo file and recompiling the solution.

Perhaps this helps someone who is facing this problem.

+4
source

I was able (accidentally) to reproduce the same problem. I defined DECLARE_EVENTSINK_MAP() and the full

 BEGIN_EVENTSINK_MAP(CDlgMessage, CDialog) ON_EVENT(CDlgMessage, IDC_GM_VIEW1, 1, CDlgMessage::GMEventGmView1, VTS_I2 VTS_BSTR VTS_BSTR) END_EVENTSINK_MAP() 

and I manually deleted the entire BEGIN-END section, but I left DECLARE undeleted. When I later tried to add an event handler with a graphical interface, I got the mentioned answer. Just removing the DECLARED part solved the problem.

I believe that this can be copied to all such problems.

Srjan

+2
source

I know this can wait a bit, but have you renamed this class too? If so, you may have forgotten to rename

 DECLARE_DYNAMIC(RandomClass, CDialog/alternative) 

and

 IMPLEMENT_DYNAMIC(RandomClass) 

The documentation for these calls is not very thorough, but when I tried to create a class to which I could add an event, I got a similar error when trying to add an event to this class:

http://msdn.microsoft.com/en-us/library/ywz9k63y%28v=vs.90%29.aspx

+1
source

How I fixed it (deleting .ncb / .suo / .user files and rebuilds did not help) ...

I noticed the following feature when this error occurred in my VS 2008 project:

  • This happened in one dialogue + class, and not in others.
  • In the .cpp class file for the broken dialog box in the area selector there is only the "(Global Scope)" element, there were no other lines (there was no expected class).
  • I also checked the .h class file and visibility selector. OK.

I first fixed this problem in # 2 (explained below), then VS came out, deleted the * .ncb, * .suo files, restarted VS, rebuilt the project, and the wizards started working again.

To fix the visibility selector issue in # 2, I first narrowed it down to headers not included in the class .h file, i.e. I had some types used inside the class declaration, but not a single heading in the .h file that declared these types. Therefore, if I included the .h file in a clean .cpp file, it would not compile. The rest of the project was compiled because all the necessary files were added to all the corresponding .cpp files before the .h class. After I added all the necessary headers to the beginning of the .h class (this will compile a clean .cpp file), the area selector in the .cpp file is correctly inserted and, in turn, the wizard corrected.

On the side: there is a school of thought to not include any other .h files in any of the .h files, and Microsoft seems to follow this path quite often (fortunately, not always). I usually follow various inclusion rules - always include the headers with all the used ads in the .h file, so when I need to use the module, I only need to include its .h file. In the rare case when I didn’t do this, VS wizard clogged (or IntelliSense was clogged by this wizard). This makes my attachment to this inclusion policy stronger. The only exception to this policy is not to place stdafx.h, windows, and MFC files in a .h file. This is done differently due to precompiled headers.

+1
source

Just FYI, which I faced the same problem in Visual Studio 2010 SP1.

Deleting the SDF file (equivalent to previous versions of Visual Studio 2010 NCB) resolves the issue.

(At first I tried many other things, including cleaning up the project and rebuilding, deleting the .suo file, etc., but to no avail. However, I did not know whether these actions were necessary in ADDITION to permanently delete the SDF file.)

+1
source

Delete .ncb file with solution. rebuild also worked on Visual Studio 2008. I must mention that I started to encounter this problem after transferring my code to a new PC.

0
source

I had the same problem with VS2005. I tried to remove * .ncb and * .suo, but to no avail.

In the end, I just need to close the file, which is the complaint (because it opens, VS cannot automatically add new code to the file when we perform some actions with GUI resources, such as adding an event handler to the menu item).

0
source

All Articles