CListBox hotlight跟踪

时间:2015-05-30 08:28:07

标签: clistbox

我使用DrawItem ()重绘CListBoxods_hotlight在win7 / win8中不起作用。 我该怎样做CListBox hotlight tracking?

1 个答案:

答案 0 :(得分:0)

OK ,I solved this now .... ,Code posted below :

extern "C" WINUSERAPI BOOL WINAPI TrackMouseEvent (LPTRACKMOUSEEVENT lpEventTrack);

    void CListBoxCS::OnMouseMove(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
        TRACKMOUSEEVENT tme;
        tme.cbSize      = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags     = TME_HOVER | TME_LEAVE;
        tme.dwHoverTime = HOVER_DEFAULT;
        tme.hwndTrack   = m_hWnd;
        tme.dwHoverTime = 1;
        TrackMouseEvent (&tme);

        BOOL        bOut = TRUE;
        short       index;

        index = (short) ItemFromPoint (point,bOut);
        if (FALSE == bOut) {
            if (m_ihot != index) {
                m_ihot = index;
                //printf ("index = %d \n",m_ihot);
                Invalidate (FALSE);
            }
        } else {
            //printf ( "out \n" );
        }
    }

    void CListBoxCS::OnMouseLeave (void) 
    {
        //printf ( "mouse leave \n" );
        m_ihot = -1;
    }

void CListBoxCS::DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    // some judgements here .....

    // some preparations 

    // hot light code ...
    if ((act & ODA_SELECT) || (act & ODA_DRAWENTIRE)) {
        if (lpDIS->itemState & ODS_SELECTED) { 
            dc.FillSolidRect (&lpDIS->rcItem,(RGB (209, 232, 255)));
        } else { 
            dc.FillSolidRect (&lpDIS->rcItem,(RGB (230, 230, 230)));
        } 

        if (m_ihot == lpDrawItemStruct->itemID) {
            dc.FillSolidRect (&lpDIS->rcItem,(RGB (229, 243, 251)));
        }
     }
     // something U like to do ....
}