📄 sunhightangledlg.cpp
字号:
// SunHightAngleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SunHightAngle.h"
#include "SunHightAngleDlg.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI 3.1415926
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSunHightAngleDlg dialog
CSunHightAngleDlg::CSunHightAngleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSunHightAngleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSunHightAngleDlg)
m_date = COleDateTime::GetCurrentTime();
m_time = COleDateTime::GetCurrentTime();
m_heightAngle = 0.0;
m_latitude = 0.0;
m_longitude = 0.0;
m_eastOrWest = -1;
m_northOrSouth = -1;
//m_aspectAngle = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSunHightAngleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSunHightAngleDlg)
DDX_Control(pDX, IDC_BUTTON1, m_calculate);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_date);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_time);
DDX_Text(pDX, IDC_EDIT_HeightAngle, m_heightAngle);
DDX_Text(pDX, IDC_EDIT_Latitude, m_latitude);
DDX_Text(pDX, IDC_EDIT_Longitude, m_longitude);
DDX_Radio(pDX, IDC_RADIO1, m_eastOrWest);
DDX_Radio(pDX, IDC_RADIO3, m_northOrSouth);
//DDX_Text(pDX, IDC_EDIT_HeightAngle2, m_aspectAngle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSunHightAngleDlg, CDialog)
//{{AFX_MSG_MAP(CSunHightAngleDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnCalculate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSunHightAngleDlg message handlers
BOOL CSunHightAngleDlg::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
m_longitude = 0.0;
m_latitude = 0.0;
m_eastOrWest = 0;
m_northOrSouth = 0;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSunHightAngleDlg::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 CSunHightAngleDlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSunHightAngleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSunHightAngleDlg::OnCalculate()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int year = m_date.GetYear();
double N0 = 79.6764 + 0.2422*(year-1985) - floor((year-1985)/4);
int N = m_date.GetDayOfYear();
double sitar = 2*PI*(N-N0)/365.2422;
double ED = 0.3723 + 23.2567*sin(sitar) + 0.1149*sin(2*sitar) - 0.1712*sin(3*sitar)
- 0.758*cos(sitar) + 0.3656*cos(2*sitar) + 0.0201*cos(3*sitar);
ED = ED*PI/180; //ED本身有符号,无需判断正负。
//ED = (m_northOrSouth==0)? ED:(-ED);
double dLong = 0.0; //地球上某一点与其所在时区中心的经度差
if (0==m_eastOrWest)
{
dLong = m_longitude - (floor((m_longitude*10-75)/150)+1)*15.0;
}
else
{
dLong = (floor((m_longitude*10-75)/150)+1)*15.0- m_longitude;
}
double dTimeAngle = 15.0* (12.0-(m_time.GetHour()+m_time.GetMinute()/60.0+m_time.GetSecond()/3600.0))-dLong;
dTimeAngle = dTimeAngle*PI/180;
double latitudeArc = (m_northOrSouth==0)? m_latitude:(-m_latitude);
double latitude = latitudeArc*PI/180;
double m_heightAngleArc = asin(sin(latitude)*sin(ED)+cos(latitude)*cos(ED)*cos(dTimeAngle));
m_heightAngle = m_heightAngleArc*180/PI;
/*double m_aspectAngleArc = acos(sin(m_heightAngleArc)*sin(latitudeArc)-sin(ED))/(cos(m_heightAngleArc)*cos(latitudeArc));
m_aspectAngle = m_aspectAngleArc*180/PI;*/
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -