< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_List.cpp

Print this page

        

@@ -476,22 +476,25 @@
 }
 
 MsgRouting AwtList::HandleEvent(MSG *msg, BOOL synthetic)
 {
     if (IsFocusingMouseMessage(msg)) {
-        LONG item = static_cast<LONG>(SendListMessage(LB_ITEMFROMPOINT, 0, msg->lParam));
-        if (item != LB_ERR) {
+        if (GetCount() > 0) {
+            LONG result = static_cast<LONG>(SendListMessage(LB_ITEMFROMPOINT, 0, msg->lParam));
+            WORD item = LOWORD(result);
+            if (item < GetCount()) {
             if (isMultiSelect) {
                 if (IsItemSelected(item)) {
                     Deselect(item);
                 } else {
                     Select(item);
                 }
             } else {
                 Select(item);
             }
         }
+        }
         delete msg;
         return mrConsume;
     }
     if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN) {
         WmNotify(LBN_DBLCLK);
< prev index next >