⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 平移算法dlg.cpp

📁 本程序描绘了一个图形的基本平移
💻 CPP
字号:
// 平移算法Dlg.cpp : implementation file
//
/********************************************************************  
 *				作者:巫丙亮										*
 *				华东交通大学信息工程学院02级						*
 *				快毕业。。。。。就要被卖了。。。。。				*
 ********************************************************************/
#include "stdafx.h"
#include "平移算法.h"
#include "平移算法Dlg.h"
#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_x = 0;
	m_y = 0;
	m_jiaodu = 0;
	m_beishu = 0.0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Text(pDX, IDC_EDIT1, m_x);
	DDX_Text(pDX, IDC_EDIT2, m_y);
	DDX_Text(pDX, IDC_EDIT3, m_jiaodu);
	DDX_Text(pDX, IDC_EDIT4, m_beishu);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIO1, Onx)
	ON_BN_CLICKED(IDC_RADIO2, Ony)
	ON_BN_CLICKED(IDC_RADIO3, Ono)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, Onpingyi)
	ON_BN_CLICKED(IDC_BUTTON2, Onjiaodu)
	ON_BN_CLICKED(IDC_BUTTON3, Onchong)
	ON_BN_CLICKED(IDC_BUTTON4, Onsuofang)
	ON_BN_CLICKED(IDC_RADIO4, Onzhen)
	ON_BN_CLICKED(IDC_RADIO5, Onfu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	X=75,Y=130,X1=105,Y1=130,X2=125,Y2=160,X3=55,Y3=160;
	SetTimer(1,10,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
void CMyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
	//横纵坐标
	CClientDC dc(this);
	dc.MoveTo(15,215);
	dc.LineTo(330,215);
	dc.MoveTo(175,75);
	dc.LineTo(175,355);
	dc.MoveTo(15,75);
	dc.LineTo(330,355);
	dc.MoveTo(330,75);
	dc.LineTo(15,355);
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::Onx() 
{
	// TODO: Add your control notification handler code here	
	InvalidateRect(NULL,true);
	Y=430-Y;
	Y1=430-Y1;
	Y2=430-Y2;
	Y3=430-Y3;
}

void CMyDlg::Ony() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	X=350-X;
	X1=350-X1;
	X2=350-X2;
	X3=350-X3;
}

void CMyDlg::Ono() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	X=350-X;
	X1=350-X1;
	X2=350-X2;
	X3=350-X3;
	Y=430-Y;
	Y1=430-Y1;
	Y2=430-Y2;
	Y3=430-Y3;
}
void CMyDlg::drawtixing(int x,int y,int x1,int y1,int x2,int y2,int x3,int y3)
{
	CClientDC dc(this);
	CPen mypen;
	mypen.CreatePen(PS_SOLID,1,RGB(0,0,255));
	CPen* p;
	p=dc.SelectObject(&mypen);
	dc.MoveTo(x,y);
	dc.LineTo(x1,y1);
	dc.LineTo(x2,y2);
	dc.LineTo(x3,y3);
	dc.LineTo(x,y);
}

void CMyDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	drawtixing(X,Y,X1,Y1,X2,Y2,X3,Y3);
	CDialog::OnTimer(nIDEvent);
}

void CMyDlg::Onpingyi() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	UpdateData(true);
	X+=m_x;
	X1+=m_x;
	X2+=m_x;
	X3+=m_x;
	Y+=m_y;
	Y1+=m_y;
	Y2+=m_y;
	Y3+=m_y;
}

void CMyDlg::Onjiaodu() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	UpdateData(true);
	double i=6.18*(double(m_jiaodu)/360);
	int m=X,m1=X1,m2=X2,m3=X3;	
	X=175+(X-175)*cos(i)-(Y-215)*sin(i);
	Y=215+(m-175)*sin(i)+(Y-215)*cos(i);
	X1=175+(X1-175)*cos(i)-(Y1-215)*sin(i);
	Y1=215+(m1-175)*sin(i)+(Y1-215)*cos(i);
	X2=175+(X2-175)*cos(i)-(Y2-215)*sin(i);
	Y2=215+(m2-175)*sin(i)+(Y2-215)*cos(i);
	X3=175+(X3-175)*cos(i)-(Y3-215)*sin(i);
	Y3=215+(m3-175)*sin(i)+(Y3-215)*cos(i);
}

void CMyDlg::Onchong() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	X=75,Y=130,X1=105,Y1=130,X2=125,Y2=160,X3=55,Y3=160;
}

void CMyDlg::Onsuofang() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	UpdateData(true);
	X=175+(X-175)*m_beishu;
	Y=215+(Y-215)*m_beishu;
	X1=175+(X1-175)*m_beishu;
	Y1=215+(Y1-215)*m_beishu;
	X2=175+(X2-175)*m_beishu;
	Y2=215+(Y2-215)*m_beishu;
	X3=175+(X3-175)*m_beishu;
	Y3=215+(Y3-215)*m_beishu;

}

void CMyDlg::Onzhen() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	int t=X,t1=X1,t2=X2,t3=X3;
	X=-(Y-215)+175;
	Y=-(t-175)+215;
	X1=-(Y1-215)+175;
	Y1=-(t1-175)+215;
	X2=-(Y2-215)+175;
	Y2=-(t2-175)+215;
	X3=-(Y3-215)+175;
	Y3=-(t3-175)+215;
}

void CMyDlg::Onfu() 
{
	// TODO: Add your control notification handler code here
	InvalidateRect(NULL,true);
	int t=X,t1=X1,t2=X2,t3=X3;
	X=(Y-215)+175;
	Y=(t-175)+215;
	X1=(Y1-215)+175;
	Y1=(t1-175)+215;
	X2=(Y2-215)+175;
	Y2=(t2-175)+215;
	X3=(Y3-215)+175;
	Y3=(t3-175)+215;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -