C++程序设讠 H #include<afxwin h #define maX bubble 250 class CMy Wnd: public CFrame Wnd CRect m rectBubble MAX BUbble int m nBubblecount public CMy Wndo im bUbble Count=0;
C++程序设计 #include<afxwin.h> #define MAX_BUBBLE 250 class CMyWnd:public CFrameWnd { CRect m_rectBubble[MAX_BUBBLE]; int m_nBubbleCount; public: CMyWnd() {m_nBubbleCount=0;}
C++程序设讠 H protected afx msg void OnLButtonDown UINT nFlags, CPoint point afx msg void OnPaint DECLARE MESSAGE MAPO 消息映射 BEGIN MESSAGE MAP(CMy Wnd, CFrame Wnd) ON WM LBUTTONDOWNO ON WM PAINTO END MESSAGE MAPO
C++程序设计 protected: afx_msg void OnLButtonDown(UINT nFlags,CPoint point); afx_msg void OnPaint(); DECLARE_MESSAGE_MAP() }; //消息映射 BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd) ON_WM_LBUTTONDOWN() ON_WM_PAINT() END_MESSAGE_MAP()
C++程序设讠 H ∥框架窗口类的成员函数 void CMy Wnd: OnLButtonDown qUINT nFlags, CPoint point if(m nBubble Count<MAX BUBBLE) int r=rand(%050+10 CRect rect(point x-r, point. y-r, point x+r, point y+r) m rect Bubble[m nBubble Count=rect m bUbble Count++ InvalidateRect(rect, FALSE)
C++程序设计 //框架窗口类的成员函数 void CMyWnd::OnLButtonDown(UINT nFlags,CPoint point) { if(m_nBubbleCount<MAX_BUBBLE) { 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++; InvalidateRect(rect,FALSE); }
C++程序设讠 H void CMy Wnd: OnPainto CPaintdc dc(this) CBrush brushNew CPen penNey brushNew. Create Solid Brush(rGB(rando%0255, rando%25 5, rand(90255) penNe. CreatePen(PS SOLID, 1, RGB(255,0,0)) dc Selectobject(&brushNew) dc Selectobject( &penNew)
C++程序设计 } void CMyWnd::OnPaint() { CPaintDC dc(this); CBrush brushNew; CPen penNew; brushNew.CreateSolidBrush(RGB(rand()%255,rand()%25 5,rand()%255)); penNew.CreatePen(PS_SOLID,1,RGB(255,0,0)); dc.SelectObject(&brushNew); dc.SelectObject(&penNew);
C++程序设讠 H for(int i=0; K<m nUbble Count; i++) dc ellipse(m rectBubble[]) 应用程序类 class CMyApp public CWinApp public BOOL Initinstance(;; BOOL CMyApp: nitInstanceo
C++程序设计 for(int i=0;i<m_nBubbleCount;i++) dc.Ellipse(m_rectBubble[i]); } //应用程序类 class CMyApp:public CWinApp { public: BOOL InitInstance(); }; BOOL CMyApp::InitInstance()