MFC Dealing with Keyboard Input

#include <afxwin.h>
class CSimpleApp : public CWinApp
{
public:
BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
public:
CMainFrame();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );
afx_msg void OnPaint();
CString keycode;
CString character;
DECLARE_MESSAGE_MAP()
};
BOOL CSimpleApp::InitInstance(){
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}
CMainFrame::CMainFrame()
{
CRect rect(12,12,500,400);
Create(NULL, "MFC KeyBoard Input",WS_CAPTION| WS_SYSMENU| WS_MAXIMIZEBOX| WS_MINIMIZEBOX);
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_WM_KEYDOWN()
ON_WM_CHAR()
ON_WM_PAINT()
END_MESSAGE_MAP()
CSimpleApp MFCApp1;
afx_msg void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags )
{
CString converti;
converti.Format("%d", nChar);
keycode="keycode "+converti;
}
afx_msg void CMainFrame::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags )
{
CRect clientRect;
AfxGetMainWnd()->GetClientRect(&clientRect);
CString converti;
converti=(char)nChar;
if (nChar>=32)
{
character="character "+converti;
}
AfxGetMainWnd()->InvalidateRect(clientRect,TRUE);
}

afx_msg void CMainFrame::OnPaint()
{
CPaintDC dc (this);
dc.TextOut(0,0, keycode);
dc.TextOut(0,20, character);
}