The function calls CWnd::GetCurrentMessage()
to retrieve a MSG structure that describes the "current message" (which is only valid "when in an OnMessage handler").
It then compares the hwnd of the button against the hwnd and lParam of the current message to see if the current message orignated from the button.
I can think of a couple of different scenarios where one might use this:
a) You have the same message handler invoked for several different buttons. In which case you might enumerate the buttons and test them to find out the specific one that was invoked.
If you dynamically create new buttons and add them to the toolbar then you can't have a separate handler for all possible buttons, instead you'd have a single handler that did different things based on data associated with the button itself.
b) The same message might be coming from the toolbar, or a menu item or a keyboard shortcut. You want to do the same thing no matter where it came from, but maybe there is some visual cue you want to play depending on if it was the button that was pressed or not.