📄 tidedlg.cpp
字号:
// TideDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Tide.h"
#include "TideDlg.h"
#include "Calender.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()
/////////////////////////////////////////////////////////////////////////////
// CTideDlg dialog
CTideDlg::CTideDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTideDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTideDlg)
m_time = -1;
m_year = 0;
m_month = 0;
m_day = 0;
m_height1 = _T("");
m_time1 = _T("");
m_time2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTideDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTideDlg)
DDX_Control(pDX,IDC_FORECAST_BTN,m_forecastBtn);
DDX_Control(pDX,IDC_EXIT_BTN,m_exitBtn);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_time);
DDX_Text(pDX, IDC_EDIT1, m_year);
DDX_Text(pDX, IDC_EDIT2, m_month);
DDX_Text(pDX, IDC_EDIT3, m_day);
DDX_Text(pDX, IDC_HEIGHT1_EDIT, m_height1);
DDX_Text(pDX, IDC_TIME1_EDIT, m_time1);
DDX_Text(pDX, IDC_TIME2_EDIT, m_time2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTideDlg, CDialog)
//{{AFX_MSG_MAP(CTideDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT_BTN, OnExitBtn)
ON_BN_CLICKED(IDC_FORECAST_BTN, OnForecastBtn)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTideDlg message handlers
BOOL CTideDlg::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_forecastBtn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_forecastBtn.SetBkColor(RGB(252,189,252));
m_forecastBtn.SetRounded(TRUE);
m_forecastBtn.SetTooltipText(_T("预报"));
m_exitBtn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_exitBtn.SetBkColor(RGB(252,189,252));
m_exitBtn.SetRounded(TRUE);
m_exitBtn.SetTooltipText(_T("预报"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CTideDlg::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 CTideDlg::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 CTideDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTideDlg::OnExitBtn()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CTideDlg::OnForecastBtn()
{
// TODO: Add your control notification handler code here
UpdateData();
struct myDATE m_date,m_lunarDate;//定义两个myDATE类型的对象,一个存储阳历日期,一个存储阴日期
m_date.year=m_time.GetYear();
m_date.month=m_time.GetMonth();
m_date.day=m_time.GetDay();//将当前日期存储到m_date中
m_lunarDate=m_calender.Lunar(m_date);//将当前日期的阴历日期存储到m_lunarDate中
//显示农历日期
m_year=m_lunarDate.year;//农历的年
m_month=m_lunarDate.month;//农历的月
m_day=m_lunarDate.day;//农历的天
//x是初一的第一次涨潮时间,要得到不同地区的预报,只需修改此处的值就可以
//y是初一的第二次涨潮时间,要得到不同地区的预报,只需修改此处的值就可以
float x=4.5;//小数点后面为60进制;因为1小时是60分,0.15为9分钟
float y=17;
float time;//用于存储预测后的时间
int hour1,hour2,minute;//x用于存储小时,z用于存储分钟
CString str1,str2,str,str_t1,str_t2;//
if(m_day==1)
{
//将第一次涨潮的时间计算后,转换成字符串的形式,存储在str_t1中
time=x;//计算涨潮时间,在此处直接得到,后面须计算
hour1=(int)time;//得到涨潮时间的小时部分
str1.Format("%d",hour1);//存储涨潮时间的小时部分
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);//用于存储涨潮时间的分钟部分
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//将第二次涨潮的时间计算后,转换成字符串的形式,存储在str_t2中
time=y;
hour2=(int)time;
str1.Format("%d",hour2);//用于存储涨潮时间的小时部分
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day>1&&m_day<11)
{
time=(m_day*0.6-1.2)+x;//计算涨潮时间
hour1=(int)time;//得到涨潮时间的小时部分
str1.Format("%d",hour1);//存储涨潮时间的小时部分
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=(m_day*0.8-1.6)+y;
hour2=(int)time;
str1.Format("%d",hour2);//用于存储涨潮时间的小时部分
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day>10&&m_day<16)
{
time=(m_day*0.8-1.2)+x;
hour1=(int)time;
if(hour1>24)
hour1-=24;
str1.Format("%d",hour1);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=(m_day*0.8-0.8)+y;
hour2=(int)time;
if(hour2>24)
hour2-=24;
str1.Format("%d",hour2);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day==16)
{
time=x;
hour1=(int)time;
str1.Format("%d",hour1);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=y;
hour2=(int)time;
str1.Format("%d",hour2);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day>16&&m_day<22)
{
time=(m_day*0.8-1.8)+x;
hour1=(int)time;
if(hour1>24)
hour1-=24;
str1.Format("%d",hour1);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=(m_day*0.8-1.8)+y;
hour2=(int)time;
if(hour2>24)
hour2-=24;
str1.Format("%d",hour2);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day>21&&m_day<26)
{
time=(m_day*0.8-2.2)+x;
hour1=(int)time;
if(hour1>24)
hour1=hour1-24;
str1.Format("%d",hour1);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=(m_day*0.8-2.2)+y;
hour2=(int)time;
if(hour2>24)
hour2=hour2-24;
str1.Format("%d",hour2);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
else if(m_day>25&&m_day<31)
{
time=m_day*0.8+x;
hour1=(int)time;
if(hour1>24)
hour1-=24;
str1.Format("%d",hour1);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t1.Format("%s:%s",str1,str2);
//the second tide
time=m_day*0.8+y;
hour2=(int)time;
if(hour2>24)
hour2-=24;
str1.Format("%d",hour2);
time=time*100;
minute=int((int)(time)%100*0.6);
if(minute<10)
{
str2.Format("0%d",minute);
}
else
str2.Format("%d",minute);
str_t2.Format("%s:%s",str1,str2);
if(hour1<hour2)
{
m_time1=str_t1;
m_time2=str_t2;
}
else
{
m_time1=str_t2;
m_time2=str_t1;
}
}
UpdateData(false);
}
HBRUSH CTideDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
/*if(nCtlColor==CTLCOLOR_LISTBOX)
{
pDC->SetTextColor(RGB(233,233,220));
//pDC->SetBkColor(RGB(233,233,220));
HBRUSH h=CreateSolidBrush(RGB(233,233,220));
return h;
}
else if(nCtlColor==CTLCOLOR_STATIC)
{
}
else if(nCtlColor==CTLCOLOR_DLG)
{
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(160,180,220));
HBRUSH h=CreateSolidBrush(RGB(160,180,220));
return h;
}
*/
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -