标签:windows编程
Hello.h
class CHelloApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
class CMainFrame:public CFrameWnd
{
public:
CMainFrame();
CRect m_rectBubble[50];
int m_nBubbleCount;
public:
void DrawEllipse(CRect rect);
protected:
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
DECLARE_MESSAGE_MAP()
};
Hello.cpp
#include <afxwin.h>
#include "Hello.h"
CHelloApp theApp;
CMainFrame::CMainFrame():m_nBubbleCount(0)
{
Create(NULL,_T("The Hello Application"));
}
BOOL CHelloApp::InitInstance()
{
m_pMainWnd=new CMainFrame;
m_pMainWnd->ShowWindow(SW_SHOWNORMAL );
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CMainFrame::OnLButtonDown(UINT nFlags,CPoint point)
{
srand((unsigned)time(NULL));
int r=rand()%50+10;
CRect rect(point.x-r,point.y-r,point.x+r,point.y+r);
m_rectBubble[m_nBubbleCount]=rect;
m_nBubbleCount++;
DrawEllipse(rect);
}
void CMainFrame::DrawEllipse(CRect rect)
{
CClientDC dc(this);
dc.SelectStockObject(BLACK_BRUSH);
dc.Ellipse(&rect);
}
void CMainFrame::OnPaint()
{
/* CPaintDC dc(this);
dc.SelectStockObject(BLACK_BRUSH);
for(int i=0;i<m_nBubbleCount;i++)
{
dc.Ellipse(&m_rectBubble[i]);
}
*/
for(int i=0;i<m_nBubbleCount;i++)
{
DrawEllipse(m_rectBubble[i]);
}
}
标签:windows编程
原文地址:http://xuexhui.blog.51cto.com/7878938/1563086