views:

434

answers:

2

The situation is a bit hard to explain, I'll do my best.

I have a ListView, which has a right click menu. One of the menu item opens a new non-modal form. Usually the user clicks the menu item, new form shows up and is fine.

However, if user brings up right click menu by clicking on an area of the ListView where there is no ListItem showing, e.g. below the last ListItem, then click the menu item, the non-modal form shows up, but the cursor seems to be stuck in a left button mouse down state in the ListView, i.e. The non-modal form is at the front, but when I move the mouse, it makes those drag area rectangles in the background ListView, as if the mouse button is being held down.

I've tried using various BringToFront, SetFocus, and tried to use SendMessage to simulate mouse clicks to get around it with no success.

A: 

Sounds to me like the list view is not properly handling the WM_CANCELMODE message which tells it that it has lost focus while it had mouse capture. Not sure how you can resolve this except perhaps by sending it a mouse up message.

mj2008
A: 

Found the problem. Upon further investigation the ListView was actually a custom descendant of TListView, and it had its own (buggy) way of handling popup menus.

I switched it to use TListView's default TListView.PopupMenu and it works all sweet.

Thanks Lars Truijens for suggesting building a minimal test app, that led me to the right direction.

Robo