Directly or Indirectly classes is derived from CCmdTarget.
CWnd, CMainFrame, CWinApp, CDocument are all derived from CCmdTarget. CCmdTarget is giving a message mapping functionality in MFC.
Whenever an events occur like pressing a key, mouse click with regards to our application. Message loop is responsible to keep processing any message and sent to the application.
GetMessage() collects the message sent to the application by OS. DispatchMessage() function post the message in a message queue.
Winproc() search message in an array of message map and call appropriate handler by using array entry and processed message.