Question

In my mfc dialog based application, there is a CListCtrl. I need to disable a button when the user clicks on an empty item in the list control.I used NM_CLICK message and achieved this. But if the user drags the mouse out of list control area and releases the mouse this doesn't work. I found the reason that NM_CLICK will be called only on receiving button up message.Is there any other solution for this.

Was it helpful?

Solution 4

I found the solution for the issue. There is a message which can be handled if the user drags the mouse using left button namely LVN_BEGINDRAG.By handling this message in the OnBeginDrag function I update the button status.So the button gets updated as soon as the user tries to drag the mouse.The code is as below: In the header add

afx_msg void OnBeginDrag( NMHDR* pNMHDR, LRESULT *pResult );

In the implementation add message map and corresponding function:

BEGIN_MESSAGE_MAP( .. )

ON_NOTIFY( LVN_BEGINDRAG, IDC_LIST1, OnBeginDrag )

END_MESSAGE_MAP

OnBeginDrag( .... )

{

Updatebutton();

}

It solves the issue. thank you all for the support.

OTHER TIPS

But if the user drags the mouse out of list control area and releases the mouse this doesn't work.

That is entirely by design, and you shouldn't want those clicks to "count". This is the only way that a user has of changing her mind in the middle of a click. It works like this:

  • Start to click on an object (or the empty space) in the list box control
  • Change your mind
  • While still holding down the mouse button (i.e., before committing your click), drag the mouse pointer outside of the bounds of the control
  • Think: Whew! That was a close call!

You'll notice that, in Windows, an action never happens until the mouse button is released (often called "MouseUp"). If this wasn't supported, there would be no way for the user to bail out early of an action, which is a critical feature of any user interface.

There are some feasible options. In parent dialog, MouseUp Handler function can use for this.

afx_msg void OnLButtonUp(UINT nFlags, CPoint point);

By using point, you can check whether mouse releasing is occured CListCtrl. If it is, you just disable the button.

Also, WindowFromPoint can be another option.

static CWnd* PASCAL WindowFromPoint(POINT point);

In such as a OnMouseMove, if you use this function, you can check the window is pointed by mouse.

Implement a LVN_ITEMCHANGED handler, and in that handler disable the button as soon as the selected item count is zero.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top