vecachinh

Màu nền
Font chữ
Font size
Chiều cao dòng

/* Hien cua so co menu ve cac hinh */

#define IDR_MENU1                       101

#define IDM_DIALOG1                     102

#define IDR_ACCELERATOR1                103

#define IDC_EDIT1                       1000

#define IDC_EDIT2                       1001

#define IDC_EDIT3                       1002

#define IDC_EDIT4                       1003

#define IDC_BUTTON1                     1004

#define ID_FILE_MAYTINH                 40001

#define ID_FILE_THOAT                   40003

#define ID_TOOL_VEHINHVUONG             40004

#define ID_TOOL_VEHINHCHUNHAT           40005

#define ID_TOOL_VEHINHTRON              40006

#define ID_TOOL_VEHINHELIP              40007

#define ID_TOOL_VEDOANTHANG             40008

#define ID_TOOL_VEHINHLUCGIAC           40009

IDR_MENU1 MENU DISCARDABLE

BEGIN

    POPUP "&File"

    BEGIN

        MENUITEM "&Close\tCtrl+W",              ID_FILE_THOAT

    END

    POPUP "Tool"

    BEGIN

        MENUITEM "Ve hinh vuong",               ID_TOOL_VEHINHVUONG

        MENUITEM "Ve hinh chu nhat",            ID_TOOL_VEHINHCHUNHAT

        MENUITEM "Ve hinh tron",                ID_TOOL_VEHINHTRON

        MENUITEM "Ve hinh Elip",                ID_TOOL_VEHINHELIP

        MENUITEM "Ve doan thang",               ID_TOOL_VEDOANTHANG

        MENUITEM "Ve hinh luc giac",            ID_TOOL_VEHINHLUCGIAC

    END

END

#include<afxwin.h>

#include<math.h>

#include "resource.h"

