// msgnew.cpp

// An MFC, App/Windows program that processes mouse and keyboard character messages

#include <afxwin.h>
#include <string.h>
#include "msgnew.h"
 

// Our CMainWin class definition

// 1. CMainWin's constructor--creates the window
CMainWin::CMainWin()
{
  RECT r;
  r.left = r.top = 10;
  r.right = 500; r.bottom = 250;
  Create(NULL, "Processing mouse messages", WS_OVERLAPPEDWINDOW, r);
}
 

// 2. CMainWin's message map
BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd)
  ON_WM_CHAR()
  ON_WM_LBUTTONDOWN()
  ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
 

// 3. CMainWin's message-processing handler functions--

// WM_CHAR message-processing ftn.
void CMainWin::OnChar(UINT ch, UINT count, UINT flags)
{
  char str[]="     ";
  CDC* pDC;
  pDC = this->GetDC();
  wsprintf(str, "%c   ", ch);
  pDC->TextOut(1,1,str,lstrlen(str));
}

// Left mouse button-processing message ftn.
void CMainWin::OnLButtonDown(UINT flags, CPoint loc)
{
  CDC* pDC;
  pDC = this->GetDC();
  pDC->TextOut(loc.x, loc.y,"L",1);
}

// Right mouse button-processing message ftn.
void CMainWin::OnRButtonDown(UINT flags, CPoint loc)
{
  CDC* pDC;
  pDC = this->GetDC();
  pDC->TextOut(loc.x, loc.y,"R",1);
}
 

// 4. Our CApp class function definitions
// Initialize the application (InitInstance() override)
BOOL CApp::InitInstance()
{
  m_pMainWnd = new CMainWin;
  m_pMainWnd->ShowWindow(m_nCmdShow);
  m_pMainWnd->UpdateWindow();
  return TRUE;
}
 

// 5.Instantiate the application
CApp App;