Chinaunix首页 | 论坛 | 博客
  • 博客访问: 513144
  • 博文数量: 158
  • 博客积分: 4015
  • 博客等级: 上校
  • 技术积分: 1711
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-27 14:00
文章分类

全部博文(158)

文章存档

2010年(71)

2009年(87)

我的朋友

分类: C/C++

2010-02-06 14:14:37

其实不用处理WM_SIZE消息,但是为了练习,加上了:
头文件:

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

class CMainWindow : public CFrameWnd {
public:
    CMainWindow();
protected:
    static const int num = 1000;
    POINT pt[num];
    int cxClient, cyClient;
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
};

cpp:

#include <afxwin.h>
#include <math.h>
#include "sina.h"

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_SIZE()
    ON_WM_PAINT()
END_MESSAGE_MAP()

CMainWindow::CMainWindow() {
    Create(NULL, "看我来画正弦曲线曲线曲线!");
}

void CMainWindow::OnSize(UINT nType,
                         int cx,
                         int cy) {
                             cxClient = cx;
                             cyClient = cy;
}
void CMainWindow::OnPaint() {
    CPaintDC dc(this);
    dc.MoveTo(0, cyClient / 2);
    dc.LineTo(cxClient, cyClient / 2);
    for(int i = 0; i < num; i++) {
        pt[i].x = i * cxClient / num;
        pt[i].y = cyClient / 2 - (cyClient / 2) * sin(2 * 3.14159 * i / num);
    }
    dc.Polyline(pt, num);
}

运行结果:

阅读(1397) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~