* - check UDM_SETBUDDY message
* - check UDM_GETBUDDY message
* - up-down control and buddy control must have the same parent
- * - up-down control notifies its parent window when its position changes with UDN_DELTAPOS + WM_VSCROLL or WM_HSCROLL
* - check UDS_ALIGN[LEFT,RIGHT]...check that width of buddy window is decreased
* - check that UDS_SETBUDDYINT sets the caption of the buddy window when it is changed
* - check that the thousands operator is set for large numbers
* - more stuff to test
*/
-#include "precomp.h"
+#include <windows.h>
+#include <commctrl.h>
+#include <stdio.h>
+
+#include "wine/test.h"
+#include "msg.h"
#define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
static HWND parent_wnd, g_edit;
+static HWND (WINAPI *pCreateUpDownControl)(DWORD, INT, INT, INT, INT,
+ HWND, INT, HINSTANCE, HWND, INT, INT, INT);
static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
{ 0 }
};
+static const struct message test_updown_pos_notifications_seq[] = {
+ { WM_CTLCOLOREDIT, sent|optional },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_SETFOCUS) },
+ { WM_NOTIFY, sent|id, 0, 0, UDN_DELTAPOS },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_UPDATE) },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_CHANGE) },
+ { WM_VSCROLL, sent|wparam, MAKELONG(SB_THUMBPOSITION, 51) },
+ { WM_CTLCOLOREDIT, sent|optional },
+ { WM_VSCROLL, sent|wparam, MAKELONG(SB_ENDSCROLL, 51) },
+ /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
+ { 0 }
+};
+
+static const struct message test_updown_pos_notifications_horz_seq[] = {
+ { WM_CTLCOLOREDIT, sent|optional },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_SETFOCUS) },
+ { WM_NOTIFY, sent|id, 0, 0, UDN_DELTAPOS },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_UPDATE) },
+ { WM_COMMAND, sent|wparam, MAKELONG(0, EN_CHANGE) },
+ { WM_HSCROLL, sent|wparam, MAKELONG(SB_THUMBPOSITION, 51) },
+ { WM_CTLCOLOREDIT, sent|optional },
+ { WM_HSCROLL, sent|wparam, MAKELONG(SB_ENDSCROLL, 51) },
+ /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
+ { 0 }
+};
+
static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LONG defwndproc_counter = 0;
if (defwndproc_counter) msg.flags |= defwinproc;
msg.wParam = wParam;
msg.lParam = lParam;
+ if (message == WM_NOTIFY && lParam)
+ msg.id = ((NMHDR*)lParam)->code;
add_message(sequences, PARENT_SEQ_INDEX, &msg);
}
RECT rect;
GetClientRect(parent_wnd, &rect);
- updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE | style,
- 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), buddy,
- 100, 0, 50);
+ updown = CreateWindowExA(0, UPDOWN_CLASSA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | style,
+ 0, 0, rect.right, rect.bottom,
+ parent_wnd, (HMENU)1, GetModuleHandleA(NULL), NULL);
+ ok(updown != NULL, "Failed to create UpDown control.\n");
if (!updown) return NULL;
+ SendMessageA(updown, UDM_SETBUDDY, (WPARAM)buddy, 0);
+ SendMessageA(updown, UDM_SETRANGE, 0, MAKELONG(100, 0));
+ SendMessageA(updown, UDM_SETPOS, 0, MAKELONG(50, 0));
+
oldproc = (WNDPROC)SetWindowLongPtrA(updown, GWLP_WNDPROC,
(LONG_PTR)updown_subclass_proc);
SetWindowLongPtrA(updown, GWLP_USERDATA, (LONG_PTR)oldproc);
static void test_updown_buddy(void)
{
HWND updown, buddyReturn, buddy;
+ RECT rect, rect2;
WNDPROC proc;
DWORD style;
}
DestroyWindow(updown);
-
DestroyWindow(buddy);
+
+ /* Create with buddy and UDS_HORZ, reset buddy. */
+ updown = create_updown_control(UDS_HORZ, g_edit);
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0);
+ ok(buddyReturn == g_edit, "Unexpected buddy window.\n");
+
+ GetClientRect(updown, &rect);
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0);
+ ok(buddyReturn == g_edit, "Unexpected buddy window.\n");
+
+ GetClientRect(updown, &rect2);
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ /* Remove UDS_HORZ, reset buddy again. */
+ style = GetWindowLongA(updown, GWL_STYLE);
+ SetWindowLongA(updown, GWL_STYLE, style & ~UDS_HORZ);
+ style = GetWindowLongA(updown, GWL_STYLE);
+ ok(!(style & UDS_HORZ), "Unexpected style.\n");
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0);
+ ok(buddyReturn == NULL, "Unexpected buddy window.\n");
+
+ GetClientRect(updown, &rect2);
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ DestroyWindow(updown);
+
+ /* Without UDS_HORZ. */
+ updown = create_updown_control(0, g_edit);
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0);
+ ok(buddyReturn == g_edit, "Unexpected buddy window.\n");
+
+ GetClientRect(updown, &rect);
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0);
+ ok(buddyReturn == g_edit, "Unexpected buddy window.\n");
+
+ GetClientRect(updown, &rect2);
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ DestroyWindow(updown);
+
+ /* Create without buddy. */
+ GetClientRect(parent_wnd, &rect);
+ updown = CreateWindowExA(0, UPDOWN_CLASSA, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | UDS_HORZ,
+ 0, 0, rect.right, rect.bottom, parent_wnd, (HMENU)1, GetModuleHandleA(NULL), NULL);
+ ok(updown != NULL, "Failed to create UpDown control.\n");
+
+ GetClientRect(updown, &rect);
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0);
+ ok(buddyReturn == NULL, "Unexpected buddy window.\n");
+ GetClientRect(updown, &rect2);
+
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ style = GetWindowLongA(updown, GWL_STYLE);
+ SetWindowLongA(updown, GWL_STYLE, style & ~UDS_HORZ);
+
+ GetClientRect(updown, &rect2);
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, (WPARAM)g_edit, 0);
+ ok(buddyReturn == NULL, "Unexpected buddy window.\n");
+ GetClientRect(updown, &rect);
+
+ buddyReturn = (HWND)SendMessageA(updown, UDM_SETBUDDY, 0, 0);
+ ok(buddyReturn == g_edit, "Unexpected buddy window.\n");
+ GetClientRect(updown, &rect2);
+todo_wine
+ ok(EqualRect(&rect, &rect2), "Unexpected window rect.\n");
+
+ DestroyWindow(updown);
}
static void test_updown_base(void)
r = SendMessageA(updown, UDM_SETPOS, 0, 10);
expect(50, r);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text);
r = SendMessageA(updown, UDM_SETBASE, 16, 0);
expect(10, r);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
/* FIXME: currently hex output isn't properly formatted, but for this
test only change from initial text matters */
ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text);
style = GetWindowLongA(updown, GWL_STYLE);
ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n");
SendMessageA(updown, UDM_SETPOS, 0, 20);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
ok(lstrlenA(text) == 0, "Expected empty string\n");
DestroyWindow(updown);
/* creating with UDS_SETBUDDYINT */
updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
/* 50 is initial value here */
ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text);
/* now remove style flag */
style = GetWindowLongA(updown, GWL_STYLE);
SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT);
SendMessageA(updown, UDM_SETPOS, 0, 20);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text);
/* set edit text directly, check position */
strcpy(text, "10");
style = GetWindowLongA(updown, GWL_STYLE);
SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
SendMessageA(updown, UDM_SETPOS, 0, 30);
- GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+ GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text);
DestroyWindow(updown);
}
-START_TEST(updown)
+static void test_CreateUpDownControl(void)
+{
+ HWND updown, buddy;
+ DWORD range, pos;
+ RECT rect;
+
+ GetClientRect(parent_wnd, &rect);
+ updown = pCreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE,
+ 0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), g_edit, 100, 10, 50);
+ ok(updown != NULL, "Failed to create control.\n");
+
+ buddy = (HWND)SendMessageA(updown, UDM_GETBUDDY, 0, 0);
+ ok(buddy == g_edit, "Unexpected buddy window.\n");
+
+ range = SendMessageA(updown, UDM_GETRANGE, 0, 0);
+ ok(range == MAKELONG(100, 10), "Unexpected range.\n");
+
+ pos = SendMessageA(updown, UDM_GETPOS, 0, 0);
+ ok(pos == MAKELONG(50, 1), "Unexpected position.\n");
+
+ DestroyWindow(updown);
+}
+
+static void test_updown_pos_notifications(void)
+{
+ HWND updown;
+ RECT rect;
+ UINT x, y;
+ int result;
+
+ /* test updown control notifications without UDS_HORZ style */
+ updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT, g_edit);
+ SetFocus(updown);
+ flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+ /* click on the up-arrow button */
+ GetClientRect(updown, &rect);
+ x = rect.left + (rect.right - rect.left) / 2;
+ y = rect.top + (rect.bottom - rect.top) / 4;
+ result = SendMessageA(updown, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
+ expect(result, 0);
+ result = SendMessageA(updown, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
+ expect(result, 0);
+
+ ok_sequence(sequences, PARENT_SEQ_INDEX, test_updown_pos_notifications_seq,
+ "test updown to parent notify (vertical)", FALSE);
+
+ DestroyWindow(updown);
+
+ /* test updown control notifications with UDS_HORZ style */
+ updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_HORZ, g_edit);
+ SetFocus(updown);
+ flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+ /* click on the right-arrow button */
+ GetClientRect(updown, &rect);
+ x = rect.left + (rect.right - rect.left) * 3 / 4;
+ y = rect.top + (rect.bottom - rect.top) / 2;
+ result = SendMessageA(updown, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
+ expect(result, 0);
+ result = SendMessageA(updown, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
+ expect(result, 0);
+
+ ok_sequence(sequences, PARENT_SEQ_INDEX, test_updown_pos_notifications_horz_seq,
+ "test updown to parent notify (horizontal)", FALSE);
+
+ DestroyWindow(updown);
+}
+
+static void init_functions(void)
{
- HMODULE mod = GetModuleHandleA("comctl32.dll");
+ HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
+
+#define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
+#define X2(f, ord) p##f = (void*)GetProcAddress(hComCtl32, (const char *)ord);
+ X(CreateUpDownControl);
+ X2(SetWindowSubclass, 410);
+#undef X
+#undef X2
+}
- pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410);
+START_TEST(updown)
+{
+ init_functions();
- InitCommonControls();
init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
parent_wnd = create_parent_window();
test_updown_base();
test_updown_unicode();
test_UDS_SETBUDDYINT();
+ test_CreateUpDownControl();
+ test_updown_pos_notifications();
DestroyWindow(g_edit);
DestroyWindow(parent_wnd);