Demonpiggies
Programmer
I cannot get the OnLButtonUp to fire unless I've moved the mouse. It will fire after the DoubleClick event and after MouseMove event but it will fire when user clicks on an item. It seems dependent on MouseMove. why? (click down, OnLButtonDown fires, Button clicks up, nothing) Is there something I missed or need to move somewhere else? I've been stuck here for about 2 days now any help would be GREAT!!!
ASSUME: m_iOld/NewSelection is -1 by default
ASSUME: m_iOld/NewSelection is -1 by default
Code:
void CDeviceListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
//Call to the base class
CListCtrl::OnLButtonDown(nFlags, point);
//capture mouse movements
SetCapture();
//Set flag to off
m_bIsSourceSelectionDone = false;
//Get position of newly selected item
m_iNewSelection = GetSelectionMark();
TRACE( _T("OnLButtonDown: new: %d old: %d\n" ), m_iNewSelection, m_iOldSelection );
//Flag for the other two listeners
m_bIsDraggingAction = true;
//Set new item to selected
SetItemState( m_iNewSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
}
void CDeviceListCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
//Call to the base class
CListCtrl::OnMouseMove(nFlags, point);
//Leave if not selecting a source
if( !m_bIsDraggingAction || !(nFlags & MK_LBUTTON) )
{
return;
}
TRACE( _T("OnMouseMove: index %d old: %d\n" ), m_iNewSelection, m_iOldSelection );
// Get the current mouse location and convert it to client coordinates.
CPoint pos( ::GetMessagePos() );
ScreenToClient(&pos);
//For a basic HitTest on the item's rectangle
CRect rectSelection;
GetItemRect(m_iNewSelection, &rectSelection, LVIR_BOUNDS);
//If the cursor happens to be on the newly selected button then depress it
//else keep the old button down
if( rectSelection.PtInRect(pos) )
{
SetItemState( m_iNewSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
else if( m_iOldSelection != -1 )
{
SetItemState( m_iOldSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
else
{
UnselectDevice();
}
}
void CDeviceListCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
TRACE( _T("OnLButtonUP: index %d old: %d\n" ), m_iNewSelection, m_iOldSelection );
if( !m_bIsDraggingAction )
{
return;
}
// Get the current mouse location and convert it to client coordinates.
CPoint pos( ::GetMessagePos() );
ScreenToClient(&pos);
//For a basic HitTest on the item's rectangle
CRect rectSelection;
GetItemRect(m_iNewSelection, &rectSelection, LVIR_BOUNDS);
//If the buttonUp happens on the new selected button then depress it
//else keep the old button down
if( rectSelection.PtInRect(pos) )
{
UnselectDevice();
m_bIsSourceSelectionDone = true;
SetItemState( m_iNewSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
m_iOldSelection = m_iNewSelection;
}
else if( m_iOldSelection != -1 )
{
SetItemState( m_iOldSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
else
{
UnselectDevice();
}
m_bIsDraggingAction = false;
m_iNewSelection = -1;
ReleaseCapture();
//Call to the base class
CListCtrl::OnLButtonUp(nFlags, point);
}