I have a listview that is single selection only, so I use %LVM_GETSELECTIONMARK to get the selected item. If no item is selected the code does nothing, and if selected it performs an action using values from the selected item. %LVM_GETSELECTIONMARK is supposed to return -1 if an item isn't selected, but it is possible to Select an item and then click a blank area of the listview to select no item...this is fine and works nice if they change their mind, etc. The problem is that when they click in a blank area the selection is gone, but the focus/dotted rectangle remains and when %LVM_GETSELECTIONMARK is called it returns the item index with the focus rectangle still.
To fix this I decided to use %LVN_ITEMCHANGED and expected it to have a @nmlv.uNewState with %LVIS_SELECTED off and %LVIS_FOCUSED on...or maybe even an old state of selected and a new of focused, etc...but this isn't the case. In fact, the only thing I have found to work that removes this phantom Focus Rectangle is:
I would think this would make an endless loop since once changed to 0 it would fire again with a new state of 0 and be changed again, etc...but it doesn't. Is this supposed to work like this?
To fix this I decided to use %LVN_ITEMCHANGED and expected it to have a @nmlv.uNewState with %LVIS_SELECTED off and %LVIS_FOCUSED on...or maybe even an old state of selected and a new of focused, etc...but this isn't the case. In fact, the only thing I have found to work that removes this phantom Focus Rectangle is:
Code:
Case %LVN_ITEMCHANGED nmlv= lParam If ((@nmlv.uNewState And %LVIS_SELECTED) = 0) And ((@nmlv.uNewState And %LVIS_FOCUSED) = 0) Then ' clicked off all items lvi.stateMask= %LVIS_FOCUSED Or %LVIS_SELECTED SendMessage(HWND_ListView, %LVM_SETITEMSTATE, @nmlv.iItem, VarPtr(lvi)) End If
Comment