0f78bbec3096de131ab1e3e5bf737a52f8f20152
[reactos.git] / rostests / winetests / comctl32 / comboex.c
1 /* Unit test suite for comboex control.
2 *
3 * Copyright 2005 Jason Edmeades
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include <assert.h>
21 //#include <windows.h>
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winuser.h>
26 #include <commctrl.h>
27
28 //#include "wine/test.h"
29 #include "msg.h"
30
31 #define EDITBOX_SEQ_INDEX 0
32 #define NUM_MSG_SEQUENCES 1
33
34 #define EDITBOX_ID 0
35
36 #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
37
38 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
39
40 static HWND hComboExParentWnd;
41 static HINSTANCE hMainHinst;
42 static const char ComboExTestClass[] = "ComboExTestClass";
43
44 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
45
46 #define MAX_CHARS 100
47 static char *textBuffer = NULL;
48
49 static BOOL received_end_edit = FALSE;
50
51 static HWND createComboEx(DWORD style) {
52 return CreateWindowExA(0, WC_COMBOBOXEXA, NULL, style, 0, 0, 300, 300,
53 hComboExParentWnd, NULL, hMainHinst, NULL);
54 }
55
56 static LONG addItem(HWND cbex, int idx, LPTSTR text) {
57 COMBOBOXEXITEM cbexItem;
58 memset(&cbexItem, 0x00, sizeof(cbexItem));
59 cbexItem.mask = CBEIF_TEXT;
60 cbexItem.iItem = idx;
61 cbexItem.pszText = text;
62 cbexItem.cchTextMax = 0;
63 return SendMessage(cbex, CBEM_INSERTITEM, 0, (LPARAM)&cbexItem);
64 }
65
66 static LONG setItem(HWND cbex, int idx, LPTSTR text) {
67 COMBOBOXEXITEM cbexItem;
68 memset(&cbexItem, 0x00, sizeof(cbexItem));
69 cbexItem.mask = CBEIF_TEXT;
70 cbexItem.iItem = idx;
71 cbexItem.pszText = text;
72 cbexItem.cchTextMax = 0;
73 return SendMessage(cbex, CBEM_SETITEM, 0, (LPARAM)&cbexItem);
74 }
75
76 static LONG delItem(HWND cbex, int idx) {
77 return SendMessage(cbex, CBEM_DELETEITEM, idx, 0);
78 }
79
80 static LONG getItem(HWND cbex, int idx, COMBOBOXEXITEM *cbItem) {
81 memset(cbItem, 0x00, sizeof(COMBOBOXEXITEM));
82 cbItem->mask = CBEIF_TEXT;
83 cbItem->pszText = textBuffer;
84 cbItem->iItem = idx;
85 cbItem->cchTextMax = 100;
86 return SendMessage(cbex, CBEM_GETITEM, 0, (LPARAM)cbItem);
87 }
88
89 static LRESULT WINAPI editbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
90 {
91 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
92 static LONG defwndproc_counter = 0;
93 LRESULT ret;
94 struct message msg;
95
96 msg.message = message;
97 msg.flags = sent|wparam|lparam;
98 if (defwndproc_counter) msg.flags |= defwinproc;
99 msg.wParam = wParam;
100 msg.lParam = lParam;
101 msg.id = EDITBOX_ID;
102
103 if (message != WM_PAINT &&
104 message != WM_ERASEBKGND &&
105 message != WM_NCPAINT &&
106 message != WM_NCHITTEST &&
107 message != WM_GETTEXT &&
108 message != WM_GETICON &&
109 message != WM_DEVICECHANGE)
110 {
111 add_message(sequences, EDITBOX_SEQ_INDEX, &msg);
112 }
113
114 defwndproc_counter++;
115 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
116 defwndproc_counter--;
117 return ret;
118 }
119
120 static HWND subclass_editbox(HWND hwndComboEx)
121 {
122 WNDPROC oldproc;
123 HWND hwnd;
124
125 hwnd = (HWND)SendMessage(hwndComboEx, CBEM_GETEDITCONTROL, 0, 0);
126 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC,
127 (LONG_PTR)editbox_subclass_proc);
128 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)oldproc);
129
130 return hwnd;
131 }
132
133 static void test_comboboxex(void) {
134 HWND myHwnd = 0;
135 LONG res = -1;
136 COMBOBOXEXITEM cbexItem;
137 static TCHAR first_item[] = {'F','i','r','s','t',' ','I','t','e','m',0},
138 second_item[] = {'S','e','c','o','n','d',' ','I','t','e','m',0},
139 third_item[] = {'T','h','i','r','d',' ','I','t','e','m',0},
140 middle_item[] = {'B','e','t','w','e','e','n',' ','F','i','r','s','t',' ','a','n','d',' ',
141 'S','e','c','o','n','d',' ','I','t','e','m','s',0},
142 replacement_item[] = {'B','e','t','w','e','e','n',' ','F','i','r','s','t',' ','a','n','d',' ',
143 'S','e','c','o','n','d',' ','I','t','e','m','s',0},
144 out_of_range_item[] = {'O','u','t',' ','o','f',' ','R','a','n','g','e',' ','I','t','e','m',0};
145
146 /* Allocate space for result */
147 textBuffer = HeapAlloc(GetProcessHeap(), 0, MAX_CHARS);
148
149 /* Basic comboboxex test */
150 myHwnd = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
151
152 /* Add items onto the end of the combobox */
153 res = addItem(myHwnd, -1, first_item);
154 ok(res == 0, "Adding simple item failed (%d)\n", res);
155 res = addItem(myHwnd, -1, second_item);
156 ok(res == 1, "Adding simple item failed (%d)\n", res);
157 res = addItem(myHwnd, 2, third_item);
158 ok(res == 2, "Adding simple item failed (%d)\n", res);
159 res = addItem(myHwnd, 1, middle_item);
160 ok(res == 1, "Inserting simple item failed (%d)\n", res);
161
162 /* Add an item completely out of range */
163 res = addItem(myHwnd, 99, out_of_range_item);
164 ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
165 res = addItem(myHwnd, 5, out_of_range_item);
166 ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
167 /* Removed: Causes traps on Windows XP
168 res = addItem(myHwnd, -2, "Out Of Range Item");
169 ok(res == -1, "Adding out of range worked unexpectedly (%ld)\n", res);
170 */
171
172 /* Get an item completely out of range */
173 res = getItem(myHwnd, 99, &cbexItem);
174 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
175 res = getItem(myHwnd, 4, &cbexItem);
176 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
177 res = getItem(myHwnd, -2, &cbexItem);
178 ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
179
180 /* Get an item in range */
181 res = getItem(myHwnd, 0, &cbexItem);
182 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
183 ok(strcmp(first_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
184
185 res = getItem(myHwnd, 1, &cbexItem);
186 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
187 ok(strcmp(middle_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
188
189 res = getItem(myHwnd, 2, &cbexItem);
190 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
191 ok(strcmp(second_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
192
193 res = getItem(myHwnd, 3, &cbexItem);
194 ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
195 ok(strcmp(third_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);
196
197 /* Set an item completely out of range */
198 res = setItem(myHwnd, 99, replacement_item);
199 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
200 res = setItem(myHwnd, 4, replacement_item);
201 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
202 res = setItem(myHwnd, -2, replacement_item);
203 ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
204
205 /* Set an item in range */
206 res = setItem(myHwnd, 0, replacement_item);
207 ok(res != 0, "Setting first item failed (%d)\n", res);
208 res = setItem(myHwnd, 3, replacement_item);
209 ok(res != 0, "Setting last item failed (%d)\n", res);
210
211 /* Remove items completely out of range (4 items in control at this point) */
212 res = delItem(myHwnd, -1);
213 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
214 res = delItem(myHwnd, 4);
215 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
216
217 /* Remove items in range (4 items in control at this point) */
218 res = delItem(myHwnd, 3);
219 ok(res == 3, "Deleting using out of range index failed (%d)\n", res);
220 res = delItem(myHwnd, 0);
221 ok(res == 2, "Deleting using out of range index failed (%d)\n", res);
222 res = delItem(myHwnd, 0);
223 ok(res == 1, "Deleting using out of range index failed (%d)\n", res);
224 res = delItem(myHwnd, 0);
225 ok(res == 0, "Deleting using out of range index failed (%d)\n", res);
226
227 /* Remove from an empty box */
228 res = delItem(myHwnd, 0);
229 ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
230
231
232 /* Cleanup */
233 HeapFree(GetProcessHeap(), 0, textBuffer);
234 DestroyWindow(myHwnd);
235 }
236
237 static void test_WM_LBUTTONDOWN(void)
238 {
239 HWND hComboEx, hCombo, hEdit, hList;
240 COMBOBOXINFO cbInfo;
241 UINT x, y, item_height;
242 LRESULT result;
243 UINT i;
244 int idx;
245 RECT rect;
246 WCHAR buffer[3];
247 static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
248 static const WCHAR stringFormat[] = {'%','2','d','\0'};
249 BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO);
250
251 pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo");
252 if (!pGetComboBoxInfo){
253 win_skip("GetComboBoxInfo is not available\n");
254 return;
255 }
256
257 hComboEx = CreateWindowExA(0, WC_COMBOBOXEXA, NULL,
258 WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150,
259 hComboExParentWnd, NULL, hMainHinst, NULL);
260
261 for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){
262 COMBOBOXEXITEMW cbexItem;
263 wsprintfW(buffer, stringFormat, choices[i]);
264
265 memset(&cbexItem, 0x00, sizeof(cbexItem));
266 cbexItem.mask = CBEIF_TEXT;
267 cbexItem.iItem = i;
268 cbexItem.pszText = buffer;
269 cbexItem.cchTextMax = 0;
270 ok(SendMessageW(hComboEx, CBEM_INSERTITEMW, 0, (LPARAM)&cbexItem) >= 0,
271 "Failed to add item %d\n", i);
272 }
273
274 hCombo = (HWND)SendMessage(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
275 hEdit = (HWND)SendMessage(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
276
277 cbInfo.cbSize = sizeof(COMBOBOXINFO);
278 result = pGetComboBoxInfo(hCombo, &cbInfo);
279 ok(result, "Failed to get combobox info structure. LastError=%d\n",
280 GetLastError());
281 hList = cbInfo.hwndList;
282
283 ok(GetFocus() == hComboExParentWnd,
284 "Focus not on Main Window, instead on %p\n", GetFocus());
285
286 /* Click on the button to drop down the list */
287 x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2;
288 y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2;
289 result = SendMessage(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
290 ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
291 GetLastError());
292 ok(GetFocus() == hCombo ||
293 broken(GetFocus() != hCombo), /* win98 */
294 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
295 GetFocus());
296 ok(SendMessage(hComboEx, CB_GETDROPPEDSTATE, 0, 0),
297 "The dropdown list should have appeared after clicking the button.\n");
298 idx = SendMessage(hCombo, CB_GETTOPINDEX, 0, 0);
299 ok(idx == 0, "For TopIndex expected %d, got %d\n", 0, idx);
300
301 result = SendMessage(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
302 ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n",
303 GetLastError());
304 ok(GetFocus() == hCombo ||
305 broken(GetFocus() != hCombo), /* win98 */
306 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
307 GetFocus());
308
309 /* Click on the 5th item in the list */
310 item_height = SendMessage(hCombo, CB_GETITEMHEIGHT, 0, 0);
311 ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n");
312 x = rect.left + (rect.right-rect.left)/2;
313 y = item_height/2 + item_height*4;
314 result = SendMessage(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
315 ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n",
316 GetLastError());
317 ok(GetFocus() == hCombo ||
318 broken(GetFocus() != hCombo), /* win98 */
319 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
320 GetFocus());
321
322 result = SendMessage(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
323 ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
324 GetLastError());
325 ok(GetFocus() == hCombo ||
326 broken(GetFocus() != hCombo), /* win98 */
327 "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n",
328 GetFocus());
329 ok(SendMessage(hComboEx, CB_GETDROPPEDSTATE, 0, 0),
330 "The dropdown list should still be visible.\n");
331
332 result = SendMessage(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
333 ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n",
334 GetLastError());
335 todo_wine ok(GetFocus() == hEdit ||
336 broken(GetFocus() == hCombo), /* win98 */
337 "Focus not on ComboBoxEx's Edit Control, instead on %p\n",
338 GetFocus());
339
340 result = SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0);
341 ok(!result ||
342 broken(result != 0), /* win98 */
343 "The dropdown list should have been rolled up.\n");
344 idx = SendMessage(hComboEx, CB_GETCURSEL, 0, 0);
345 ok(idx == 4 ||
346 broken(idx == -1), /* win98 */
347 "Current Selection: expected %d, got %d\n", 4, idx);
348 ok(received_end_edit, "Expected to receive a CBEN_ENDEDIT message\n");
349
350 SetFocus( hComboExParentWnd );
351 ok( GetFocus() == hComboExParentWnd, "got %p\n", GetFocus() );
352 SetFocus( hComboEx );
353 ok( GetFocus() == hEdit, "got %p\n", GetFocus() );
354
355 DestroyWindow(hComboEx);
356 }
357
358 static void test_CB_GETLBTEXT(void)
359 {
360 HWND hCombo;
361 CHAR buff[1];
362 COMBOBOXEXITEMA item;
363 LRESULT ret;
364
365 hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
366
367 /* set text to null */
368 addItem(hCombo, 0, NULL);
369
370 buff[0] = 'a';
371 item.mask = CBEIF_TEXT;
372 item.iItem = 0;
373 item.pszText = buff;
374 item.cchTextMax = 1;
375 ret = SendMessage(hCombo, CBEM_GETITEMA, 0, (LPARAM)&item);
376 ok(ret != 0, "CBEM_GETITEM failed\n");
377 ok(buff[0] == 0, "\n");
378
379 ret = SendMessage(hCombo, CB_GETLBTEXTLEN, 0, 0);
380 ok(ret == 0, "Expected zero length\n");
381
382 ret = SendMessage(hCombo, CB_GETLBTEXTLEN, 0, 0);
383 ok(ret == 0, "Expected zero length\n");
384
385 buff[0] = 'a';
386 ret = SendMessage(hCombo, CB_GETLBTEXT, 0, (LPARAM)buff);
387 ok(ret == 0, "Expected zero length\n");
388 ok(buff[0] == 0, "Expected null terminator as a string, got %s\n", buff);
389
390 DestroyWindow(hCombo);
391 }
392
393 static void test_WM_WINDOWPOSCHANGING(void)
394 {
395 HWND hCombo;
396 WINDOWPOS wp;
397 RECT rect;
398 int combo_height;
399 int ret;
400
401 hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
402 ok(hCombo != NULL, "createComboEx failed\n");
403 ret = GetWindowRect(hCombo, &rect);
404 ok(ret, "GetWindowRect failed\n");
405 combo_height = rect.bottom - rect.top;
406 ok(combo_height > 0, "wrong combo height\n");
407
408 /* Test height > combo_height */
409 wp.x = rect.left;
410 wp.y = rect.top;
411 wp.cx = (rect.right - rect.left);
412 wp.cy = combo_height * 2;
413 wp.flags = 0;
414 wp.hwnd = hCombo;
415 wp.hwndInsertAfter = NULL;
416
417 ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
418 ok(ret == 0, "expected 0, got %x\n", ret);
419 ok(wp.cy == combo_height,
420 "Expected height %d, got %d\n", combo_height, wp.cy);
421
422 /* Test height < combo_height */
423 wp.x = rect.left;
424 wp.y = rect.top;
425 wp.cx = (rect.right - rect.left);
426 wp.cy = combo_height / 2;
427 wp.flags = 0;
428 wp.hwnd = hCombo;
429 wp.hwndInsertAfter = NULL;
430
431 ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
432 ok(ret == 0, "expected 0, got %x\n", ret);
433 ok(wp.cy == combo_height,
434 "Expected height %d, got %d\n", combo_height, wp.cy);
435
436 ret = DestroyWindow(hCombo);
437 ok(ret, "DestroyWindow failed\n");
438 }
439
440 static LRESULT ComboExTestOnNotify(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
441 {
442 NMHDR *hdr = (NMHDR*)lParam;
443 switch(hdr->code){
444 case CBEN_ENDEDITA:
445 {
446 NMCBEENDEDITA *edit_info = (NMCBEENDEDITA*)hdr;
447 if(edit_info->iWhy==CBENF_DROPDOWN){
448 received_end_edit = TRUE;
449 }
450 break;
451 }
452 case CBEN_ENDEDITW:
453 {
454 NMCBEENDEDITW *edit_info = (NMCBEENDEDITW*)hdr;
455 if(edit_info->iWhy==CBENF_DROPDOWN){
456 received_end_edit = TRUE;
457 }
458 break;
459 }
460 }
461 return 0;
462 }
463
464 static LRESULT CALLBACK ComboExTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
465 {
466 switch(msg) {
467
468 case WM_DESTROY:
469 PostQuitMessage(0);
470 break;
471 case WM_NOTIFY:
472 return ComboExTestOnNotify(hWnd,msg,wParam,lParam);
473 default:
474 return DefWindowProcA(hWnd, msg, wParam, lParam);
475 }
476
477 return 0L;
478 }
479
480 static int init(void)
481 {
482 HMODULE hComctl32;
483 BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
484 WNDCLASSA wc;
485 INITCOMMONCONTROLSEX iccex;
486
487 hComctl32 = GetModuleHandleA("comctl32.dll");
488 pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
489 if (!pInitCommonControlsEx)
490 {
491 win_skip("InitCommonControlsEx() is missing. Skipping the tests\n");
492 return 0;
493 }
494 iccex.dwSize = sizeof(iccex);
495 iccex.dwICC = ICC_USEREX_CLASSES;
496 pInitCommonControlsEx(&iccex);
497
498 pSetWindowSubclass = (void*)GetProcAddress(hComctl32, (LPSTR)410);
499
500 wc.style = CS_HREDRAW | CS_VREDRAW;
501 wc.cbClsExtra = 0;
502 wc.cbWndExtra = 0;
503 wc.hInstance = GetModuleHandleA(NULL);
504 wc.hIcon = NULL;
505 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
506 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
507 wc.lpszMenuName = NULL;
508 wc.lpszClassName = ComboExTestClass;
509 wc.lpfnWndProc = ComboExTestWndProc;
510 RegisterClassA(&wc);
511
512 hComboExParentWnd = CreateWindowExA(0, ComboExTestClass, "ComboEx test", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
513 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
514 assert(hComboExParentWnd != NULL);
515
516 hMainHinst = GetModuleHandleA(NULL);
517 return 1;
518 }
519
520 static void cleanup(void)
521 {
522 MSG msg;
523
524 PostMessageA(hComboExParentWnd, WM_CLOSE, 0, 0);
525 while (GetMessageA(&msg,0,0,0)) {
526 TranslateMessage(&msg);
527 DispatchMessageA(&msg);
528 }
529
530 DestroyWindow(hComboExParentWnd);
531 UnregisterClassA(ComboExTestClass, GetModuleHandleA(NULL));
532 }
533
534 static void test_comboboxex_subclass(void)
535 {
536 HWND hComboEx, hCombo, hEdit;
537
538 hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
539
540 hCombo = (HWND)SendMessage(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
541 ok(hCombo != NULL, "Failed to get internal combo\n");
542 hEdit = (HWND)SendMessage(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
543 ok(hEdit != NULL, "Failed to get internal edit\n");
544
545 if (pSetWindowSubclass)
546 {
547 ok(GetPropA(hCombo, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
548 ok(GetPropA(hEdit, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
549 }
550
551 DestroyWindow(hComboEx);
552 }
553
554 static const struct message test_setitem_edit_seq[] = {
555 { WM_SETTEXT, sent|id, 0, 0, EDITBOX_ID },
556 { EM_SETSEL, sent|id|wparam|lparam, 0, 0, EDITBOX_ID },
557 { EM_SETSEL, sent|id|wparam|lparam, 0, -1, EDITBOX_ID },
558 { 0 }
559 };
560
561 static void test_get_set_item(void)
562 {
563 char textA[] = "test";
564 HWND hComboEx;
565 COMBOBOXEXITEMA item;
566 BOOL ret;
567
568 hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
569
570 subclass_editbox(hComboEx);
571
572 flush_sequences(sequences, NUM_MSG_SEQUENCES);
573
574 memset(&item, 0, sizeof(item));
575 item.mask = CBEIF_TEXT;
576 item.pszText = textA;
577 item.iItem = -1;
578 ret = SendMessage(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
579 expect(TRUE, ret);
580
581 ok_sequence(sequences, EDITBOX_SEQ_INDEX, test_setitem_edit_seq, "set item data for edit", FALSE);
582
583 /* get/set lParam */
584 item.mask = CBEIF_LPARAM;
585 item.iItem = -1;
586 item.lParam = 0xdeadbeef;
587 ret = SendMessage(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
588 expect(TRUE, ret);
589 ok(item.lParam == 0, "Expected zero, got %lx\n", item.lParam);
590
591 item.lParam = 0x1abe11ed;
592 ret = SendMessage(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
593 expect(TRUE, ret);
594
595 item.lParam = 0;
596 ret = SendMessage(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
597 expect(TRUE, ret);
598 ok(item.lParam == 0x1abe11ed, "Expected 0x1abe11ed, got %lx\n", item.lParam);
599
600 DestroyWindow(hComboEx);
601 }
602
603 START_TEST(comboex)
604 {
605 if (!init())
606 return;
607
608 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
609
610 test_comboboxex();
611 test_WM_LBUTTONDOWN();
612 test_CB_GETLBTEXT();
613 test_WM_WINDOWPOSCHANGING();
614 test_comboboxex_subclass();
615 test_get_set_item();
616
617 cleanup();
618 }