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

全部博文(158)

文章存档

2010年(71)

2009年(87)

我的朋友

分类: C/C++

2010-02-07 16:26:09

《MFC windows程序设计》里有一个NIKE的玩意,它是通过固定坐标来画的,有点不爽,看我的。

再来一个?

原理非常简单,采用贝寒尔曲线来画,下面是代码,仅供参照!!
头文件:

#ifndef NIKEDEMO_H
#define NIKEDEMO_H
class CMyApp : public CWinApp {
    virtual BOOL InitInstance();
};
class CMainWindow : public CFrameWnd {
public:
    CMainWindow();
protected:
    int cxClient, cyClient, Flags;
    CPoint pt1[4], pt2[4];
    void DrawNike(POINT*);
    afx_msg void OnSize(UINT, int, int);
    afx_msg void OnPaint();
    afx_msg void OnMouseMove(UINT, CPoint);
    afx_msg void OnMButtonDown(UINT, CPoint);
    DECLARE_MESSAGE_MAP()
};
#endif

实现文件:

#include <afxwin.h>
#include "nikeDemo.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()
    ON_WM_MOUSEMOVE()
    ON_WM_MBUTTONDOWN()
END_MESSAGE_MAP()

CMainWindow::CMainWindow() {
    Create(NULL, _T("耐咳??嗯嗯!!"));
}
void CMainWindow::DrawNike(POINT* pt) {
    static CClientDC dc(this);

    dc.SetROP2(R2_NOT);
    dc.PolyBezier(pt, 4);
    // dc.MoveTo(pt[0]);

    // dc.LineTo(pt[1]);

    // dc.MoveTo(pt[2]);

    // dc.LineTo(pt[3]);

}
void CMainWindow::OnSize(UINT uType, int cx, int cy) {
    cxClient = cx;
    cyClient = cy;
    Flags = 1;

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

    pt2[0].x = cxClient / 3;
    pt2[0].y = cyClient / 2;
    pt2[1].x = cxClient;
    pt2[1].y = cyClient;
    pt2[2].x = cxClient;
    pt2[2].y = cyClient;
    pt2[3].x = 3 * cxClient / 4;
    pt2[3].y = cyClient / 4;
}
void CMainWindow::OnMButtonDown(UINT flags, CPoint point) {
    Flags = -Flags;
}
void CMainWindow::OnMouseMove(UINT flags, CPoint point) {
    if(Flags == 1) {
        if(flags & MK_LBUTTON) {
            DrawNike(pt1);
            pt1[1] = point;
            DrawNike(pt1);
        }
        if(flags & MK_RBUTTON) {
            DrawNike(pt1);
            pt1[2] = point;
            DrawNike(pt1);
        }
    }

    if(Flags == -1) {
        if(flags & MK_LBUTTON) {
            DrawNike(pt2);
            pt2[1] = point;
            DrawNike(pt2);
        }
        if(flags & MK_RBUTTON) {
            DrawNike(pt2);
            pt2[2] = point;
            DrawNike(pt2);
        }
    }
}
void CMainWindow::OnPaint() {
    CPaintDC dc(this);
    dc.PolyBezier(pt1, 4);
    dc.PolyBezier(pt2, 4);

}


阅读(1955) | 评论(0) | 转发(0) |
0

上一篇:贝塞尔曲线MFC版

下一篇:类CFont初体验

给主人留下些什么吧!~~