For example, I have a MFC application now. Users can click the user name text field, and then input username. Then user can click password text field, then input password. Then user can click login button. In MFC application, VS 2013 will generated the corresponding callback functions for me, like this:
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedCancel();
Now I expect: When user click "Left button", I can print "left button click" to a log file, when user click "cancel button", I can print "cancel button click" to a log file. I know I can do that in each callback function. like:
void LoginDialog::OnBnClickedOk()
{
printToLog("Left Button click");
}
But the problem is, this application is very large, it has at least hundreds of callback functions. I cannot put this "printToLog" function inside each callback function. Therefore, is there a function which can receive all of these generated windows messages ? If there is a function like this, I can just add my printToLog function in that one callback function. I searched online, https://msdn.microsoft.com/en-us/library/windows/desktop/ms632593(v=vs.85).aspx But the stuff in this link is not what I need. I cannot revise the existing code too much.
You need to overload
PreTranslateMessage()
of your window class. It's a virtual function ofCWnd
.Steps:
Class Wizard
Virtual Functions
tab, and search forPreTranslateMessage
Add Function
button at the right side of the dialogIt looks like: