📄 set_xxxdlg.cpp
字号:
// set_xxxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "set_xxx.h"
#include "set_xxxDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const RECT rBtnClose = {417,0,417+63,0+35};
const RECT rBtnDateDn = {141,55,141+40,55+31};
const RECT rBtnDateUp = {360,55,360+40,55+31};
const RECT rBtnTimeDn = {141,103,141+40,103+31};
const RECT rBtnTimeUp = {363,103,363+40,103+31};
const RECT rBtn12_24 = {414,103,414+40,103+31};
const RECT rBtnZoneDn = {141,142,141+40,142+31};
const RECT rBtnZoneUp = {363,142,363+40,142+31};
const RECT rBtnDl1 = {141,179,141+40,179+31};
const RECT rBtnDl2 = {190,179,190+211,179+31};
const RECT rAreaYear = {198,59,198+46,59+22};
const RECT rAreaMon = {267,59,267+34,59+22};
const RECT rAreaDate = {308,59,308+34,59+22};
const RECT rAreaHour = {198,107,198+46,107+22};
const RECT rAreaMin = {270,107,270+34,107+22};
const RECT rAreaSec = {312,107,312+34,107+22};
const RECT rAreaZone = {195,147,195+158,147+22};
/////////////////////////////////////////////////////////////////////////////
// CSet_xxxDlg dialog
CSet_xxxDlg::CSet_xxxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSet_xxxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSet_xxxDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bLongPush = FALSE;
m_bStopLP = TRUE;
m_AreaSel = AREA_YEAR;
m_b12hour=Get12HourMode();
}
void CSet_xxxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSet_xxxDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSet_xxxDlg, CDialog)
//{{AFX_MSG_MAP(CSet_xxxDlg)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSet_xxxDlg message handlers
BOOL CSet_xxxDlg::OnInitDialog()
{
CDialog::OnInitDialog();
extern CString g_szPropName;
extern HANDLE g_hValue;
SetProp(m_hWnd,g_szPropName,g_hValue);
// 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
// CenterWindow(GetDesktopWindow()); // center to the hpc screen
MoveWindow(0, 0, 480, 234);
InitButtons();
InitTimeAreas();
// TODO: Add extra initialization here
GetLocalTime(&m_CurTime);
m_TargetDate = m_CurTime;
GetTimeStr(m_CurTime,m_TargetDate,&m_TimeStr,m_b12hour);
InitZones(&(m_ZoneInf.pZoneItem),m_ZoneInf.dwZoneNum);
GetCurZone(&m_ZoneInf,m_TimeStr.zone);
m_fArea.CreateFont(14,0,0,0,FW_SEMIBOLD,
FALSE,FALSE,FALSE,
DEFAULT_CHARSET,
0,CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Arial");
mf_AmPm.CreateFont(10,0,0,0,FW_SEMIBOLD,
FALSE,FALSE,FALSE,
DEFAULT_CHARSET,
0,CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Arial");
SetTimer(TIMER_FRESH_TIME,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CSet_xxxDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
DeInitZones(m_ZoneInf.pZoneItem);
return CDialog::DestroyWindow();
}
BOOL CSet_xxxDlg::OnEraseBkgnd(CDC *pDC)
{
CRect rect;
rect.SetRect(0,0,480,234);
DrawJpg(pDC,IDR_BG1,&rect);
return TRUE;
}
void CSet_xxxDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DrawButtons(&dc);
DrawTimeAreas(&dc);
// Do not call CDialog::OnPaint() for painting messages
}
void CSet_xxxDlg::TimeAreaCheck(UINT nFlags, CPoint point)
{
UINT i;
AREA_SEL OldAreaSel;
PBTN_ITEM pTemp=m_TimeAreas;
OldAreaSel = m_AreaSel;
for(i=0;i<AREA_TAL_NUM;i++)
{
if(PtInRect(pTemp->pRect,point))
{
m_AreaSel = (AREA_SEL)pTemp->iIndex;
break;
}
pTemp++;
}
if(OldAreaSel!=m_AreaSel)
{
pTemp=m_TimeAreas;
for(i=0;i<AREA_TAL_NUM;i++)
{
if((m_AreaSel!=AREA_NONE)&&(m_AreaSel ==(AREA_SEL)pTemp->iIndex))
InvalidateRect(pTemp->pRect);
if((OldAreaSel!=AREA_NONE)&&(OldAreaSel ==(AREA_SEL)pTemp->iIndex))
InvalidateRect(pTemp->pRect);
pTemp++;
}
}
}
void CSet_xxxDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bLongPush = FALSE;
m_bStopLP = FALSE;
do {
PBTN_ITEM pTemp=m_BtnItems;
for(int i=0;i<BTN1_TOTAL_NUM;i++)
{
if(PtInRect(pTemp->pRect,point))
{
m_btn_index = (BTN1_INDEX)pTemp->iIndex;
InvalidateRect(pTemp->pRect,FALSE);
BtnCommandDown(pTemp->iIndex);
break;
}
pTemp++;
}
TimeAreaCheck(nFlags,point);
} while(0);
CDialog::OnLButtonDown(nFlags, point);
}
void CSet_xxxDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bStopLP = TRUE;
PBTN_ITEM pTemp=NULL;
BTN1_INDEX btn_index = m_btn_index;
m_btn_index = BTN1_NONE;
if(btn_index != BTN1_NONE)
{
pTemp=m_BtnItems;
for(int i=0;i<BTN1_TOTAL_NUM;i++)
{
if(btn_index==(BTN1_INDEX)pTemp->iIndex)
{
InvalidateRect(pTemp->pRect,FALSE);
if(PtInRect(pTemp->pRect,point)&&(!m_bLongPush))
BtnCommandUp(btn_index);
break;
}
pTemp++;
}
}
CDialog::OnLButtonUp(nFlags, point);
}
void CSet_xxxDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case TIMER_FRESH_TIME:
FreshTimeAreaAuto();
break;
case TIMER_LONGPUSH_ONE:
m_bLongPush = TRUE;
BtnLongPushCommand(m_btn_index);
KillTimer(TIMER_LONGPUSH_ONE);
break;
case TIMER_LONGPUSH_CON:
m_bLongPush = TRUE;
BtnLongPushCommand(m_btn_index);
KillTimer(TIMER_LONGPUSH_CON);
if(!m_bStopLP)
SetTimer(TIMER_LONGPUSH_CON,CON_TIME,NULL);
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
void CSet_xxxDlg::InitButtons()
{
PBTN_ITEM pBtnItem=m_BtnItems;
FillButton(pBtnItem++,BTN1_CLOSE,IDR_BTN1_CLOSE,IDR_BTN1_CLOSE_P,&rBtnClose);
FillButton(pBtnItem++,BTN1_DATE_DN,IDR_BTN1_DATE_DN,IDR_BTN1_DATE_DN_P,&rBtnDateDn);
FillButton(pBtnItem++,BTN1_DATE_UP,IDR_BTN1_DATE_UP,IDR_BTN1_DATE_UP_P,&rBtnDateUp);
FillButton(pBtnItem++,BTN1_TIME_DN,IDR_BTN1_TIME_DN,IDR_BTN1_TIME_DN_P,&rBtnTimeDn);
FillButton(pBtnItem++,BTN1_TIME_UP,IDR_BTN1_TIME_UP,IDR_BTN1_TIME_UP_P,&rBtnTimeUp);
FillButton(pBtnItem++,BTN1_ZONE_DN,IDR_BTN1_ZONE_DN,IDR_BTN1_ZONE_DN_P,&rBtnZoneDn);
FillButton(pBtnItem++,BTN1_ZONE_UP,IDR_BTN1_ZONE_UP,IDR_BTN1_ZONE_UP_P,&rBtnZoneUp);
FillButton(pBtnItem++,BTN1_12_24,0,0,&rBtn12_24);
FillButton(pBtnItem++,BTN1_DL1_SEL,0,0,&rBtnDl1);
FillButton(pBtnItem++,BTN1_DL2_SEL,0,0,&rBtnDl2);
}
void CSet_xxxDlg::InitTimeAreas()
{
PBTN_ITEM pBtnItem=m_TimeAreas;
FillButton(pBtnItem++,AREA_YEAR,IDR_AREA_YEAR,IDR_AREA_YEAR_P,&rAreaYear);
FillButton(pBtnItem++,AREA_MON,IDR_AREA_MON,IDR_AREA_MON_P,&rAreaMon);
FillButton(pBtnItem++,AREA_DATE,IDR_AREA_DATE,IDR_AREA_DATE_P,&rAreaDate);
FillButton(pBtnItem++,AREA_HOUR,IDR_AREA_HOUR,IDR_AREA_HOUR_P,&rAreaHour);
FillButton(pBtnItem++,AREA_MIN,IDR_AREA_MIN,IDR_AREA_MIN_P,&rAreaMin);
FillButton(pBtnItem++,AREA_SEC,IDR_AREA_SEC,IDR_AREA_SEC_P,&rAreaSec);
FillButton(pBtnItem++,AREA_ZONE,IDR_AREA_ZONE,IDR_AREA_ZONE_P,&rAreaZone);
}
void CSet_xxxDlg::DrawButtons(CDC* pDC)
{
PBTN_ITEM pTemp = m_BtnItems;
for(UINT i=0;i<BTN1_TOTAL_NUM;i++)
{
if(pTemp->iIndex<BTN1_12_24)
DrawJpg(pDC,(UINT)m_btn_index==pTemp->iIndex?pTemp->iImage2:pTemp->iImage1,pTemp->pRect);
else if(pTemp->iIndex==BTN1_12_24)
DrawJpg(pDC,m_b12hour?IDR_BTN1_SHOW12:IDR_BTN1_SHOW24,pTemp->pRect);
else if(pTemp->iIndex==BTN1_DL1_SEL)
DrawJpg(pDC,(m_ZoneInf.bDl_Mask&BIT_DL_ON)?((m_ZoneInf.bDl_Mask&BIT_DL_EN)?IDR_BTN1_DL1_EN:IDR_BTN1_DL1_DIS):\
(IDR_BTN1_DL1_OFF),pTemp->pRect);
else if(pTemp->iIndex==BTN1_DL2_SEL)
DrawJpg(pDC,(m_ZoneInf.bDl_Mask&BIT_DL_EN)?IDR_BTN1_DL2_EN:IDR_BTN1_DL2_DIS,pTemp->pRect);
pTemp++;
}
return;
}
void CSet_xxxDlg::FreshTimeArea(UINT mask)
{
CWindowDC dc(this);
GetTimeStr(m_CurTime,m_TargetDate,&m_TimeStr,m_b12hour);
DrawAreaItem(&dc,mask);
}
void CSet_xxxDlg::FreshTimeAreaAuto()
{
SYSTEMTIME OldCurTime;
UINT mask=0;
CWindowDC dc(this);
OldCurTime = m_CurTime;
GetLocalTime(&m_CurTime);
// mask |= (OldCurTime.wYear==m_CurTime.wYear?BIT_NONE:BIT_YEAR);
// mask |= (OldCurTime.wMonth==m_CurTime.wMonth?BIT_NONE:BIT_MON);
mask |= (OldCurTime.wDay==m_CurTime.wDay?BIT_NONE:BIT_DATE);
mask |= (OldCurTime.wHour==m_CurTime.wHour?BIT_NONE:BIT_HOUR);
mask |= (OldCurTime.wMinute==m_CurTime.wMinute?BIT_NONE:BIT_MIN);
mask |= (OldCurTime.wSecond==m_CurTime.wSecond?BIT_NONE:BIT_SEC);
if(mask & BIT_DATE)
{
m_TargetDate = m_CurTime;
mask |= (BIT_YEAR&BIT_MON);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -