With LBS_NODATA listboxes, LB_GETTEXT always retrieves the value zero, LB_GETITEMDATA returns zero, and LB_SETITEMDATA does nothing. However, all of them do check for valid indices and return LB_ERR if not valid.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/comctl32/listbox.c | 7 ++++--- dlls/comctl32/tests/listbox.c | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c index 5e33466..ab01430 100644 --- a/dlls/comctl32/listbox.c +++ b/dlls/comctl32/listbox.c @@ -762,7 +762,8 @@ static LRESULT LISTBOX_GetText( LB_DESCR *descr, INT index, LPWSTR buffer, BOOL } else { if (buffer) - *((DWORD *)buffer) = *(DWORD *)&descr->items[index].data; + *((DWORD *)buffer) = (descr->style & LBS_NODATA) ? 0 : + *(DWORD *)&descr->items[index].data; len = sizeof(DWORD); } return len; @@ -2635,7 +2636,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam, SetLastError(ERROR_INVALID_INDEX); return LB_ERR; } - return descr->items[wParam].data; + return (descr->style & LBS_NODATA) ? 0 : descr->items[wParam].data;
case LB_SETITEMDATA: if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) @@ -2643,7 +2644,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam, SetLastError(ERROR_INVALID_INDEX); return LB_ERR; } - descr->items[wParam].data = lParam; + if (!(descr->style & LBS_NODATA)) descr->items[wParam].data = lParam; /* undocumented: returns TRUE, not LB_OKAY (0) */ return TRUE;
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index 7429144..87b3ec0 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -1876,19 +1876,19 @@ static void test_nodata( void ) data = 0xdeadbeef; ret = SendMessageA(listbox, LB_GETTEXT, valid_idx[i], (LPARAM)&data); ok(ret <= sizeof(data), "got %d\n", ret); - todo_wine ok(data == 0, "LB_GETTEXT should retrieve 0 with LBS_NODATA, got 0x%llx\n", data); + ok(data == 0, "LB_GETTEXT should retrieve 0 with LBS_NODATA, got 0x%llx\n", data); } ret = SendMessageA(listbox, LB_GETITEMDATA, valid_idx[i], 0); - todo_wine ok(ret == 0, "LB_GETITEMDATA should return 0 with LBS_NODATA, got %d\n", ret); + ok(ret == 0, "LB_GETITEMDATA should return 0 with LBS_NODATA, got %d\n", ret); }
/* test more invalid messages with LBS_NODATA */ ret = SendMessageA(listbox, LB_FINDSTRING, 1, 42); - todo_wine ok(ret == LB_ERR, "got %d\n", ret); + ok(ret == LB_ERR, "got %d\n", ret); ret = SendMessageA(listbox, LB_FINDSTRINGEXACT, 1, 42); - todo_wine ok(ret == LB_ERR, "got %d\n", ret); + ok(ret == LB_ERR, "got %d\n", ret); ret = SendMessageA(listbox, LB_SELECTSTRING, 1, 42); - todo_wine ok(ret == LB_ERR, "got %d\n", ret); + ok(ret == LB_ERR, "got %d\n", ret);
DestroyWindow(listbox); }