Breaking on a button click event in Visual Studio debugger
This question is regarding the debugger in Visual Studio 2008. I am working on a C++/MFC application with a huge codebase (t开发者_运维技巧housands of .cpp files). I'm looking for a way to tell the debugger, "The next time I click a button in my app, stop at the function called by that button". I'm trying to avoid trolling through those thousands of files to find the function, or the resource for the button. I'd a thought it would be dead simple to trap a button click event with the debugger... but I don't see anything obvious.
Thanks!
Philip
Most MFC buttons will fire a WM_COMMAND message.
If the button's parent window is CWnd based, and you have the MFC source code, you can open cmdtarg.cpp and set a breakpoint in _AfxDispatchCmdMsg. If you step forward in to the switch case, you should be able to step in to the button's handler code.
Because this a trap for WM_COMMAND, this will likely catch more than just buttons, for example menus, so it's not fool proof.
精彩评论