开发者

Can't add event handler in visual studio 2010 (mfc project)

开发者 https://www.devze.com 2023-01-15 21:58 出处:网络
I\'ve recently converted an MFC visual studio 6.0 project to a visual studio 2010 project and I\'m experiencing problems whenever I try to add event handlers to controls on certain forms within my pro

I've recently converted an MFC visual studio 6.0 project to a visual studio 2010 project and I'm experiencing problems whenever I try to add event handlers to controls on certain forms within my project. On one particular page I have a radio button and I've tried to add a click event handler to it using 3 different ways:

1) By right clicking on the radio button and clicking "Add Event Handler". This method results in no error messages but it does not create the event handler. It just closes the Event Handler Wizard out with no messages of any kind.

2) By right clicking on the radio button and clicking properties. In the properties window I click the events window (lightning bolt button). I then navigate to the click event and hit add handler. This method produces an error message window that says "Property value is not valid" and the details of this error message in the box below say "Catastrophic failure".

3) By adding the event handler through the class wizard. This results in the same results as described in number 1 above.

Notes about my project:

1) Running Windows XP SP3

2) N开发者_Python百科ot all forms have this problem. On some forms I can add event handlers fine.

3) Whenever I receive the "Property value is not valid" error message this also breaks undo/redo functionality

4) Project contains FarPoint ActiveX controls


Check that an MFC class has been added for the problematic forms. I've had the VS2010 'Add variable...' wizard fail silently for controls where the parent form did not already have an associated class, so the same may be true for event handlers.


I had and still have the same issue in a project. I renamed everything to a new name. Not sure if this is what caused the issue but I haven't been able to fix it. Add Event Handler fails silently for me despite having the right class. What I ended up doing was copying the event handling code that was needed, which requires 3 pieces:

1) A function to handle the message declared public in the class

afx_msg void OnBnClickedSaveTButton();

2) The implementation of that function:

void CExampleDlg::OnBnClickedSaveTButton()
{
}

3) The connection of the event handler message in the Message Map after the

BEGIN_MESSAGE_MAP(CExampleDlg, CDialogEx)
// Other mappings here

ON_BN_CLICKED(IDC_SAVE_TO_DISK_RADIO, &CExampleDlg::OnBnClickedSaveTButton)

END_MESSAGE_MAP()

You can get the IDC name from the dialog editor. All this works like a charm, although it takes a bit longer than the Add Event handler wizard.


That's because intellisense or its database is disable. I encountered this recently. Check these options, should be:

IDE Tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Disable Database = False

IDE Tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Disable Intellisence = False

IDE Tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Rescan Solution Interval = 0

Open an empty VS IDE, fix the options, and reopen the project, everything should be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号