MFC Device Context example

#include <afxwin.h>
class CSimpleApp : public CWinApp
{
public:
BOOL InitInstance();
};

class CMainFrame : public CFrameWnd {
public:
CMainFrame();
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};

BOOL CSimpleApp::InitInstance(){
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}

CMainFrame::CMainFrame()
{
Create(NULL, TEXT("MFC Device context"));
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CSimpleApp MFCApp1;

//traps paint message
afx_msg void CMainFrame::OnPaint()
{

static int repaintcount;//keeps count of repaint
CString convertInt;
repaintcount++;
convertInt.Format(TEXT("%d"),repaintcount);//converts repaintcount integer to string
CPaintDC dc (this); //gets current device context
dc.TextOut(0,0,TEXT(convertInt));//writes a character string at the specified location
}