📄 alarmwnd.cpp
字号:
void CAlarmWnd::DecodeTime(BOOL bForce /*=FALSE*/)
{
CTime t = CTime::GetCurrentTime();
int t1s, t10s;
int iAlarmHour, iAlarmMinute;
int iClockHour;
m_iClock24Hour = t.GetHour();
if (pAlarmApp->m_b12HourBase)
Time24toAP(m_iClock24Hour, bCAM, iClockHour);
else
iClockHour = m_iClock24Hour;
m_iClockMinute = t.GetMinute();
m_iClockSecond = t.GetSecond();
if (pAlarmApp->m_b12HourBase)
Time24toAP(pAlarmApp->m_iAlarm24Hour, bAAM, iAlarmHour);
else
iAlarmHour = pAlarmApp->m_iAlarm24Hour;
// TRACE("iClockHour = %d, pAlarmApp->m_iClock24Hour = %d\n", iClockHour, pAlarmApp->m_iClock24Hour);
iAlarmMinute = pAlarmApp->m_iAlarmMinute;
t1s = iClockHour % 10; // Seperate the 1s.
t10s = (iClockHour - t1s) % 100; // Calculate how many 10s are in.
if (t10s > 0)
t10s = t10s / 10;
iC[0] = t10s;
iC[1] = t1s;
t1s = m_iClockMinute % 10;
t10s = (m_iClockMinute - t1s) % 100;
if (t10s > 0)
t10s = t10s / 10;
iC[2] = t10s;
iC[3] = t1s;
if (pAlarmApp->m_bAlarmActive)
{
t1s = iAlarmHour % 10;
t10s = (iAlarmHour - t1s) % 100;
if (t10s > 0)
t10s = t10s / 10;
iA[0] = t10s;
iA[1] = t1s;
t1s = iAlarmMinute % 10;
t10s = (iAlarmMinute - t1s) % 100;
if (t10s > 0)
t10s = t10s / 10;
iA[2] = t10s;
iA[3] = t1s;
}
else
{
iA[0] = iA[1] = iA[2] = iA[3] = 10;
}
if (pAlarmApp->m_bAlarmActive)
{
if ((m_iClock24Hour == pAlarmApp->m_iAlarm24Hour) && (m_iClockMinute == pAlarmApp->m_iAlarmMinute))
{
if ((m_iClock24Hour != m_iAlarmStarted24Hour) && (m_iClockMinute != m_iAlarmStartedMinute))
{
m_iAlarmStarted24Hour = m_iClock24Hour;
m_iAlarmStartedMinute = m_iClockMinute;
m_uiTimerAlarm = SetTimer(2, 5000, NULL);
}
}
}
if (bForce)
{
bClockAM = bCAM;
m_iC[0] = iC[0];
m_iC[1] = iC[1];
m_iC[2] = iC[2];
m_iC[3] = iC[3];
bAlarmAM = bAAM;
m_iA[0] = iA[0];
m_iA[1] = iA[1];
m_iA[2] = iA[2];
m_iA[3] = iA[3];
bCAM != bCAM;
bAAM != bAAM;
memset(iC, 0, sizeof(iC) / sizeof(iC[0]));
memset(iA, 0, sizeof(iA) / sizeof(iA[0]));
}
}
void CAlarmWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
}
void CAlarmWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
int cx = GetSystemMetrics(SM_CXBORDER) * 2;
int cy = GetSystemMetrics(SM_CYBORDER) * 2;
lpncsp->rgrc[0].left -= cx;
lpncsp->rgrc[0].top -= cy;
lpncsp->rgrc[0].right += cx;
lpncsp->rgrc[0].bottom += cy;
}
void CAlarmWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
{
SendMessage(WM_LBUTTONDOWN, (WPARAM)nFlags, MAKELPARAM(point.x,point.y));
}
int CAlarmWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_uiTimer = SetTimer(1, 250, NULL);
return 0;
}
void CAlarmWnd::OnDestroy()
{
CFrameWnd::OnDestroy();
if (m_uiTimer)
KillTimer(m_uiTimer);
if (m_uiTimerAlarm)
KillTimer(m_uiTimerAlarm);
}
void CAlarmWnd::OnTimer(UINT nIDEvent)
{
if (nIDEvent == m_uiTimer)
{
UpdateTime(m_bSilent);
if (m_bSilent)
{
m_bSilent = FALSE;
}
}
else if (nIDEvent == m_uiTimerAlarm)
{
if (pAlarmApp->m_bAlarmActive)
{
CSound snd;
snd.PlayResourceWav("BELLS", FALSE);
}
}
}
BOOL CAlarmWnd::OnEraseBkgnd(CDC *pDC)
{
return TRUE;
}
BOOL CAlarmWnd::PreTranslateMessage(MSG *pMsg)
{
if (m_hAccelTable != NULL)
{
if (::TranslateAccelerator(m_hWnd, m_hAccelTable, pMsg))
return TRUE;
}
return CFrameWnd::PreTranslateMessage(pMsg);
}
void CAlarmWnd::OnOptions()
{
/*
If user hits OK button, apply message is automatically sent.
*/
COptionsDlg dlg;
dlg.DoModal();
}
void CAlarmWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
CPoint pos = point; // Make copy of mouse position.
ClientToScreen(&pos); // Convert to screen coordinates.
CMenu topMenu;
topMenu.LoadMenu(IDR_PROGRAM_MENU);
CMenu *pMenu = topMenu.GetSubMenu(0);
pMenu->TrackPopupMenu(TPM_RIGHTBUTTON, pos.x, pos.y, this);
}
void CAlarmWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar)
{
case VK_APPS: CRect rc;
GetClientRect(&rc);
CPoint point(rc.left+5, rc.top+5);
SendMessage(WM_RBUTTONDOWN, (WPARAM)nFlags, MAKELPARAM(point.x,point.y));
break;
}
CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CAlarmWnd::OnFloatingmenuAlarmactive()
{
if (pAlarmApp->m_bAlarmActive)
pAlarmApp->m_bAlarmActive = FALSE;
else
pAlarmApp->m_bAlarmActive = TRUE;
UpdateTime(TRUE);
}
void CAlarmWnd::OnUpdateFloatingmenuAlarmactive(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(pAlarmApp->m_bAlarmActive ? 1 : 0);
}
void CAlarmWnd::OnFloatingmenuStopalarm()
{
if (m_uiTimerAlarm)
{
KillTimer(m_uiTimerAlarm);
m_uiTimerAlarm = 0;
m_iAlarmStarted24Hour = -1;
m_iAlarmStartedMinute = -1;
pAlarmApp->m_bAlarmActive = FALSE;
}
}
void CAlarmWnd::OnUpdateFloatingmenuStopalarm(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_uiTimerAlarm ? TRUE : FALSE);
}
void CAlarmWnd::OnFloatingmenuExit()
{
PostMessage(WM_CLOSE);
}
LRESULT CAlarmWnd::OnUserApply(WPARAM wParam, LPARAM lParam)
{
ASSERT(wParam != 0L);
ApplyWhat *pAP = (ApplyWhat*) wParam;
if (pAP->bZOrderChange)
{
if (pAlarmApp->m_bWindowIsTopmost)
{
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
else
{
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
}
if (pAP->bStyleChange)
{
if (pAlarmApp->m_iStyle >= 0)
{
m_bmpClock.DeleteObject();
m_bmpClock.LoadBitmap(iAtypes[ pAlarmApp->m_iStyle ]);
Invalidate();
}
}
if (pAP->bGrayChange)
{
nrc.Initialize(pAlarmApp->m_bGrayLetters);
Invalidate();
}
if (pAP->bAlarmActiveChange || pAP->bAlarmChange)
{
if (! pAlarmApp->m_bAlarmActive && m_uiTimerAlarm)
OnFloatingmenuStopalarm();
InvalidateRect(CRect(200, 90, 200+110, 90+20)); // Invalidates the alarm area.
}
if (pAP->bHourBaseChange)
{
DecodeTime(TRUE);
UpdateTime(TRUE);
Invalidate();
}
return 0L;
}
void CAlarmWnd::OnMove(int x, int y)
{
CFrameWnd::OnMove(x, y);
pAlarmApp->m_xPos = x;
pAlarmApp->m_yPos = y;
}
void CAlarmWnd::CheckForSpeech(int iClockHour, int iClockMinute)
{
int iIntervals[] = { 1,5,15,30,60 }, i, iMinutes;
if (pAlarmApp->m_iSpeakIntervals < 0 || pAlarmApp->m_iSpeakIntervals > 4) return;
i = iIntervals[ pAlarmApp->m_iSpeakIntervals ];
iMinutes = (iClockHour * 60) + iClockMinute;
if ((iMinutes % i) == 0)
{
CSpeakNumber num;
num.SayNumber(iClockHour, TRUE);
num.SayNumber(iClockMinute, TRUE);
}
}
void CAlarmWnd::OnWindowPosChanging(WINDOWPOS *lpwndpos)
{
CRect wndRect, trayRect;
int leftTaskbar = 0, rightTaskbar = 0, topTaskbar = 0, bottomTaskbar = 0;
GetWindowRect(&wndRect);
int screenWidth = GetSystemMetrics(SM_CXSCREEN); // Screen resolution.
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
if (pAlarmApp->m_iSnap == 0)
{
lpwndpos->x = ((lpwndpos->x + 16) / 32) * 32;
lpwndpos->y = ((lpwndpos->y - 16) / 32) * 32;
return;
}
else
{
CWnd *pWnd = FindWindow(_T("Shell_TrayWnd"), _T("")); // Find the taskbar.
pWnd->GetWindowRect(&trayRect);
int wndWidth = wndRect.right - wndRect.left;
int wndHeight = wndRect.bottom - wndRect.top;
/*
Find the location of the taskbar.
*/
if (trayRect.top <= 0 && trayRect.left <= 0 && trayRect.right >= screenWidth)
{
topTaskbar = trayRect.bottom - trayRect.top;
}
else if (trayRect.top > 0 && trayRect.left <= 0)
{
bottomTaskbar = trayRect.bottom - trayRect.top;
}
else if (trayRect.top <= 0 && trayRect.left > 0)
{
rightTaskbar = trayRect.right - trayRect.left;
}
else
{
leftTaskbar = trayRect.right - trayRect.left;
}
/*
Locate this window accordingly to screen size.
*/
if (lpwndpos->x >= -m_nXOffset + leftTaskbar && lpwndpos->x <= leftTaskbar + m_nXOffset)
{
lpwndpos->x = leftTaskbar; // Left border.
}
if (lpwndpos->y >= -m_nYOffset && lpwndpos->y <= topTaskbar + m_nYOffset)
{
lpwndpos->y = topTaskbar; // Top border.
}
if (lpwndpos->x + wndWidth <= screenWidth - rightTaskbar + m_nXOffset && lpwndpos->x + wndWidth >= screenWidth - rightTaskbar - m_nXOffset)
{
lpwndpos->x = screenWidth - rightTaskbar - wndWidth; // Right border.
}
if ( lpwndpos->y + wndHeight <= screenHeight - bottomTaskbar + m_nYOffset && lpwndpos->y + wndHeight >= screenHeight - bottomTaskbar - m_nYOffset)
{
lpwndpos->y = screenHeight - bottomTaskbar - wndHeight; // Bottom border.
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -