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

📄 jindongdlg.cpp

📁 陀螺进动仿真模型
💻 CPP
字号:
// jindongDlg.cpp : implementation file
//

#include "stdafx.h"
#include "jindong.h"
#include "math.h"
#include "jindongDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CJindongDlg dialog
CJindongDlg::CJindongDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CJindongDlg::IDD, pParent)
{
	pi=6.283185307179586476925286766559;
	//{{AFX_DATA_INIT(CJindongDlg)
	m_f1 = 5.0;
	m_f2 = 30.0;
	m_x1 = 80.0;
	m_x2 = 80.0;
	m_y1 = 80.0;
	m_y2 = 80.0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CJindongDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CJindongDlg)
	DDX_Text(pDX, IDC_EDIT6, m_f1);
	DDX_Text(pDX, IDC_EDIT7, m_f2);
	DDX_Text(pDX, IDC_EDIT2, m_x1);
	DDX_Text(pDX, IDC_EDIT3, m_x2);
	DDX_Text(pDX, IDC_EDIT4, m_y1);
	DDX_Text(pDX, IDC_EDIT5, m_y2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CJindongDlg, CDialog)
	//{{AFX_MSG_MAP(CJindongDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJindongDlg message handlers

BOOL CJindongDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CJindongDlg::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 CJindongDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect rect;
	GetClientRect(&rect);
	double t;

	int originx,originy;
	originx=rect.Width()/2-70;
	originy=rect.Height()/2;
	if (IsIconic())
	{

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

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);

		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		GetPoint(0.0);

		dc.MoveTo(originx+point.x,-point.y+originy);
		double zhouqi;
		double h;
		int  max,min;
		int i,oldi;
		int sebie1;
		int sebie2;
		int sebie3;
		int multF;

		if(m_f1<m_f2)
			max=m_f2,min=m_f1;
		else
			max=m_f1,min=m_f2;

		//需要寻找最大公约数
		double gongyueshu=min;

		for(i=min;i>1;i--)
		{
			if(max%i==0)
			{
				//能被自己整除
				if(min%i==0)
				{
					gongyueshu=i;
					break;
				}
			}
		}

		zhouqi=min/gongyueshu/min;

		h=zhouqi/5000/max;
		
		CPen *RedPen=NULL;
		

		sebie1=255/gongyueshu;
		sebie2=sebie1/10;
		sebie3=sebie1/20;

		multF=(int)(max/min);

		oldi=(int)(max/min);

		for(t=0;t<zhouqi+h;t=t+h)
		{
			//高频分量经过的第i个低频的倍频
			i=(int)(t/zhouqi);
			if(oldi!=i)
			{
				COLORREF ncolor=RGB(i*sebie1,i*sebie2,i*sebie3);
				delete RedPen;
				RedPen=new CPen;
				RedPen->CreatePen(PS_SOLID,1,ncolor);
				oldi=i;
				CString str;
				str.Format("%d",i);
				dc.SetBkMode(TRANSPARENT);
				dc.TextOut(originx+point.x,-point.y+originy,str);
				Beep(1000,10);
			}
			dc.SelectObject(RedPen);
			GetPoint(t);
			dc.LineTo(originx+point.x,-point.y+originy);
		}

		delete RedPen;
		
		CDialog::OnPaint();
	}
}

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

void CJindongDlg::GetPoint(double t)
{
	point.x=(int)(m_x1*cos(m_f1*pi*t)+m_x2*cos(m_f2*pi*t));
	point.y=(int)(m_y1*sin(m_f1*pi*t)+m_y2*sin(m_f2*pi*t));
}

void CJindongDlg::OnButton1() 
{
	UpdateData(TRUE);
	Invalidate(TRUE);
}

⌨️ 快捷键说明

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