编写画一正方形程序,并在其中用不同的颜色画15个正方形,每一个都比前一个小。 有些细节告错了,就是不好 实现~谁帮下忙
#define _AFXDLL#include <afxwin.h>class CMyApp : public CWinApp{public: virtual BOOL InitInstance ();};class CMainWindow : public CFrameWnd{public: CMainWindow ();protected: afx_msg void OnPaint (); DECLARE_MESSAGE_MAP ()};CMyApp myApp;BOOL CMyApp::InitInstance (){ m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow (); return TRUE;}BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd) ON_WM_PAINT ()END_MESSAGE_MAP ()CMainWindow::CMainWindow (){ Create (NULL, _T ("Rectangles"));}void CMainWindow::OnPaint (){ srand((unsigned)time(0)); CPaintDC dc(this); CRect rc; GetClientRect(&rc); CRect rc2(rc.right / 30, rc.bottom / 30, rc.right / 30, rc.bottom / 30); for(int i = 0; i < 15; ++i) { CBrush cb; cb.CreateSolidBrush(RGB(rand() % 256, rand() % 256, rand() % 256)); dc.FillRect(&rc, &cb); rc -= rc2; }} |
|