234 lines
5.9 KiB
C++
Executable File
234 lines
5.9 KiB
C++
Executable File
// SetDateTimeDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "gpsmain.h"
|
|
#include "SetDateTimeDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSetDateTimeDlg dialog
|
|
|
|
|
|
CSetDateTimeDlg::CSetDateTimeDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CSetDateTimeDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CSetDateTimeDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
|
|
// 初始化背景画刷
|
|
CBitmap tmpBmp;
|
|
// 从资源中加载背景图片
|
|
tmpBmp.LoadBitmap(IDB_DT_WND);
|
|
|
|
// 建立背景画刷
|
|
m_BgDC.CreateCompatibleDC(NULL);
|
|
m_BgDC.SelectObject(&tmpBmp);
|
|
|
|
tmpBmp.DeleteObject();
|
|
|
|
// 18x18 粗体
|
|
m_titleFont.CreateFont(18,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,
|
|
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial"));
|
|
|
|
m_txtFont.CreateFont(16,0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,
|
|
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial"));
|
|
|
|
m_InitDC = false;
|
|
}
|
|
|
|
CSetDateTimeDlg::~CSetDateTimeDlg()
|
|
{
|
|
m_BgDC.DeleteDC();
|
|
m_BgBmp.DeleteObject();
|
|
m_MemDC.DeleteDC();
|
|
m_txtFont.DeleteObject();
|
|
m_titleFont.DeleteObject();
|
|
}
|
|
|
|
void CSetDateTimeDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CSetDateTimeDlg)
|
|
DDX_Control(pDX, IDC_BUTTON_DT_TIMEZONE, m_butSetTimeZone);
|
|
DDX_Control(pDX, IDC_BUTTON_DT_SETTIME, m_butSetTime);
|
|
DDX_Control(pDX, IDC_BUTTON_DT_SETDATE, m_butSetDate);
|
|
DDX_Control(pDX, IDC_BUTTON_DT_EXIT, m_butExit);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CSetDateTimeDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CSetDateTimeDlg)
|
|
ON_WM_PAINT()
|
|
ON_WM_ERASEBKGND()
|
|
ON_BN_CLICKED(IDC_BUTTON_DT_EXIT, OnButtonDtExit)
|
|
ON_BN_CLICKED(IDC_BUTTON_DT_SETDATE, OnButtonDtSetdate)
|
|
ON_BN_CLICKED(IDC_BUTTON_DT_SETTIME, OnButtonDtSettime)
|
|
ON_BN_CLICKED(IDC_BUTTON_DT_TIMEZONE, OnButtonDtTimezone)
|
|
ON_WM_TIMER()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSetDateTimeDlg message handlers
|
|
|
|
void CSetDateTimeDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
|
|
if (!m_InitDC)
|
|
{
|
|
m_BgBmp.CreateCompatibleBitmap(&dc,320,240);
|
|
m_MemDC.CreateCompatibleDC(&dc);
|
|
m_MemDC.SelectObject(&m_BgBmp);
|
|
m_InitDC = true;
|
|
}
|
|
|
|
// TODO: Add your message handler code here
|
|
m_MemDC.BitBlt(0,0,320,240,&m_BgDC,0,0,SRCCOPY);
|
|
|
|
m_MemDC.SelectObject(&m_titleFont);
|
|
m_MemDC.SetBkMode(TRANSPARENT);
|
|
m_MemDC.SetTextColor(RGB(255,255,255));
|
|
|
|
WCHAR strRes[MAX_PATH];
|
|
CString(LoadString(theApp.GetResourceLib(),IDS_SET_DATETIME_TITLE,strRes,MAX_PATH));
|
|
m_MemDC.DrawText(strRes,CRect(45,4,220,32),DT_LEFT|DT_VCENTER);
|
|
|
|
m_MemDC.SelectObject(&m_txtFont);
|
|
|
|
m_MemDC.DrawText(m_CurrentDate,CRect(48,69,224,98),DT_CENTER|DT_VCENTER);
|
|
m_MemDC.DrawText(m_CurrentTime,CRect(48,119,224,147),DT_CENTER|DT_VCENTER);
|
|
|
|
CString(LoadString(theApp.GetResourceLib(),IDS_SET_DATETIME_LOCALZONE,strRes,MAX_PATH));
|
|
m_MemDC.DrawText(strRes,CRect(48,171,224,200),DT_CENTER|DT_VCENTER);
|
|
|
|
dc.BitBlt(0,0,320,240,&m_MemDC,0,0,SRCCOPY);
|
|
// Do not call CDialog::OnPaint() for painting messages
|
|
}
|
|
|
|
BOOL CSetDateTimeDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
CenterWindow(this); // center to the hpc screen
|
|
|
|
// TODO: Add extra initialization here
|
|
// 设置窗口大小
|
|
MoveWindow(0,0,320,240);
|
|
|
|
m_butExit.MoveWindow(282,6,25,25);
|
|
m_butExit.LoadBitmaps(IDB_SETVOLUME_CLOSE,IDB_SETVOLUME_CLOSED);
|
|
|
|
m_butSetDate.MoveWindow(226,59,48,48);
|
|
m_butSetDate.LoadBitmaps(IDB_DT_SETDATE,IDB_DT_SETDATED);
|
|
|
|
m_butSetTime.MoveWindow(226,109,48,48);
|
|
m_butSetTime.LoadBitmaps(IDB_DT_SETTIME,IDB_DT_SETTIMED);
|
|
|
|
m_butSetTimeZone.MoveWindow(226,161,48,48);
|
|
m_butSetTimeZone.LoadBitmaps(IDB_DT_TIMEZONE,IDB_DT_TIMEZONED);
|
|
|
|
// 绘制日期日期
|
|
SYSTEMTIME dt;
|
|
// 获取本地日期和时间
|
|
GetLocalTime(&dt);
|
|
|
|
|
|
// 格式化日期
|
|
m_CurrentDate.Format(L"%02d/%02d/%04d",dt.wMonth,dt.wDay,dt.wYear);
|
|
|
|
// 格式化时间
|
|
m_CurrentTime.Format(L"%02d:%02d:%02d",dt.wHour,dt.wMinute,dt.wSecond);
|
|
|
|
SetTimer(1,1000,NULL);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
BOOL CSetDateTimeDlg::OnEraseBkgnd(CDC* pDC)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
return FALSE;
|
|
//return CDialog::OnEraseBkgnd(pDC);
|
|
}
|
|
|
|
void CSetDateTimeDlg::OnButtonDtExit()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
EndDialog(IDOK);
|
|
}
|
|
|
|
void CSetDateTimeDlg::OnButtonDtSetdate()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CSetDateDlg dlgSetDate;
|
|
if (dlgSetDate.DoModal() == IDOK)
|
|
{
|
|
// 绘制日期日期
|
|
SYSTEMTIME dt;
|
|
// 获取本地日期和时间
|
|
GetLocalTime(&dt);
|
|
|
|
// 格式化日期
|
|
m_CurrentDate.Format(L"%02d/%02d/%04d",dt.wMonth,dt.wDay,dt.wYear);
|
|
InvalidateRect(CRect(48,69,224,98));
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
|
|
void CSetDateTimeDlg::OnButtonDtSettime()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CSetTimeDlg dlgSetTime;
|
|
if (dlgSetTime.DoModal() == IDOK)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
|
|
void CSetDateTimeDlg::OnButtonDtTimezone()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
|
|
}
|
|
|
|
void CSetDateTimeDlg::OnTimer(UINT nIDEvent)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
|
|
// 绘制日期日期
|
|
SYSTEMTIME dt;
|
|
// 获取本地日期和时间
|
|
GetLocalTime(&dt);
|
|
|
|
|
|
|
|
|
|
// 格式化时间
|
|
m_CurrentTime.Format(L"%02d:%02d:%02d",dt.wHour,dt.wMinute,dt.wSecond);
|
|
|
|
InvalidateRect(CRect(48,119,224,147));
|
|
|
|
if (dt.wHour + dt.wMinute + dt.wSecond == 0)
|
|
{
|
|
// 格式化日期
|
|
m_CurrentDate.Format(L"%02d/%02d/%04d",dt.wMonth,dt.wDay,dt.wYear);
|
|
InvalidateRect(CRect(48,69,224,98));
|
|
}
|
|
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|