class CMyApp:public CWinApp

    {

public:

    BOOL InitInstance();

    };

    CMyApp theApp;

    class CMyWin:public CFrameWnd

    {

    public:

        CMyWin();

       

        DECLARE_MESSAGE_MAP();

        //afx_msg void OnLButtonDown(UINT nFlgs, CPoint pt);

        afx_msg void OnThoat();

        afx_msg void OnTron();

        afx_msg void OnVuong();

        afx_msg void OnElip();

        afx_msg void OnCN();

        afx_msg void OnLucGiac();

        afx_msg void OnDuongThang(UINT nFlgs, CPoint pt);

   

    };

    CMyWin::CMyWin()

    {

        Create(NULL,"Nguyen Dai Duong");

        CMenu *m=new CMenu;

        m->LoadMenu(IDR_MENU1);

        SetMenu(m);

        LoadAccelTable((LPSTR)IDR_ACCELERATOR1);

    }

    BOOL CMyApp::InitInstance()

    {

        m_pMainWnd=new CMyWin();

        m_pMainWnd->ShowWindow(3);

        m_pMainWnd->UpdateWindow();

        return TRUE;

    }

    BEGIN_MESSAGE_MAP(CMyWin, CFrameWnd)

        //ON_WM_LBUTTONDOWN()

        ON_COMMAND(ID_FILE_THOAT, OnThoat)

        ON_COMMAND(ID_TOOL_VEHINHELIP, OnElip)

        ON_COMMAND(ID_TOOL_VEHINHTRON, OnTron)

        ON_COMMAND(ID_TOOL_VEHINHVUONG, OnVuong)

        ON_COMMAND(ID_TOOL_VEHINHCHUNHAT, OnCN)

        ON_COMMAND(ID_TOOL_VEDOANTHANG, OnDuongThang)

        ON_COMMAND(ID_TOOL_VEHINHLUCGIAC, OnLucGiac)

       

    END_MESSAGE_MAP()

   

    afx_msg void CMyWin::OnElip()

    {

        RECT r;

        CDC *dc=GetDC();

        PAINTSTRUCT ps;

        int xt,yt,h,w;

        GetClientRect(&r);

        h=r.bottom-r.top;

        w=r.right-r.left;

        xt=w/2;yt=h/2;

        BeginPaint(&ps);

        dc->Ellipse(xt-h/3,yt-h/2,xt+h/3,yt+h/2);

        EndPaint(&ps);

    }

    afx_msg void CMyWin::OnTron()

    {

        RECT r;

        CDC *dc=GetDC();

        PAINTSTRUCT ps;

        int xt,yt,h,w;

        GetClientRect(&r);

        h=r.bottom-r.top;

        w=r.right-r.left;

        xt=w/2;yt=h/2;

        BeginPaint(&ps);

        dc->Ellipse(xt-h/2,yt-h/2,xt+h/2,yt+h/2);

        EndPaint(&ps);

    }

    afx_msg void CMyWin::OnVuong()

    {

        RECT r;

        CDC *dc=GetDC();

        PAINTSTRUCT ps;

        int xt,yt,h,w, a, b;

            a=r.bottom-r.top;

    b=r.right-r.left;

    xt=b/2;yt=a/2;

    dc->Rectangle(-1, -1, b+1, a+1);

        GetClientRect(&r);

        h=r.bottom-r.top;

        w=r.right-r.left;

        xt=w/2;yt=h/2;

        BeginPaint(&ps);

        //dc->Ellipse(xt-h/2,yt-h/2,xt+h/2,yt+h/2);

        dc->Rectangle(xt-h/3,yt-h/3,xt+h/3,yt+h/3);

        EndPaint(&ps);

    }

    afx_msg void CMyWin::OnCN()

    {

        RECT r;

        CDC *dc=GetDC();

        PAINTSTRUCT ps;

        int xt,yt,h,w, a, b;

        GetClientRect(&r);

        h=r.bottom-r.top;

        w=r.right-r.left;

        xt=w/2;yt=h/2;

        a=r.bottom-r.top;

    b=r.right-r.left;

    xt=b/2;yt=a/2;

    dc->Rectangle(-1, -1, b+1, a+1);

        BeginPaint(&ps);

        //dc->Ellipse(xt-h/2,yt-h/2,xt+h/2,yt+h/2);

        dc->Rectangle(xt-h/3,yt-h/4,xt+h/3,yt+h/4);

        EndPaint(&ps);

    }

    afx_msg void CMyWin::OnDuongThang(UINT nFlgs, CPoint pt)

    {

        RECT r;

        CDC *dc=GetDC();

        PAINTSTRUCT ps;

        int xt,yt,h,w, a, b;

        GetClientRect(&r);

a=r.bottom-r.top;

    b=r.right-r.left;

    xt=b/2;yt=a/2;

    dc->Rectangle(-1, -1, b+1, a+1);

        h=r.bottom-r.top;

        w=r.right-r.left;

       

        BeginPaint(&ps);

        //dc->Ellipse(xt-h/2,yt-h/2,xt+h/2,yt+h/2);

        dc->LineTo(w,h);

        dc->MoveTo(xt,yt);

        EndPaint(&ps);

    }

afx_msg void CMyWin::OnLucGiac()

    {

    double a, b, xt, yt, canh = 200;

    CDC *dc = GetDC();

    RECT r;

    GetClientRect(&r);

    a=r.bottom-r.top;

    b=r.right-r.left;

    xt=b/2;yt=a/2;

    dc->Rectangle(-1, -1, b+1, a+1);

    dc->MoveTo(xt-(canh*sqrt(3)/2),yt-(canh/2));

    dc->LineTo(xt,yt-canh);

    dc->MoveTo(xt,yt-canh);

    dc->LineTo(xt+(canh*sqrt(3)/2),yt-(canh/2));

    dc->MoveTo(xt+(canh*sqrt(3)/2),yt-(canh/2));

    dc->LineTo(xt+(canh*sqrt(3)/2),yt+(canh/2));

    dc->MoveTo(xt+(canh*sqrt(3)/2),yt+(canh/2));

    dc->LineTo(xt,yt+canh);

    dc->MoveTo(xt,yt+canh);

    dc->LineTo(xt-(canh*sqrt(3)/2),yt+(canh/2));

    dc->MoveTo(xt-(canh*sqrt(3)/2),yt+(canh/2));

    dc->LineTo(xt-(canh*sqrt(3)/2),yt-(canh/2));   

    }

   

    afx_msg void CMyWin::OnThoat()

    {

        OnClose();

    }

Bạn đang đọc truyện trên: Truyen2U.Pro