CDateTimeUI 的bug

DUILib库中时间控件在xp下的bug,描述如下:

    时间控件CDateTimeUI点击下拉展开日历后,选中日期后,展开部分不消失。

    时间控件CDateTimeUI在xp下点击下拉日历(calender)中的日期不会自动消失,Win7下没有这个问题

解决方案:

修改CDateTimeWnd的HandleMessage方法

DUILib源码:

        LRESULT lRes = 0;
        BOOL bHandled = TRUE;
        if( uMsg == WM_KILLFOCUS )
        {
            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;
        }



修复后的代码


LRESULT CDateTimeWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)

    {

        LRESULT lRes = 0;

        BOOL bHandled = TRUE;

        /**xpBug***/

        DWORD ProcessId;

        if(WM_SETFOCUS==uMsg)

        {

            ::OutputDebugString("WM_SETFOCUS\n");

        }

        if(WM_NOTIFY==uMsg)

        {

            ::SetFocus(m_hWnd);

        }

        if( uMsg == WM_KILLFOCUS /**/)

        {

            ::OutputDebugString("WM_KILLFOCUS\n");

            if( uMsg == WM_KILLFOCUS /**/)

            {

                //这里肯可能需要优化,因为FindWindow找出来的窗口不一定是本进程的窗口

                HWND hh=::FindWindow(_T("SysMonthCal32"),NULL);

                //Isdel=true;

                if(::IsWindow(hh))

                {

                    MCHITTESTINFO pp;

                    memset(&pp,0,sizeof(pp));

                    GetCursorPos(&pp.pt);

                    ::ScreenToClient(hh,&pp.pt);

                    pp.cbSize=sizeof(pp);

                    MonthCal_HitTest(hh,&pp);

                    //下一个月

                    if(pp.uHit==MCHT_TITLEBTNNEXT)

                    {

                        return 1;

                    }

                    //上一个月

                    if(pp.uHit==MCHT_TITLEBTNPREV)

                    {

                        return 1;

                    }

                }else

                {

                    POINT pt;

                    ::GetCursorPos(&pt); 

                    RECT rt;

                    ::GetWindowRect(m_hWnd,&rt);

                    if(

                        !(pt.x>=rt.left&&pt.x<=rt.right)||

                        !(pt.x>=rt.top&&pt.x<=rt.bottom)

                        )

                    {

                        ::OutputDebugString("CLose\n");

                        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 

            bHandled = FALSE;

 

        if(!bHandled ) 

        {

            return CWindowWnd::HandleMessage(uMsg, wParam, lParam);

        }

        return lRes;

    }


你可能感兴趣的:(DUILIb,bug记录,CDateTimeUI,DuiLib)