comctl32: Return the number of characters copied in WM_GETTEXT even if the buffer is too small.
This commit is contained in:
parent
b9d955b86d
commit
390a248e06
|
@ -1016,12 +1016,17 @@ STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
|
||||||
|
|
||||||
len = strlenW (infoPtr->parts[0].text);
|
len = strlenW (infoPtr->parts[0].text);
|
||||||
|
|
||||||
if (size > len) {
|
if (!size)
|
||||||
|
return len;
|
||||||
|
else if (size > len) {
|
||||||
strcpyW (buf, infoPtr->parts[0].text);
|
strcpyW (buf, infoPtr->parts[0].text);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return -1;
|
memcpy (buf, infoPtr->parts[0].text, (size - 1) * sizeof(WCHAR));
|
||||||
|
buf[size - 1] = 0;
|
||||||
|
return size - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,34 @@ static void test_status_ownerdraw(void)
|
||||||
SetWindowLongPtr( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
|
SetWindowLongPtr( g_hMainWnd, GWLP_WNDPROC, (LONG_PTR)g_wndproc_saved );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_gettext(void)
|
||||||
|
{
|
||||||
|
HWND hwndStatus = CreateWindow(SUBCLASS_NAME, NULL, WS_CHILD|WS_VISIBLE,
|
||||||
|
0, 0, 300, 20, g_hMainWnd, NULL, NULL, NULL);
|
||||||
|
char buf[5];
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = SendMessage(hwndStatus, SB_SETTEXT, 0, (LPARAM)"Text");
|
||||||
|
expect(TRUE, r);
|
||||||
|
r = SendMessage(hwndStatus, WM_GETTEXTLENGTH, 0, 0);
|
||||||
|
expect(4, r);
|
||||||
|
/* A size of 0 returns the length of the text */
|
||||||
|
r = SendMessage(hwndStatus, WM_GETTEXT, 0, 0);
|
||||||
|
expect(4, r);
|
||||||
|
/* A size of 1 only stores the NULL terminator */
|
||||||
|
buf[0] = 0xa;
|
||||||
|
r = SendMessage(hwndStatus, WM_GETTEXT, 1, (LPARAM)buf);
|
||||||
|
expect(0, r);
|
||||||
|
ok(!buf[0], "expected empty buffer\n");
|
||||||
|
/* A size of 2 returns a length 1 */
|
||||||
|
r = SendMessage(hwndStatus, WM_GETTEXT, 2, (LPARAM)buf);
|
||||||
|
expect(1, r);
|
||||||
|
r = SendMessage(hwndStatus, WM_GETTEXT, sizeof(buf), (LPARAM)buf);
|
||||||
|
expect(4, r);
|
||||||
|
ok(!strcmp(buf, "Text"), "expected Text, got %s\n", buf);
|
||||||
|
DestroyWindow(hwndStatus);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(status)
|
START_TEST(status)
|
||||||
{
|
{
|
||||||
hinst = GetModuleHandleA(NULL);
|
hinst = GetModuleHandleA(NULL);
|
||||||
|
@ -483,4 +511,5 @@ START_TEST(status)
|
||||||
test_create();
|
test_create();
|
||||||
test_height();
|
test_height();
|
||||||
test_status_ownerdraw();
|
test_status_ownerdraw();
|
||||||
|
test_gettext();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue