码迷,mamicode.com
首页 > 编程语言 > 详细

FIRST_MFC

时间:2014-10-13 11:50:20      阅读:172      评论:0      收藏:0      [点我收藏+]

标签: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]);
 }
 
}

 

FIRST_MFC

标签:windows编程

原文地址:http://xuexhui.blog.51cto.com/7878938/1563086

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!