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

📄 gpsweekdlg.cpp

📁 把年月日时分秒转换为GPS周
💻 CPP
字号:
// gpsweekDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gpsweek.h"
#include "gpsweekDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CGpsweekDlg dialog

CGpsweekDlg::CGpsweekDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGpsweekDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGpsweekDlg)
	m_ymd = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGpsweekDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGpsweekDlg)
	DDX_Text(pDX, IDC_EDIT_DAY, m_ymd);
	DDV_MaxChars(pDX, m_ymd, 9);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGpsweekDlg, CDialog)
	//{{AFX_MSG_MAP(CGpsweekDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_CANCE, OnButtonCance)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsweekDlg message handlers

BOOL CGpsweekDlg::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 CGpsweekDlg::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 CGpsweekDlg::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 CGpsweekDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
bool CGpsweekDlg::GetGPSTime(int year,int month,int day,int &GPSweek,double &gpstime,double &JD)
{
	  year=2006;
	  month=4;
	  day=2;
	  int hour=6;
	  int minute=45;
	  double second=0; 
	  int   dayofw, dayofy, yr, ttlday, m;
	  int dinmth[ 13 ] ={0,31,28,31,30,31,30,31,31,30,31,30,31};

	//// Check limits of day, month and year 
	  if (year < 1981 || month < 1 || month > 12 || day < 1 || day > 31)
		 GPSweek = 0;

	////  Convert day, month and year to day of year 
	  if (month == 1)
		 dayofy = day;
	  else
	  {
		dayofy = 0;
		for (m=1; m<=(month-1); m++)
		{
		  dayofy += dinmth[m];
		  if ( m==2 )
		  {
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		   dayofy += 1;
		  }
		}
		dayofy += day;
	  }
	////  Convert day of year and year into week number and day of week 
	  ttlday = 360;
	  for (yr=1981; yr<=(year-1); yr++)
	  {
		ttlday  += 365;
		if (yr % 4 == 0 && yr % 100 != 0 || yr % 400 ==0)
		   ttlday  += 1;
	  }
	  ttlday += dayofy;
	  GPSweek  = ttlday/7;
	  dayofw  = ttlday - 7 * GPSweek;
	  gpstime =  (hour * 3600 + minute * 60 + second + dayofw * 86400);
	  //convert GPS time to julian data
	  JD=GPSweek*7+gpstime/86400+2444244.5;
	  return true;
}

void CGpsweekDlg::OnButtonOk() 
{
	// TODO: Add your control notification handler code here
	int      year,month,day,i,GPSweek;
	double    gpstime;
	char     Cyear[5],Cmonth[3],Cday[3];
	CString  CGPSWeek;
	UpdateData(TRUE);
	for (i=0;i<4;i++)
		Cyear[i]=m_ymd[i];
	for (i=4;i<6;i++)
	    Cmonth[i-4]=m_ymd[i];
	for (i=6;i<8;i++)
	    Cday[i-6]=m_ymd[i];
    year=atoi(Cyear);
	month=atoi(Cmonth);
    day=atoi(Cday);
	double JD;
	GetGPSTime( year, month, day,GPSweek,gpstime,JD);
	CGPSWeek.Format("%4d",GPSweek);
	CString SJD;
	SJD.Format("%lf",JD);
	AfxMessageBox(SJD);

	
	
}

void CGpsweekDlg::OnButtonCance() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
	
}

⌨️ 快捷键说明

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