1
votes

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.

2
Have you tried Windows.mouse_event()?Gerry Coll
How are you displaying the context-menu? Has it been assigned to the TreeView's PopupMenu property?Stijn Sanders
It must be something specific you do, because this is not an uncommon operation. Maybe you should try a minimal test application and see how you can reproduce it with as little code as possible.Lars Truijens

2 Answers

0
votes

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.

0
votes

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.