Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing Application Problem

Status
Not open for further replies.

Leibnitz

Programmer
Apr 6, 2001
393
0
0
CA
I have created a very basic MFC Application but when i run it, it use 100% of my CPU resources. Here is the code:

Code:
#include <afxwin.h>

class CDrawingApp : public CWinApp {
public:
	virtual BOOL InitInstance();
	CDrawingApp() {};
};

class CMainFrame : public CFrameWnd {
public:
	CMainFrame() {
		Create( NULL, "DrawingApp" );
	}
	afx_msg void OnPaint();
	DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd )
	ON_WM_PAINT()
END_MESSAGE_MAP()


BOOL CDrawingApp::InitInstance() {
	m_pMainWnd = new CMainFrame;
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}

void CMainFrame::OnPaint() {
	CDC *pDC = GetDC();
	CRect lpRect;
	lpRect.left = 50;
	lpRect.top = 50;
	lpRect.right = 300;
	lpRect.bottom = 300;
	pDC->Rectangle(lpRect);
	ReleaseDC(pDC);
}

CDrawingApp theApp;
Can anybody tell me what am i doing wrong?
 
alright,i have figure it out,i had to use:
Code:
PAINTSTRUCT ps;
CDC *pDC = BeginPaint(&ps);
....
....
EndPaint(&ps)

instead of:
Code:
CDC *pDC = GetDC();
....
...
ReleaseDC(pDC);
inside the OnPaint message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top