Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (thousands 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

like image 663
psteiner Avatar asked Apr 29 '26 07:04

psteiner


1 Answers

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.

like image 102
TheSteve Avatar answered May 02 '26 20:05

TheSteve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!