LRESULT WINAPI SubClassProc(HWND hwndControl, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg) 
	{
		case WM_KEYDOWN:
			{
				switch(wParam)
				{
				case VK_DOWN:
						sCurrentDay=DateAdd(dd,7,sCurrentDay); 
						InvalidateRect(GetParent(hwndControl),NULL,FALSE);
						break;
				case VK_UP:
						sCurrentDay=DateAdd(dd,-7,sCurrentDay); 
						InvalidateRect(GetParent(hwndControl),NULL,FALSE);
						break;
				case VK_LEFT:
						sCurrentDay=DateAdd(dd,-1,sCurrentDay); 
						InvalidateRect(GetParent(hwndControl),NULL,FALSE);
						break;
				case VK_RIGHT:
						sCurrentDay=DateAdd(dd,1,sCurrentDay); 
						InvalidateRect(GetParent(hwndControl),NULL,FALSE);
						break;
				}
			}
			break;
		case WM_ERASEBKGND:
			return 1;
		case WM_GETDLGCODE:
			return CallWindowProc(hOldProc,hwndControl,uMsg,wParam,lParam)|DLGC_WANTARROWS;
			break;
    }
	return CallWindowProc(hOldProc,hwndControl,uMsg,wParam,lParam);
}
void OnCalendarCommand(HWND hwndDlg, int id, HWND hwndCtl, UINT codeNotify)
{
	switch(id) // This switch identifies the control
	{
	//Enter Key
	case 1:
		EndDialog(hwndDlg,TRUE);
		return;
	//Escape Key
	case 2:
		EndDialog(hwndDlg,FALSE);
		return;
	}
	if(id>=5000)
	{ sCurrentDay=DateAdd(yy,id-5005,sCurrentDay);
		InvalidateRect(hwndDlg,NULL,FALSE);
		return;
	}

}
Exemple #3
0
bool CClockDevice::Update ()
{
    // The clocks stays synchronised to real time
    time_t tNow = time(NULL);

    // Same time as before?
    if (tNow == m_tLast)
        return false;

    // Before the previous time?!
    if (tNow < m_tLast)
    {
        // Force a resync for negative differences (DST or manual change)
        Reset();
        return true;
    }

    // Work out how many seconds have passed since the last SAM time update
    int nDiff = static_cast<int>(tNow - m_tLast);
    m_tLast = tNow;

    // Update the time, clipping to the maximum values
    nDiff = DateAdd(m_st.nSecond, nDiff, 59);
    nDiff = DateAdd(m_st.nMinute, nDiff, 59);
    nDiff = DateAdd(m_st.nHour, nDiff, 23);

    // Any remaining time is in days and affects the date
    while (nDiff > 0)
    {
        // Limit the month so we know how many days are in the current month
        int nMonth  = Decode(m_st.nMonth);
        nMonth = min(nMonth ? nMonth : 1, 12);

        // Table for the number of days in each month
        static int anDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        // Decode the year and determine whether it's a leap year
        int nYear = Decode(m_st.nCentury)*100 + Decode(m_st.nYear);
        anDays[2] = (!(nYear % 4) && ((nYear % 100) || !(nYear % 400))) ? 29 : 28;

        // Limit the day to between 1 and the maximum for the current month
        int nDay = Decode(m_st.nDay);
        nDay = min((nDay ? nDay : 1), anDays[nMonth]);

        // If there's not enough to complete the current month, add it on and finish
        if (nDay + nDiff <= anDays[nMonth])
        {
            // Update the day in the month
            DateAdd(m_st.nDay, nDiff, anDays[nMonth]);
            break;
        }

        // Complete the current month and set the day back to the first of the month
        nDiff -= anDays[nMonth] - nDay + 1;
        m_st.nDay = 1;

        // Advance to the next month
        DateAdd(m_st.nMonth, 1, 12);

        // If we've completed a year, move back to Jan and increment the year
        if (!m_st.nMonth)
        {
            m_st.nMonth = 1;
            int nCarry = DateAdd(m_st.nYear, 1, 99);
            DateAdd(m_st.nCentury, nCarry, 99);
        }
    }

    // Time updated
    return true;
}