Пример #1
0
wxCalendarHitTestResult
wxCalendarCtrl::HitTest(const wxPoint& pos,
                        wxDateTime *date,
                        wxDateTime::WeekDay *wd)
{
    WinStruct<MCHITTESTINFO> hti;

    // Vista and later SDKs add a few extra fields to MCHITTESTINFO which are
    // not supported by the previous versions, as we don't use them anyhow we
    // should pretend that we always use the old struct format to make the call
    // below work on pre-Vista systems (see #11057)
#ifdef MCHITTESTINFO_V1_SIZE
    hti.cbSize = MCHITTESTINFO_V1_SIZE;
#endif

    hti.pt.x = pos.x;
    hti.pt.y = pos.y;
    switch ( MonthCal_HitTest(GetHwnd(), &hti) )
    {
        default:
        case MCHT_CALENDARWEEKNUM:
            wxFAIL_MSG( "unexpected" );
            // fall through

        case MCHT_NOWHERE:
        case MCHT_CALENDARBK:
        case MCHT_TITLEBK:
        case MCHT_TITLEMONTH:
        case MCHT_TITLEYEAR:
            return wxCAL_HITTEST_NOWHERE;

        case MCHT_CALENDARDATE:
            if ( date )
                date->SetFromMSWSysDate(hti.st);
            return wxCAL_HITTEST_DAY;

        case MCHT_CALENDARDAY:
            if ( wd )
            {
                int day = hti.st.wDayOfWeek;

                // the native control returns incorrect day of the week when
                // the first day isn't Monday, i.e. the first column is always
                // "Monday" even if its label is "Sunday", compensate for it
                const int first = LOWORD(MonthCal_GetFirstDayOfWeek(GetHwnd()));
                if ( first == MonthCal_Monday )
                {
                    // as MonthCal_Monday is 0 while wxDateTime::Mon is 1,
                    // normally we need to do this to transform from MSW
                    // convention to wx one
                    day++;
                    day %= 7;
                }
                //else: but when the first day is MonthCal_Sunday, the native
                //      control still returns 0 (i.e. MonthCal_Monday) for the
                //      first column which looks like a bug in it but to work
                //      around it it's enough to not apply the correction above

                *wd = static_cast<wxDateTime::WeekDay>(day);
            }
            return wxCAL_HITTEST_HEADER;

        case MCHT_TITLEBTNNEXT:
            return wxCAL_HITTEST_INCMONTH;

        case MCHT_TITLEBTNPREV:
            return wxCAL_HITTEST_DECMONTH;

        case MCHT_CALENDARDATENEXT:
        case MCHT_CALENDARDATEPREV:
            return wxCAL_HITTEST_SURROUNDING_WEEK;
    }
}
Пример #2
0
	LRESULT CDateTimeWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		LRESULT lRes = 0;
		BOOL bHandled = TRUE;

		if( uMsg == WM_NOTIFY)
		{
			::SetFocus(m_hWnd);
		}
		// 根据网络博客所知bug修复
		if( uMsg == WM_KILLFOCUS )
		{		
			HWND hCanlender=::FindWindow( MONTHCAL_CLASS, NULL);
			if(::IsWindow(hCanlender))
			{
				MCHITTESTINFO hitInfo;
				memset(&hitInfo,0,sizeof(hitInfo));
				GetCursorPos(&hitInfo.pt);
				::ScreenToClient(hCanlender,&hitInfo.pt);
				hitInfo.cbSize=sizeof(hitInfo);
				MonthCal_HitTest(hCanlender,&hitInfo);
				//下一个月
				if(hitInfo.uHit==MCHT_TITLEBTNNEXT)
				{
					return 1;
				}
				//上一个月
				if(hitInfo.uHit==MCHT_TITLEBTNPREV)
				{
					return 1;
				}
			}
			else
			{
				POINT pt;
				::GetCursorPos(&pt); 
				RECT rcWnd;
				::GetWindowRect(m_hWnd,&rcWnd);
				if(	!( pt.x >= rcWnd.left && pt.x <= rcWnd.right )||
					!( pt.x >= rcWnd.top && pt.x <= rcWnd.bottom ))
				{
					lRes= OnKillFocus(uMsg,wParam, lParam,bHandled);
				}
			}
		}
		else if (uMsg == WM_KEYUP && (wParam == VK_DELETE || wParam == VK_BACK))
		{
			LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
			m_pOwner->m_nDTUpdateFlag = DT_DELETE;
			m_pOwner->UpdateText();
			PostMessage(WM_CLOSE);
			return lRes;
		}
		else if (uMsg == WM_KEYUP && wParam == VK_ESCAPE)
		{
			LRESULT lRes = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
			m_pOwner->m_nDTUpdateFlag = DT_KEEP;
			PostMessage(WM_CLOSE);
			return lRes;
		}
		//	else if( uMsg == OCM_COMMAND ) {
		// 		if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE ) lRes = OnEditChanged(uMsg, wParam, lParam, bHandled);
		// 		else if( GET_WM_COMMAND_CMD(wParam, lParam) == EN_UPDATE ) {
		// 			RECT rcClient;
		// 			::GetClientRect(m_hWnd, &rcClient);
		// 			::InvalidateRect(m_hWnd, &rcClient, FALSE);
		// 		}
		//	}

		else bHandled = FALSE;
		if( !bHandled ) return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
		return lRes;
	}