Delphi ListView "stuck" on mouse event
The situation is a little difficult to explain, I will do my best.
I have a ListView that has a context menu. One of the menu items opens a new modeless form. Usually the user clicks on a menu item, a new form appears and that's okay.
However, if the user brings up the right-click menu by clicking on an area of the ListView where there is no ListItem, for example. below the last ListItem, then click the menu item, a modeless form appears, but the cursor seems to be stuck on the left mouse button click in the ListView i.e. the modeless form is in front, but when I move the mouse, it makes those drop area rectangles in the background of the ListView as if the mouse button was being held down.
I have tried various BringToFront, SetFocus and tried using SendMessage to simulate mouse clicks to get around it without success.
a source to share
Found the problem. After further exploring, ListView was actually a custom TListView thread and had its own (buggy) way of handling popup menus.
I switched it to use the default TListView.PopupMenu and it works all sweetly.
Thanks to Lars Truijens for suggesting building a minimal test application, which led me in the right direction.
a source to share
It seems to me that the WM_CANCELMODE message is not properly handled in the list view , which says it lost focus when it grabbed the mouse, Not sure how you can solve this, except maybe by sending a mouse message.
a source to share