Commit 390a248e authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

comctl32: Return the number of characters copied in WM_GETTEXT even if the buffer is too small.

parent b9d955b8
......@@ -1016,12 +1016,17 @@ STATUSBAR_WMGetText (const STATUS_INFO *infoPtr, INT size, LPWSTR buf)
len = strlenW (infoPtr->parts[0].text);
if (size > len) {
if (!size)
return len;
else if (size > len) {
strcpyW (buf, infoPtr->parts[0].text);
return len;
}
return -1;
else {
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 );
}
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)
{
hinst = GetModuleHandleA(NULL);
......@@ -483,4 +511,5 @@ START_TEST(status)
test_create();
test_height();
test_status_ownerdraw();
test_gettext();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment