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

全部博文(158)

文章存档

2010年(71)

2009年(87)

我的朋友

分类: C/C++

2010-02-06 16:03:04

请参照:http://blog.chinaunix.net/u3/91935/showart_2143250.html
运行结果一样。
头文件:

#ifndef DRAWDEMO_H
#define DRAWDEMO_H
class CMyApp : public CWinApp {
    virtual BOOL InitInstance();
};

class CMainWindow : public CFrameWnd {
public:
    CMainWindow();
protected:
    int cxClient, cyClient;
    CPoint pt[4];
    afx_msg void OnSize(UINT,int, int);
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
};
#endif

实现文件:

#include <afxwin.h>
#include "draw.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 uType,
                         int cx,
                         int cy) {
                             cxClient = cx;
                             cyClient = cy;
}

void CMainWindow::OnPaint() {
    CPaintDC dc(this);
    dc.MoveTo(0, cyClient / 2);
    dc.LineTo(cxClient, cyClient / 2);
    dc.MoveTo(cxClient / 2, 0);
    dc.LineTo(cxClient / 2, cyClient);

    pt[0].x = cxClient / 4;
    pt[0].y = 0;
    pt[1].x = cxClient / 2;
    pt[1].y = cyClient / 4;
    pt[2].x = cxClient / 4;
    pt[2].y = cyClient / 2;
    pt[3].x = 0;
    pt[3].y = cyClient / 4;

    dc.Polygon(pt, 4);

    dc.Ellipse(cxClient / 2, 0, cxClient, cyClient / 2);

    dc.RoundRect(cxClient / 8, 5 * cyClient / 8,
        cxClient / 2 - cxClient / 8, cyClient - cyClient / 8,
        cxClient / 16, cyClient / 16);
    dc.Chord(cxClient / 2, cyClient / 2, 3 * cxClient / 2, 3* cyClient / 2,
        cxClient, cyClient / 2, cxClient / 2, cyClient);
}


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