crypt32: Make sure we show Unicode characters (Dutch translation).
[wine] / dlls / comctl32 / tests / header.c
1 /* Unit test suite for header control.
2  *
3  * Copyright 2005 Vijay Kiran Kamuju
4  * Copyright 2007 Shanren Zhou
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <assert.h>
25
26 #include "wine/test.h"
27 #include "msg.h"
28
29 typedef struct tagEXPECTEDNOTIFY
30 {
31     INT iCode;
32     BOOL fUnicode;
33     HDITEMA hdItem;
34 } EXPECTEDNOTIFY;
35
36 typedef LRESULT (*CUSTOMDRAWPROC)(int n, NMCUSTOMDRAW *nm);
37
38 static CUSTOMDRAWPROC g_CustomDrawProc;
39 static int g_CustomDrawCount;
40 static DRAWITEMSTRUCT g_DrawItem;
41 static BOOL g_DrawItemReceived;
42 static DWORD g_customheight;
43
44 static EXPECTEDNOTIFY expectedNotify[10];
45 static INT nExpectedNotify = 0;
46 static INT nReceivedNotify = 0;
47 static INT unexpectedNotify[10];
48 static INT nUnexpectedNotify = 0;
49
50 static HWND hHeaderParentWnd;
51 static HWND hWndHeader;
52 #define MAX_CHARS 100
53
54 #define compare(val, exp, fmt)  ok((val) == (exp), #val " value: " fmt ", expected: " fmt "\n", (val), (exp))
55
56 #define expect(expected, got) ok(expected == got, "expected %d, got %d\n", expected,got)
57
58 #define NUM_MSG_SEQUENCES    2
59 #define PARENT_SEQ_INDEX     0
60 #define HEADER_SEQ_INDEX     1
61
62 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
63
64 static const struct message create_parent_wnd_seq[] = {
65     { WM_GETMINMAXINFO, sent },
66     { WM_NCCREATE, sent },
67     { WM_NCCALCSIZE, sent|wparam, 0 },
68     { WM_CREATE, sent },
69     { 0 }
70 };
71
72 static const struct message add_header_to_parent_seq_interactive[] = {
73     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
74     { WM_QUERYUISTATE, sent },
75     { WM_PARENTNOTIFY, sent|wparam, 1 },
76     { WM_SHOWWINDOW, sent|wparam, 1 },
77     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
78     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
79     { WM_ACTIVATEAPP, sent|wparam, 1 },
80     { WM_NCACTIVATE, sent|wparam, 1 },
81     { WM_ACTIVATE, sent|wparam, 1 },
82     { WM_IME_SETCONTEXT, sent|defwinproc|wparam, 1 },
83     { WM_IME_NOTIFY, sent|defwinproc|wparam, 2 },
84     { WM_SETFOCUS, sent|defwinproc|wparam, 0 },
85     { WM_WINDOWPOSCHANGED, sent|wparam, 0 },
86     { WM_SIZE, sent|wparam, 0 },
87     { WM_MOVE, sent|wparam, 0 },
88     { 0 }
89 };
90
91 static const struct message add_header_to_parent_seq[] = {
92     { WM_NOTIFYFORMAT, sent|lparam, 0, NF_QUERY },
93     { WM_QUERYUISTATE, sent|optional },
94     { WM_PARENTNOTIFY, sent },
95     { 0 }
96 };
97
98 static const struct message insertItem_seq[] = {
99     { HDM_INSERTITEM, sent|wparam, 0 },
100     { HDM_INSERTITEM, sent|wparam, 1 },
101     { HDM_INSERTITEM, sent|wparam, 2 },
102     { HDM_INSERTITEM, sent|wparam, 3 },
103     { 0 }
104 };
105
106 static const struct message getItem_seq[] = {
107     { HDM_GETITEM, sent|wparam, 3 },
108     { HDM_GETITEM, sent|wparam, 0 },
109     { 0 }
110 };
111
112
113 static const struct message deleteItem_getItemCount_seq[] = {
114     { HDM_DELETEITEM, sent|wparam, 3 },
115     { HDM_GETITEMCOUNT, sent },
116     { HDM_DELETEITEM, sent|wparam, 3 },
117     { HDM_GETITEMCOUNT, sent },
118     { HDM_DELETEITEM, sent|wparam, 2 },
119     { HDM_GETITEMCOUNT, sent },
120     { 0 }
121 };
122
123 static const struct message orderArray_seq[] = {
124     { HDM_GETITEMCOUNT, sent },
125     { HDM_SETORDERARRAY, sent|wparam, 2 },
126     { HDM_GETORDERARRAY, sent|wparam, 2 },
127     { 0 }
128 };
129
130 static const struct message setItem_seq[] = {
131     { HDM_SETITEM, sent|wparam, 0 },
132     { HDM_SETITEM, sent|wparam, 1 },
133     { 0 }
134 };
135
136 static const struct message getItemRect_seq[] = {
137     { HDM_GETITEMRECT, sent|wparam, 1 },
138     { HDM_GETITEMRECT, sent|wparam, 0 },
139     { HDM_GETITEMRECT, sent|wparam, 10 },
140     { 0 }
141 };
142
143 static const struct message layout_seq[] = {
144     { HDM_LAYOUT, sent },
145     { 0 }
146 };
147
148 static const struct message orderToIndex_seq[] = {
149     { HDM_ORDERTOINDEX, sent|wparam, 1 },
150     { 0 }
151 };
152
153 static const struct message hittest_seq[] = {
154     { HDM_HITTEST, sent },
155     { HDM_HITTEST, sent },
156     { HDM_HITTEST, sent },
157     { 0 }
158 };
159
160 static const struct message setHotDivider_seq_interactive[] = {
161     { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
162     { WM_PAINT, sent|defwinproc},
163     { WM_NCPAINT, sent|defwinproc},
164     { WM_ERASEBKGND, sent|defwinproc},
165     { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
166     { WM_PAINT, sent|defwinproc},
167     { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
168     { WM_PAINT, sent|defwinproc},
169     { 0 }
170 };
171
172 static const struct message setHotDivider_seq_noninteractive[] = {
173     { HDM_SETHOTDIVIDER, sent|wparam, TRUE },
174     { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 100 },
175     { HDM_SETHOTDIVIDER, sent|wparam|lparam, FALSE, 1},
176     { 0 }
177 };
178
179 static const struct message imageMessages_seq[] = {
180     { HDM_SETIMAGELIST, sent },
181     { HDM_GETIMAGELIST, sent },
182     { HDM_CREATEDRAGIMAGE, sent },
183     { 0 }
184 };
185
186 static const struct message filterMessages_seq_interactive[] = {
187     { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
188     { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
189     { HDM_EDITFILTER,  sent|wparam|lparam, 1, 0 },
190     { WM_PARENTNOTIFY, sent|wparam|defwinproc, WM_CREATE },
191     { WM_CTLCOLOREDIT, sent|defwinproc },
192     { WM_COMMAND, sent|defwinproc },
193     { 0 }
194 };
195
196 static const struct message filterMessages_seq_noninteractive[] = {
197     { HDM_SETFILTERCHANGETIMEOUT, sent|wparam|lparam, 1, 100 },
198     { HDM_CLEARFILTER, sent|wparam|lparam, 0, 1 },
199     { HDM_EDITFILTER,  sent|wparam|lparam, 1, 0 },
200     { WM_PARENTNOTIFY, sent|wparam|defwinproc|optional, WM_CREATE },
201     { WM_COMMAND, sent|defwinproc|optional },
202     { 0 }
203 };
204
205 static const struct message unicodeformatMessages_seq[] = {
206     { HDM_SETUNICODEFORMAT, sent|wparam, TRUE },
207     { HDM_GETUNICODEFORMAT, sent },
208     { 0 }
209 };
210
211 static const struct message bitmapmarginMessages_seq[] = {
212     { HDM_GETBITMAPMARGIN, sent },
213     { 0 }
214 };
215
216
217 static void expect_notify(INT iCode, BOOL fUnicode, HDITEMA *lpItem)
218 {
219     assert(nExpectedNotify < 10);
220     expectedNotify[nExpectedNotify].iCode = iCode;
221     expectedNotify[nExpectedNotify].fUnicode = fUnicode;
222     expectedNotify[nExpectedNotify].hdItem = *lpItem;
223     nExpectedNotify++;
224 }
225
226 static void dont_expect_notify(INT iCode)
227 {
228     assert(nUnexpectedNotify < 10);
229     unexpectedNotify[nUnexpectedNotify++] = iCode;
230 }
231
232 static BOOL notifies_received(void)
233 {
234     BOOL fRet = (nExpectedNotify == nReceivedNotify);
235     nExpectedNotify = nReceivedNotify = 0;
236     nUnexpectedNotify = 0;
237     return fRet;
238 }
239
240 static LONG addItem(HWND hdex, int idx, LPSTR text)
241 {
242     HDITEMA hdItem;
243     hdItem.mask       = HDI_TEXT | HDI_WIDTH;
244     hdItem.cxy        = 100;
245     hdItem.pszText    = text;
246     hdItem.cchTextMax = 0;
247     return (LONG)SendMessage(hdex, HDM_INSERTITEMA, (WPARAM)idx, (LPARAM)&hdItem);
248 }
249
250 static LONG setItem(HWND hdex, int idx, LPSTR text, BOOL fCheckNotifies)
251 {
252     LONG ret;
253     HDITEMA hdexItem;
254     hdexItem.mask       = HDI_TEXT;
255     hdexItem.pszText    = text;
256     hdexItem.cchTextMax = 0;
257     if (fCheckNotifies)
258     {
259         expect_notify(HDN_ITEMCHANGINGA, FALSE, &hdexItem);
260         expect_notify(HDN_ITEMCHANGEDA, FALSE, &hdexItem);
261     }
262     ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
263     if (fCheckNotifies)
264         ok(notifies_received(), "setItem(): not all expected notifies were received\n");
265     return ret;
266 }
267
268 static LONG setItemUnicodeNotify(HWND hdex, int idx, LPSTR text, LPWSTR wText)
269 {
270     LONG ret;
271     HDITEMA hdexItem;
272     HDITEMW hdexNotify;
273     hdexItem.mask       = HDI_TEXT;
274     hdexItem.pszText    = text;
275     hdexItem.cchTextMax = 0;
276     
277     hdexNotify.mask    = HDI_TEXT;
278     hdexNotify.pszText = wText;
279     
280     expect_notify(HDN_ITEMCHANGINGW, TRUE, (HDITEMA*)&hdexNotify);
281     expect_notify(HDN_ITEMCHANGEDW, TRUE, (HDITEMA*)&hdexNotify);
282     ret = (LONG)SendMessage(hdex, HDM_SETITEMA, (WPARAM)idx, (LPARAM)&hdexItem);
283     ok(notifies_received(), "setItemUnicodeNotify(): not all expected notifies were received\n");
284     return ret;
285 }
286
287 static LONG delItem(HWND hdex, int idx)
288 {
289     return (LONG)SendMessage(hdex, HDM_DELETEITEM, (WPARAM)idx, 0);
290 }
291
292 static LONG getItemCount(HWND hdex)
293 {
294     return (LONG)SendMessage(hdex, HDM_GETITEMCOUNT, 0, 0);
295 }
296
297 static LONG getItem(HWND hdex, int idx, LPSTR textBuffer)
298 {
299     HDITEMA hdItem;
300     hdItem.mask         = HDI_TEXT;
301     hdItem.pszText      = textBuffer;
302     hdItem.cchTextMax   = MAX_CHARS;
303     return (LONG)SendMessage(hdex, HDM_GETITEMA, (WPARAM)idx, (LPARAM)&hdItem);
304 }
305
306 static void addReadDelItem(HWND hdex, HDITEMA *phdiCreate, int maskRead, HDITEMA *phdiRead)
307 {
308     ok(SendMessage(hdex, HDM_INSERTITEMA, 0, (LPARAM)phdiCreate)!=-1, "Adding item failed\n");
309     ZeroMemory(phdiRead, sizeof(HDITEMA));
310     phdiRead->mask = maskRead;
311     ok(SendMessage(hdex, HDM_GETITEMA, 0, (LPARAM)phdiRead)!=0, "Getting item data failed\n");
312     ok(SendMessage(hdex, HDM_DELETEITEM, 0, 0)!=0, "Deleting item failed\n");
313 }
314
315 static HWND create_header_control (void)
316 {
317     HWND handle;
318     HDLAYOUT hlayout;
319     RECT rectwin;
320     WINDOWPOS winpos;
321
322     handle = CreateWindowEx(0, WC_HEADER, NULL,
323                             WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
324                             0, 0, 0, 0,
325                             hHeaderParentWnd, NULL, NULL, NULL);
326     assert(handle);
327
328     if (winetest_interactive)
329         ShowWindow (hHeaderParentWnd, SW_SHOW);
330
331     GetClientRect(hHeaderParentWnd,&rectwin);
332     hlayout.prc = &rectwin;
333     hlayout.pwpos = &winpos;
334     SendMessageA(handle,HDM_LAYOUT,0,(LPARAM) &hlayout);
335     SetWindowPos(handle, winpos.hwndInsertAfter, winpos.x, winpos.y, 
336                  winpos.cx, winpos.cy, 0);
337
338     return handle;
339 }
340
341 static void compare_items(INT iCode, HDITEMA *hdi1, HDITEMA *hdi2, BOOL fUnicode)
342 {
343     ok(hdi1->mask == hdi2->mask, "Notify %d mask mismatch (%08x != %08x)\n", iCode, hdi1->mask, hdi2->mask);
344     if (hdi1->mask & HDI_WIDTH)
345     {
346         ok(hdi1->cxy == hdi2->cxy, "Notify %d cxy mismatch (%08x != %08x)\n", iCode, hdi1->cxy, hdi2->cxy);
347     }
348     if (hdi1->mask & HDI_TEXT)
349     {
350         if (hdi1->pszText == LPSTR_TEXTCALLBACKA)
351         {
352             ok(hdi1->pszText == LPSTR_TEXTCALLBACKA, "Notify %d - only one item is LPSTR_TEXTCALLBACK\n", iCode);
353         }
354         else
355         if (fUnicode)
356         {
357             char buf1[260];
358             char buf2[260];
359             WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi1->pszText, -1, buf1, 260, NULL, NULL);
360             WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)hdi2->pszText, -1, buf2, 260, NULL, NULL);
361             ok(lstrcmpW((LPWSTR)hdi1->pszText, (LPWSTR)hdi2->pszText)==0,
362                 "Notify %d text mismatch (L\"%s\" vs L\"%s\")\n",
363                     iCode, buf1, buf2);
364         }
365         else
366         {
367             ok(strcmp(hdi1->pszText, hdi2->pszText)==0,
368                 "Notify %d text mismatch (\"%s\" vs \"%s\")\n",
369                     iCode, hdi1->pszText, hdi2->pszText);
370             }
371     }
372 }
373
374 static char pszFirstItem[]      = "First Item";
375 static char pszSecondItem[]     = "Second Item";
376 static char pszThirdItem[]      = "Third Item";
377 static char pszFourthItem[]     = "Fourth Item";
378 static char pszReplaceItem[]    = "Replace Item";
379 static char pszOutOfRangeItem[] = "Out Of Range Item";
380
381 static char *str_items[] =
382     {pszFirstItem, pszSecondItem, pszThirdItem, pszFourthItem, pszReplaceItem, pszOutOfRangeItem};
383     
384 static char pszUniTestA[]  = "TST";
385 static WCHAR pszUniTestW[] = {'T','S','T',0};
386
387
388 #define TEST_GET_ITEM(i,c)\
389 {   res = getItem(hWndHeader, i, buffer);\
390     ok(res != 0, "Getting item[%d] using valid index failed unexpectedly (%d)\n", i, res);\
391     ok(strcmp(str_items[c], buffer) == 0, "Getting item[%d] returned \"%s\" expecting \"%s\"\n", i, buffer, str_items[c]);\
392 }
393
394 #define TEST_GET_ITEMCOUNT(i)\
395 {   res = getItemCount(hWndHeader);\
396     ok(res == i, "Got Item Count as %d\n", res);\
397 }
398
399 struct subclass_info
400 {
401     WNDPROC oldproc;
402 };
403
404 static LRESULT WINAPI header_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
405 {
406     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
407     static LONG defwndproc_counter = 0;
408     LRESULT ret;
409     struct message msg;
410
411     trace("header: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
412     msg.message = message;
413     msg.flags = sent|wparam|lparam;
414     if (defwndproc_counter) msg.flags |= defwinproc;
415     msg.wParam = wParam;
416     msg.lParam = lParam;
417     add_message(sequences, HEADER_SEQ_INDEX, &msg);
418
419     defwndproc_counter++;
420     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
421     defwndproc_counter--;
422
423     return ret;
424 }
425
426 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
427 {
428     static LONG defwndproc_counter = 0;
429     LRESULT ret;
430     struct message msg;
431
432     /* do not log painting messages */
433     if (message != WM_PAINT &&
434         message != WM_ERASEBKGND &&
435         message != WM_NCPAINT &&
436         message != WM_NCHITTEST &&
437         message != WM_GETTEXT &&
438         message != WM_GETICON &&
439         message != WM_DEVICECHANGE)
440
441     {
442         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
443
444         msg.message = message;
445         msg.flags = sent|wparam|lparam;
446         if (defwndproc_counter) msg.flags |= defwinproc;
447         msg.wParam = wParam;
448         msg.lParam = lParam;
449         add_message(sequences, PARENT_SEQ_INDEX, &msg);
450    }
451
452     defwndproc_counter++;
453     ret = DefWindowProcA(hwnd, message, wParam, lParam);
454     defwndproc_counter--;
455
456     return ret;
457 }
458
459 static BOOL register_parent_wnd_class(void)
460 {
461     WNDCLASSA cls;
462
463     cls.style = 0;
464     cls.lpfnWndProc = parent_wnd_proc;
465     cls.cbClsExtra = 0;
466     cls.cbWndExtra = 0;
467     cls.hInstance = GetModuleHandleA(NULL);
468     cls.hIcon = 0;
469     cls.hCursor = LoadCursorA(0, IDC_ARROW);
470     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
471     cls.lpszMenuName = NULL;
472     cls.lpszClassName = "Header test parent class";
473     return RegisterClassA(&cls);
474 }
475
476 static HWND create_custom_parent_window(void)
477 {
478     if (!register_parent_wnd_class())
479         return NULL;
480
481     return CreateWindowExA(0, "Header test parent class", "Header Message Sequence Testing",
482                            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
483                            672+2*GetSystemMetrics(SM_CXSIZEFRAME),
484                            226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
485                            NULL, NULL, GetModuleHandleA(NULL), 0);
486 }
487
488 static HWND create_custom_header_control(HWND hParent, BOOL preloadHeaderItems)
489 {
490     struct subclass_info *info;
491     HWND childHandle;
492     HDLAYOUT hlayout;
493     RECT rectwin;
494     WINDOWPOS winpos;
495     int retVal;
496     int loopcnt;
497     static char firstHeaderItem[] = "Name";
498     static char secondHeaderItem[] = "Size";
499     static char *items[] = {secondHeaderItem, firstHeaderItem};
500     HDITEM hdItem;
501     hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
502     hdItem.fmt = HDF_LEFT;
503     hdItem.cxy = 80;
504     hdItem.cchTextMax = 260;
505
506
507     flush_sequences(sequences, NUM_MSG_SEQUENCES);
508     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
509     if (!info)
510          return NULL;
511
512     childHandle = CreateWindowEx(0, WC_HEADER, NULL,
513                            WS_CHILD|WS_BORDER|WS_VISIBLE|HDS_BUTTONS|HDS_HORZ,
514                            0, 0, 0, 0,
515                            hParent, NULL, NULL, NULL);
516     assert(childHandle);
517     if (preloadHeaderItems)
518     {
519          for ( loopcnt = 0 ; loopcnt < 2 ; loopcnt++ )
520          {
521              hdItem.pszText = items[loopcnt];
522              retVal = SendMessage(childHandle, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
523              ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
524           }
525     }
526
527     if (winetest_interactive)
528        ShowWindow (hParent, SW_SHOW);
529
530     GetClientRect(hParent,&rectwin);
531     hlayout.prc = &rectwin;
532     hlayout.pwpos = &winpos;
533     SendMessageA(childHandle,HDM_LAYOUT,0,(LPARAM) &hlayout);
534     SetWindowPos(childHandle, winpos.hwndInsertAfter, winpos.x, winpos.y,
535                  winpos.cx, winpos.cy, 0);
536
537     info->oldproc = (WNDPROC)SetWindowLongPtrA(childHandle, GWLP_WNDPROC,
538                                                (LONG_PTR)header_subclass_proc);
539     SetWindowLongPtrA(childHandle, GWLP_USERDATA, (LONG_PTR)info);
540     return childHandle;
541 }
542
543 static void check_auto_format(void)
544 {
545     HDITEMA hdiCreate;
546     HDITEMA hdiRead;
547     static CHAR text[] = "Test";
548     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
549
550     /* Windows implicitly sets some format bits in INSERTITEM */
551
552     /* HDF_STRING is automatically set and cleared for no text */
553     hdiCreate.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
554     hdiCreate.pszText = text;
555     hdiCreate.cxy = 100;
556     hdiCreate.fmt=HDF_CENTER;
557     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
558     ok(hdiRead.fmt == (HDF_STRING|HDF_CENTER), "HDF_STRING not set automatically (fmt=%x)\n", hdiRead.fmt);
559
560     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
561     hdiCreate.pszText = text;
562     hdiCreate.fmt = HDF_CENTER|HDF_STRING;
563     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
564     ok(hdiRead.fmt == (HDF_CENTER), "HDF_STRING should be automatically cleared (fmt=%x)\n", hdiRead.fmt);
565
566     /* HDF_BITMAP is automatically set and cleared for a NULL bitmap or no bitmap */
567     hdiCreate.mask = HDI_BITMAP|HDI_WIDTH|HDI_FORMAT;
568     hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
569     hdiCreate.fmt = HDF_CENTER;
570     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
571     ok(hdiRead.fmt == (HDF_BITMAP|HDF_CENTER), "HDF_BITMAP not set automatically (fmt=%x)\n", hdiRead.fmt);
572     DeleteObject(hdiCreate.hbm);
573
574     hdiCreate.hbm = NULL;
575     hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
576     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
577     ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for NULL bitmap (fmt=%x)\n", hdiRead.fmt);
578
579     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
580     hdiCreate.fmt = HDF_CENTER|HDF_BITMAP;
581     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
582     ok(hdiRead.fmt == HDF_CENTER, "HDF_BITMAP not cleared automatically for no bitmap (fmt=%x)\n", hdiRead.fmt);
583
584     /* HDF_IMAGE is automatically set but not cleared */
585     hdiCreate.mask = HDI_IMAGE|HDI_WIDTH|HDI_FORMAT;
586     hdiCreate.iImage = 17;
587     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
588     ok(hdiRead.fmt == (HDF_IMAGE|HDF_CENTER), "HDF_IMAGE not set automatically (fmt=%x)\n", hdiRead.fmt);
589
590     hdiCreate.mask = HDI_WIDTH|HDI_FORMAT;
591     hdiCreate.fmt = HDF_CENTER|HDF_IMAGE;
592     hdiCreate.iImage = 0;
593     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
594     ok(hdiRead.fmt == (HDF_CENTER|HDF_IMAGE), "HDF_IMAGE shouldn't be cleared automatically (fmt=%x)\n", hdiRead.fmt);
595 }
596
597 static void check_auto_fields(void)
598 {
599     HDITEMA hdiCreate;
600     HDITEMA hdiRead;
601     static CHAR text[] = "Test";
602     LONG res;
603
604     /* Windows stores the format, width, lparam even if they are not in the item's mask */
605     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
606     hdiCreate.mask = HDI_TEXT;
607     hdiCreate.cxy = 100;
608     hdiCreate.pszText = text;
609     addReadDelItem(hWndHeader, &hdiCreate, HDI_WIDTH, &hdiRead);
610     TEST_GET_ITEMCOUNT(6);
611     ok(hdiRead.cxy == hdiCreate.cxy, "cxy should be automatically set\n");
612
613     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
614     hdiCreate.mask = HDI_TEXT;
615     hdiCreate.pszText = text;
616     hdiCreate.lParam = 0x12345678;
617     addReadDelItem(hWndHeader, &hdiCreate, HDI_LPARAM, &hdiRead);
618     TEST_GET_ITEMCOUNT(6);
619     ok(hdiRead.lParam == hdiCreate.lParam, "lParam should be automatically set\n");
620
621     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
622     hdiCreate.mask = HDI_TEXT;
623     hdiCreate.pszText = text;
624     hdiCreate.fmt = HDF_STRING|HDF_CENTER;
625     addReadDelItem(hWndHeader, &hdiCreate, HDI_FORMAT, &hdiRead);
626     TEST_GET_ITEMCOUNT(6);
627     ok(hdiRead.fmt == hdiCreate.fmt, "fmt should be automatically set\n");
628
629     /* others fields are not set */
630     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
631     hdiCreate.mask = HDI_TEXT;
632     hdiCreate.pszText = text;
633     hdiCreate.hbm = CreateBitmap(16, 16, 1, 8, NULL);
634     addReadDelItem(hWndHeader, &hdiCreate, HDI_BITMAP, &hdiRead);
635     TEST_GET_ITEMCOUNT(6);
636     ok(hdiRead.hbm == NULL, "hbm should not be automatically set\n");
637     DeleteObject(hdiCreate.hbm);
638
639     ZeroMemory(&hdiCreate, sizeof(HDITEMA));
640     hdiCreate.mask = HDI_IMAGE;
641     hdiCreate.iImage = 17;
642     hdiCreate.pszText = text;
643     addReadDelItem(hWndHeader, &hdiCreate, HDI_TEXT, &hdiRead);
644     TEST_GET_ITEMCOUNT(6);
645     ok(hdiRead.pszText==NULL, "pszText shouldn't be automatically set\n");
646
647     /* field from comctl >4.0 not tested as the system probably won't touch them */
648 }
649
650 static void check_mask(void)
651 {
652     HDITEMA hdi;
653     static CHAR text[] = "ABC";
654     LRESULT ret;
655
656     /* don't create items if the mask is zero */
657     ZeroMemory(&hdi, sizeof(hdi));
658     hdi.mask = 0;
659     hdi.cxy = 200;
660     hdi.pszText = text;
661     hdi.fmt = 0;
662     hdi.iOrder = 0;
663     hdi.lParam = 17;
664     hdi.cchTextMax = 260;
665     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
666     ok(ret == -1, "Creating an item with a zero mask should have failed\n");
667     if (ret != -1) SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
668
669     /* with a non-zero mask creation will succeed */
670     ZeroMemory(&hdi, sizeof(hdi));
671     hdi.mask = HDI_LPARAM;
672     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
673     ok(ret != -1, "Adding item with non-zero mask failed\n");
674     if (ret != -1)
675         SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
676
677     /* in SETITEM if the mask contains a unknown bit, it is ignored */
678     ZeroMemory(&hdi, sizeof(hdi));
679     hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
680     hdi.lParam = 133;
681     hdi.iImage = 17;
682     ret = SendMessage(hWndHeader, HDM_INSERTITEM, 0, (LPARAM)&hdi);
683     ok(ret != -1, "Adding item failed\n");
684
685     if (ret != -1)
686     {
687         /* check result */
688         ZeroMemory(&hdi, sizeof(hdi));
689         hdi.mask = HDI_LPARAM | HDI_IMAGE;
690         SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
691         ok(hdi.lParam == 133, "comctl32 4.0 field not set\n");
692         ok(hdi.iImage == 17, "comctl32 >4.0 field not set\n");
693
694         /* but in GETITEM if an unknown bit is set, comctl32 uses only version 4.0 fields */
695         ZeroMemory(&hdi, sizeof(hdi));
696         hdi.mask = 0x08000000 | HDI_LPARAM | HDI_IMAGE;
697         SendMessage(hWndHeader, HDM_GETITEM, 0, (LPARAM)&hdi);
698         ok(hdi.lParam == 133, "comctl32 4.0 field not read\n");
699         ok(hdi.iImage == 0, "comctl32 >4.0 field shouldn't be read\n");
700
701         SendMessage(hWndHeader, HDM_DELETEITEM, 0, 0);
702     }
703 }
704
705 static void test_header_control (void)
706 {
707     LONG res;
708     static char buffer[MAX_CHARS];
709     int i;
710
711     hWndHeader = create_header_control ();
712
713     for (i = 3; i >= 0; i--)
714     {
715         TEST_GET_ITEMCOUNT(3-i);
716         res = addItem(hWndHeader, 0, str_items[i]);
717         ok(res == 0, "Adding simple item failed (%d)\n", res);
718     }
719
720     TEST_GET_ITEMCOUNT(4);
721     res = addItem(hWndHeader, 99, str_items[i+1]);
722     ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
723     TEST_GET_ITEMCOUNT(5);
724     res = addItem(hWndHeader, 5, str_items[i+1]);
725     ok(res != -1, "Adding Out of Range item should fail with -1 got (%d)\n", res);
726     TEST_GET_ITEMCOUNT(6);
727
728     for (i = 0; i < 4; i++) { TEST_GET_ITEM(i,i); TEST_GET_ITEMCOUNT(6); }
729
730     res=getItem(hWndHeader, 99, buffer);
731     ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
732     res=getItem(hWndHeader, 5, buffer);
733     ok(res == 1, "Getting Out of Range item should fail with 1 (%d), got %s\n", res,buffer);
734     res=getItem(hWndHeader, -2, buffer);
735     ok(res == 0, "Getting Out of Range item should fail with 0 (%d), got %s\n", res,buffer);
736
737     if (winetest_interactive)
738     {
739         UpdateWindow(hHeaderParentWnd);
740         UpdateWindow(hWndHeader);
741     }
742
743     TEST_GET_ITEMCOUNT(6);
744     res=setItem(hWndHeader, 99, str_items[5], FALSE);
745     ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
746     res=setItem(hWndHeader, 5, str_items[5], TRUE);
747     ok(res == 1, "Setting Out of Range item should fail with 1 (%d)\n", res);
748     res=setItem(hWndHeader, -2, str_items[5], FALSE);
749     ok(res == 0, "Setting Out of Range item should fail with 0 (%d)\n", res);
750     TEST_GET_ITEMCOUNT(6);
751
752     for (i = 0; i < 4; i++)
753     {
754         res = setItem(hWndHeader, i, str_items[4], TRUE);
755         ok(res != 0, "Setting %d item failed (%d)\n", i+1, res);
756         TEST_GET_ITEM(i, 4);
757         TEST_GET_ITEMCOUNT(6);
758     }
759     
760     SendMessageA(hWndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, 0);
761     setItemUnicodeNotify(hWndHeader, 3, pszUniTestA, pszUniTestW);
762     SendMessageA(hWndHeader, WM_NOTIFYFORMAT, (WPARAM)hHeaderParentWnd, (LPARAM)NF_REQUERY);
763     setItem(hWndHeader, 3, str_items[4], TRUE);
764     
765     dont_expect_notify(HDN_GETDISPINFOA);
766     dont_expect_notify(HDN_GETDISPINFOW);
767     addItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA);
768     setItem(hWndHeader, 0, str_items[4], TRUE);
769     /* unexpected notifies cleared by notifies_received in setItem */
770     dont_expect_notify(HDN_GETDISPINFOA);
771     dont_expect_notify(HDN_GETDISPINFOW);
772     setItem(hWndHeader, 0, LPSTR_TEXTCALLBACKA, TRUE);
773     /* unexpected notifies cleared by notifies_received in setItem */
774     delItem(hWndHeader, 0);
775
776     check_auto_format();
777     TEST_GET_ITEMCOUNT(6);
778     check_auto_fields();
779     TEST_GET_ITEMCOUNT(6);
780     check_mask();
781     TEST_GET_ITEMCOUNT(6);
782
783     res = delItem(hWndHeader, 5);
784     ok(res == 1, "Deleting Out of Range item should fail with 1 (%d)\n", res);
785     res = delItem(hWndHeader, -2);
786     ok(res == 0, "Deleting Out of Range item should fail with 0 (%d)\n", res);
787     TEST_GET_ITEMCOUNT(5);
788
789     res = delItem(hWndHeader, 3);
790     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
791     TEST_GET_ITEMCOUNT(4);
792     res = delItem(hWndHeader, 0);
793     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
794     TEST_GET_ITEMCOUNT(3);
795     res = delItem(hWndHeader, 0);
796     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
797     TEST_GET_ITEMCOUNT(2);
798     res = delItem(hWndHeader, 0);
799     ok(res != 0, "Deleting using out of range index failed (%d)\n", res);
800     TEST_GET_ITEMCOUNT(1);
801
802     DestroyWindow(hWndHeader);
803 }
804
805 static void test_hdm_getitemrect(HWND hParent)
806 {
807
808     HWND hChild;
809     RECT rect;
810     int retVal;
811
812     flush_sequences(sequences, NUM_MSG_SEQUENCES);
813     hChild = create_custom_header_control(hParent, TRUE);
814     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
815                                     "adder header control to parent", FALSE);
816
817     retVal = SendMessage(hChild, HDM_GETITEMRECT, 1, (LPARAM) &rect);
818     ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
819     /* check bounding rectangle information of 2nd header item */
820     expect(80, rect.left);
821     expect(0, rect.top);
822     expect(160, rect.right);
823     todo_wine
824     {
825       expect(g_customheight, rect.bottom);
826     }
827     retVal = SendMessage(hChild, HDM_GETITEMRECT, 0, (LPARAM) &rect);
828
829     ok(retVal == TRUE, "Getting item rect should TRUE, got %d\n", retVal);
830     /* check bounding rectangle information of 1st header item */
831     expect(0, rect.left);
832     expect(0, rect.top);
833
834     expect(80, rect.right);
835     todo_wine
836     {
837       expect(g_customheight, rect.bottom);
838     }
839     retVal = SendMessage(hChild, HDM_GETITEMRECT, 10, (LPARAM) &rect);
840     ok(retVal == 0, "Getting rect of nonexistent item should return 0, got %d\n", retVal);
841
842     ok_sequence(sequences, HEADER_SEQ_INDEX, getItemRect_seq, "getItemRect sequence testing", FALSE);
843     DestroyWindow(hChild);
844 }
845
846 static void test_hdm_layout(HWND hParent)
847 {
848     HWND hChild;
849     int retVal;
850     RECT rect;
851     HDLAYOUT hdLayout;
852     WINDOWPOS windowPos;
853     hdLayout.prc = &rect;
854     hdLayout.pwpos = &windowPos;
855
856     flush_sequences(sequences, NUM_MSG_SEQUENCES);
857     hChild = create_custom_header_control(hParent, TRUE);
858     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
859                                     "adder header control to parent", FALSE);
860
861     flush_sequences(sequences, NUM_MSG_SEQUENCES);
862     retVal = SendMessage(hChild, HDM_LAYOUT, 0, (LPARAM) &hdLayout);
863     expect(TRUE, retVal);
864
865     ok_sequence(sequences, HEADER_SEQ_INDEX, layout_seq, "layout sequence testing", FALSE);
866
867     DestroyWindow(hChild);
868 }
869
870 static void test_hdm_ordertoindex(HWND hParent)
871 {
872     HWND hChild;
873     int retVal;
874
875     flush_sequences(sequences, NUM_MSG_SEQUENCES);
876     hChild = create_custom_header_control(hParent, TRUE);
877     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
878                                     "adder header control to parent", FALSE);
879
880     flush_sequences(sequences, NUM_MSG_SEQUENCES);
881     retVal = SendMessage(hChild, HDM_ORDERTOINDEX, 1, 0);
882     expect(1, retVal);
883
884     ok_sequence(sequences, HEADER_SEQ_INDEX, orderToIndex_seq, "orderToIndex sequence testing", FALSE);
885     DestroyWindow(hChild);
886 }
887
888 static void test_hdm_hittest(HWND hParent)
889 {
890     HWND hChild;
891     int retVal;
892     POINT pt;
893     HDHITTESTINFO hdHitTestInfo;
894     const int firstItemRightBoundary = 80;
895     const int secondItemRightBoundary = 160;
896     const int bottomBoundary = g_customheight;
897
898     pt.x = firstItemRightBoundary - 1;
899     pt.y = bottomBoundary - 1;
900     hdHitTestInfo.pt = pt;
901
902
903     flush_sequences(sequences, NUM_MSG_SEQUENCES);
904     hChild = create_custom_header_control(hParent, TRUE);
905     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
906                                     "adder header control to parent", FALSE);
907
908     flush_sequences(sequences, NUM_MSG_SEQUENCES);
909     retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
910     todo_wine
911     {
912       expect(0, retVal);
913       expect(0, hdHitTestInfo.iItem);
914     }
915
916     pt.x = secondItemRightBoundary - 1;
917     pt.y = bottomBoundary - 1;
918     hdHitTestInfo.pt = pt;
919     retVal = SendMessage(hChild, HDM_HITTEST, 1, (LPARAM) &hdHitTestInfo);
920     todo_wine
921     {
922       expect(1, retVal);
923     }
924     expect(1, hdHitTestInfo.iItem);
925
926     pt.x = secondItemRightBoundary;
927     pt.y = bottomBoundary + 1;
928     hdHitTestInfo.pt = pt;
929     todo_wine
930     {
931      retVal = SendMessage(hChild, HDM_HITTEST, 0, (LPARAM) &hdHitTestInfo);
932      expect(-1, retVal);
933     }
934
935     ok_sequence(sequences, HEADER_SEQ_INDEX, hittest_seq, "hittest sequence testing", FALSE);
936
937     DestroyWindow(hChild);
938 }
939
940 static void test_hdm_sethotdivider(HWND hParent)
941 {
942     HWND hChild;
943     int retVal;
944     /*  low word: x coordinate = 5
945      *  high word:  y coordinate = 5
946      */
947
948     flush_sequences(sequences, NUM_MSG_SEQUENCES);
949     hChild = create_custom_header_control(hParent, TRUE);
950     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
951                                     "adder header control to parent", FALSE);
952
953     flush_sequences(sequences, NUM_MSG_SEQUENCES);
954     todo_wine
955     {
956         retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, TRUE, 0X00050005);
957         expect(0, retVal);
958     }
959     retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 100);
960     expect(100, retVal);
961     retVal = SendMessage(hChild, HDM_SETHOTDIVIDER, FALSE, 1);
962     expect(1, retVal);
963     if (winetest_interactive)
964        ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_interactive,
965                    "setHotDivider sequence testing", TRUE);
966     else
967        ok_sequence(sequences, HEADER_SEQ_INDEX, setHotDivider_seq_noninteractive,
968                    "setHotDivider sequence testing", FALSE);
969
970     DestroyWindow(hChild);
971 }
972
973 static void test_hdm_imageMessages(HWND hParent)
974 {
975     HIMAGELIST hImageList = ImageList_Create (4, 4, 0, 1, 0);
976     HIMAGELIST hImageListRetVal;
977     HWND hChild;
978
979     flush_sequences(sequences, NUM_MSG_SEQUENCES);
980     hChild = create_custom_header_control(hParent, TRUE);
981     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
982                                     "adder header control to parent", FALSE);
983
984     flush_sequences(sequences, NUM_MSG_SEQUENCES);
985
986     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_SETIMAGELIST, 0, (LPARAM) hImageList);
987     ok(hImageListRetVal == NULL, "Expected NULL, got %p\n", hImageListRetVal);
988
989     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_GETIMAGELIST, 0, 0);
990     ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
991
992     hImageListRetVal = (HIMAGELIST) SendMessage(hChild, HDM_CREATEDRAGIMAGE, 0, 0);
993     ok(hImageListRetVal != NULL, "Expected non-NULL handle, got %p\n", hImageListRetVal);
994
995     ok_sequence(sequences, HEADER_SEQ_INDEX, imageMessages_seq, "imageMessages sequence testing", FALSE);
996
997     DestroyWindow(hChild);
998 }
999
1000 static void test_hdm_filterMessages(HWND hParent)
1001 {
1002     HWND hChild;
1003     int retVal, timeout;
1004
1005     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1006     hChild = create_custom_header_control(hParent, TRUE);
1007     assert(hChild);
1008     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1009                                     "adder header control to parent", FALSE);
1010
1011     timeout = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1012     SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, timeout);
1013
1014     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1015
1016     /* msdn incorrectly states that return value
1017      * is the index of the filter control being
1018      * modified. The sendMessage here should
1019      * return previous filter timeout value
1020      */
1021
1022     retVal = SendMessage(hChild, HDM_SETFILTERCHANGETIMEOUT, 1, 100);
1023     expect(timeout, retVal);
1024
1025     todo_wine
1026     {
1027         retVal = SendMessage(hChild, HDM_CLEARFILTER, 0, 1);
1028         if (retVal == 0)
1029             win_skip("HDM_CLEARFILTER needs 5.80\n");
1030         else
1031             expect(1, retVal);
1032
1033         retVal = SendMessage(hChild, HDM_EDITFILTER, 1, 0);
1034         if (retVal == 0)
1035             win_skip("HDM_EDITFILTER needs 5.80\n");
1036         else
1037             expect(1, retVal);
1038     }
1039     if (winetest_interactive)
1040          ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_interactive,
1041                      "filterMessages sequence testing", TRUE);
1042     else
1043          ok_sequence(sequences, HEADER_SEQ_INDEX, filterMessages_seq_noninteractive,
1044                      "filterMessages sequence testing", FALSE);
1045     /* Some Win9x versions don't send a WM_KILLFOCUS.
1046      * Set the focus explicitly to the parent to avoid a crash.
1047      */
1048     SetFocus(hParent);
1049     DestroyWindow(hChild);
1050
1051 }
1052
1053 static void test_hdm_unicodeformatMessages(HWND hParent)
1054 {
1055     HWND hChild;
1056     int retVal;
1057
1058     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1059     hChild = create_custom_header_control(hParent, TRUE);
1060     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1061                                     "adder header control to parent", FALSE);
1062
1063     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1064     retVal = SendMessage(hChild, HDM_SETUNICODEFORMAT, TRUE, 0);
1065     expect(0, retVal);
1066     retVal = SendMessage(hChild, HDM_GETUNICODEFORMAT, 0, 0);
1067     expect(1, retVal);
1068
1069     ok_sequence(sequences, HEADER_SEQ_INDEX, unicodeformatMessages_seq,
1070                      "unicodeformatMessages sequence testing", FALSE);
1071     DestroyWindow(hChild);
1072 }
1073
1074 static void test_hdm_bitmapmarginMessages(HWND hParent)
1075 {
1076     HWND hChild;
1077     int retVal;
1078
1079     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1080     hChild = create_custom_header_control(hParent, TRUE);
1081     ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1082                                     "adder header control to parent", FALSE);
1083
1084     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1085     retVal = SendMessage(hChild, HDM_GETBITMAPMARGIN, 0, 0);
1086     if (retVal == 0)
1087         win_skip("HDM_GETBITMAPMARGIN needs 5.80\n");
1088     else
1089         expect(6, retVal);
1090
1091     ok_sequence(sequences, HEADER_SEQ_INDEX, bitmapmarginMessages_seq,
1092                       "bitmapmarginMessages sequence testing", FALSE);
1093     DestroyWindow(hChild);
1094 }
1095
1096 static void test_hdm_index_messages(HWND hParent)
1097 {
1098
1099     HWND hChild;
1100     int retVal;
1101     int loopcnt;
1102     int strcmpResult;
1103     int iSize;
1104     static const int lpiarray[2] = {1, 0};
1105     static int lpiarrayReceived[2];
1106     static char firstHeaderItem[] = "Name";
1107     static char secondHeaderItem[] = "Size";
1108     static char thirdHeaderItem[] = "Type";
1109     static char fourthHeaderItem[] = "Date Modified";
1110     static char *items[] = {firstHeaderItem, secondHeaderItem, thirdHeaderItem, fourthHeaderItem};
1111     HDITEM hdItem;
1112     hdItem.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
1113     hdItem.fmt = HDF_LEFT;
1114     hdItem.cxy = 80;
1115     hdItem.cchTextMax = 260;
1116
1117     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1118     hChild = create_custom_header_control(hParent, FALSE);
1119     if (winetest_interactive)
1120          ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq_interactive,
1121                                               "adder header control to parent", TRUE);
1122     else
1123          ok_sequence(sequences, PARENT_SEQ_INDEX, add_header_to_parent_seq,
1124                                      "adder header control to parent", FALSE);
1125     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1126     for ( loopcnt = 0 ; loopcnt < 4 ; loopcnt++ )
1127     {
1128       hdItem.pszText = items[loopcnt];
1129       retVal = SendMessage(hChild, HDM_INSERTITEM, loopcnt, (LPARAM) &hdItem);
1130       ok(retVal == loopcnt, "Adding item %d failed with return value %d\n", ( loopcnt + 1 ), retVal);
1131     }
1132     ok_sequence(sequences, HEADER_SEQ_INDEX, insertItem_seq, "insertItem sequence testing", FALSE);
1133
1134     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1135
1136     retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1137     ok(retVal == TRUE, "Deleting item 3 should return TRUE, got %d\n", retVal);
1138     retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1139     ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1140
1141     retVal = SendMessage(hChild, HDM_DELETEITEM, 3, (LPARAM) &hdItem);
1142     ok(retVal == FALSE, "Deleting already-deleted item should return FALSE, got %d\n", retVal);
1143     retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1144     ok(retVal == 3, "Getting item count should return 3, got %d\n", retVal);
1145
1146     retVal = SendMessage(hChild, HDM_DELETEITEM, 2, (LPARAM) &hdItem);
1147     ok(retVal == TRUE, "Deleting item 2 should return TRUE, got %d\n", retVal);
1148     retVal = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1149     ok(retVal == 2, "Getting item count should return 2, got %d\n", retVal);
1150
1151     ok_sequence(sequences, HEADER_SEQ_INDEX, deleteItem_getItemCount_seq,
1152                          "deleteItem_getItemCount sequence testing", FALSE);
1153
1154     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1155
1156     retVal = SendMessage(hChild, HDM_GETITEM, 3, (LPARAM) &hdItem);
1157     ok(retVal == FALSE, "Getting already-deleted item should return FALSE, got %d\n", retVal);
1158
1159     retVal = SendMessage(hChild, HDM_GETITEM, 0, (LPARAM) &hdItem);
1160     ok(retVal == TRUE, "Getting the 1st header item should return TRUE, got %d\n", retVal);
1161
1162     ok_sequence(sequences, HEADER_SEQ_INDEX, getItem_seq, "getItem sequence testing", FALSE);
1163
1164     /* check if the item is the right one */
1165     strcmpResult =  strcmp(hdItem.pszText, firstHeaderItem);
1166     expect(0, strcmpResult);
1167     expect(80, hdItem.cxy);
1168
1169     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1170
1171     iSize = SendMessage(hChild, HDM_GETITEMCOUNT, 0, (LPARAM) &hdItem);
1172     retVal = SendMessage(hChild, HDM_SETORDERARRAY, iSize, (LPARAM) lpiarray);
1173     ok(retVal == TRUE, "Setting header items order should return TRUE, got %d\n", retVal);
1174
1175     retVal = SendMessage(hChild, HDM_GETORDERARRAY, iSize, (LPARAM) lpiarrayReceived);
1176     ok(retVal == TRUE, "Getting header items order should return TRUE, got %d\n", retVal);
1177
1178     ok_sequence(sequences, HEADER_SEQ_INDEX, orderArray_seq, "set_get_orderArray sequence testing", FALSE);
1179
1180     /* check if the array order is set correctly and the size of the array is correct. */
1181     expect(2, iSize);
1182     expect(lpiarray[0], lpiarrayReceived[0]);
1183     expect(lpiarray[1], lpiarrayReceived[1]);
1184
1185     hdItem.mask = HDI_FORMAT;
1186     hdItem.fmt = HDF_CENTER | HDF_STRING;
1187
1188     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1189
1190     retVal = SendMessage(hChild, HDM_SETITEM, 0, (LPARAM) &hdItem);
1191     ok(retVal == TRUE, "Aligning 1st header item to center should return TRUE, got %d\n", retVal);
1192     hdItem.fmt = HDF_RIGHT | HDF_STRING;
1193     retVal = SendMessage(hChild, HDM_SETITEM, 1, (LPARAM) &hdItem);
1194     ok(retVal == TRUE, "Aligning 2nd header item to right should return TRUE, got %d\n", retVal);
1195
1196     ok_sequence(sequences, HEADER_SEQ_INDEX, setItem_seq, "setItem sequence testing", FALSE);
1197     DestroyWindow(hChild);
1198 }
1199
1200 #define TEST_NMCUSTOMDRAW(draw_stage, item_spec, lparam, _left, _top, _right, _bottom) \
1201     ok(nm->dwDrawStage == draw_stage, "Invalid dwDrawStage %d vs %d\n", draw_stage, nm->dwDrawStage); \
1202     if (item_spec != -1) \
1203         ok(nm->dwItemSpec == item_spec, "Invalid dwItemSpec %d vs %ld\n", item_spec, nm->dwItemSpec); \
1204     ok(nm->lItemlParam == lparam, "Invalid lItemlParam %d vs %ld\n", lparam, nm->lItemlParam); \
1205     ok((nm->rc.top == _top && nm->rc.bottom == _bottom && nm->rc.left == _left && nm->rc.right == _right) || \
1206         broken(draw_stage != CDDS_ITEMPREPAINT), /* comctl32 < 5.80 */ \
1207         "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", _left, _top, _right, _bottom, \
1208         nm->rc.left, nm->rc.top, nm->rc.right, nm->rc.bottom);
1209
1210 static LRESULT customdraw_1(int n, NMCUSTOMDRAW *nm)
1211 {
1212     if (nm == NULL) {  /* test ended */
1213         ok(n==1, "NM_CUSTOMDRAW messages: %d, expected: 1\n", n);
1214         return 0;
1215     }
1216
1217     switch (n)
1218     {
1219     case 0:
1220         /* don't test dwItemSpec - it's 0 no comctl5 but 1308756 on comctl6 */
1221         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1222         return 0;
1223     }
1224
1225     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1226     return -1;
1227 }
1228
1229 static LRESULT customdraw_2(int n, NMCUSTOMDRAW *nm)
1230 {
1231     if (nm == NULL) {  /* test ended */
1232         ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1233         return 0;
1234     }
1235
1236     switch (n)
1237     {
1238     case 0:
1239         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1240         return CDRF_NOTIFYITEMDRAW;
1241     case 1:
1242         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1243         return 0;
1244     case 2:
1245         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1246         return 0;
1247     case 3:
1248         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1249         return 0;
1250     }
1251
1252     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1253     return 0;
1254 }
1255
1256 static LRESULT customdraw_3(int n, NMCUSTOMDRAW *nm)
1257 {
1258     if (nm == NULL) {  /* test ended */
1259         ok(n==5, "NM_CUSTOMDRAW messages: %d, expected: 5\n", n);
1260         return 0;
1261     }
1262
1263     switch (n)
1264     {
1265     case 0:
1266         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1267         return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTERASE|CDRF_NOTIFYPOSTPAINT|CDRF_SKIPDEFAULT;
1268     case 1:
1269         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1270         return 0;
1271     case 2:
1272         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 1, 5, 50, 0, 150, g_customheight);
1273         return 0;
1274     case 3:
1275         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1276         return 0;
1277     case 4:
1278         TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1279         return 0;
1280     }
1281
1282     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1283     return 0;
1284 }
1285
1286
1287 static LRESULT customdraw_4(int n, NMCUSTOMDRAW *nm)
1288 {
1289     if (nm == NULL) {  /* test ended */
1290         ok(n==4, "NM_CUSTOMDRAW messages: %d, expected: 4\n", n);
1291         return 0;
1292     }
1293
1294     switch (n)
1295     {
1296     case 0:
1297         TEST_NMCUSTOMDRAW(CDDS_PREPAINT, -1, 0, 0, 0, 670, g_customheight);
1298         return CDRF_NOTIFYITEMDRAW|CDRF_NOTIFYPOSTPAINT;
1299     case 1:
1300         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 0, 0, 0, 0, 50, g_customheight);
1301         return 0;
1302     case 2:
1303         TEST_NMCUSTOMDRAW(CDDS_ITEMPREPAINT, 2, 10, 150, 0, 300, g_customheight);
1304         return 0;
1305     case 3:
1306         TEST_NMCUSTOMDRAW(CDDS_POSTPAINT, -1, 0, 0, 0, 670, g_customheight);
1307         return 0;
1308     }
1309
1310     ok(FALSE, "To many custom draw messages (n=%d, nm->dwDrawStage=%d)\n", n, nm->dwDrawStage);
1311     return 0;
1312 }
1313
1314 static void run_customdraw_scenario(CUSTOMDRAWPROC proc)
1315 {
1316     g_CustomDrawProc = proc;
1317     g_CustomDrawCount = 0;
1318     InvalidateRect(hWndHeader, NULL, TRUE);
1319     UpdateWindow(hWndHeader);
1320     proc(g_CustomDrawCount, NULL);
1321     g_CustomDrawProc = NULL;
1322 }
1323
1324 static void test_customdraw(void)
1325 {
1326     int i;
1327     HDITEM item;
1328     RECT rect;
1329     CHAR name[] = "Test";
1330     hWndHeader = create_header_control();
1331     GetClientRect(hWndHeader, &rect);
1332     ok(rect.right - rect.left == 670 && rect.bottom - rect.top == g_customheight,
1333         "Tests will fail as header size is %dx%d instead of 670x%d\n",
1334         rect.right - rect.left, rect.bottom - rect.top, g_customheight);
1335
1336     for (i = 0; i < 3; i++)
1337     {
1338         ZeroMemory(&item, sizeof(item));
1339         item.mask = HDI_TEXT|HDI_WIDTH;
1340         item.cxy = 50*(i+1);
1341         item.pszText = name;
1342         item.lParam = i*5;
1343         SendMessage(hWndHeader, HDM_INSERTITEM, i, (LPARAM)&item);
1344     }
1345
1346     run_customdraw_scenario(customdraw_1);
1347     run_customdraw_scenario(customdraw_2);
1348     run_customdraw_scenario(customdraw_3);
1349
1350     ZeroMemory(&item, sizeof(item));
1351     item.mask = HDI_FORMAT;
1352     item.fmt = HDF_OWNERDRAW;
1353     SendMessage(hWndHeader, HDM_SETITEM, 1, (LPARAM)&item);
1354     g_DrawItem.CtlID = 0;
1355     g_DrawItem.CtlType = ODT_HEADER;
1356     g_DrawItem.hwndItem = hWndHeader;
1357     g_DrawItem.itemID = 1;
1358     g_DrawItem.itemState = 0;
1359     SendMessage(hWndHeader, HDM_GETITEMRECT, 1, (LPARAM)&g_DrawItem.rcItem);
1360     run_customdraw_scenario(customdraw_4);
1361     ok(g_DrawItemReceived, "WM_DRAWITEM not received\n");
1362     DestroyWindow(hWndHeader);
1363     hWndHeader = NULL;
1364     g_DrawItem.CtlType = 0;
1365     g_DrawItemReceived = FALSE;
1366 }
1367
1368 static void check_order(const int expected_id[], const int expected_order[],
1369                         int count, const char *type)
1370 {
1371     int i;
1372     HDITEMA hdi;
1373
1374     ok(getItemCount(hWndHeader) == count, "Invalid item count in order tests\n");
1375     for (i = 0; i < count; i++)
1376     {
1377         hdi.mask = HDI_LPARAM|HDI_ORDER;
1378         SendMessage(hWndHeader, HDM_GETITEMA, i, (LPARAM)&hdi);
1379         ok(hdi.lParam == expected_id[i],
1380             "Invalid item ids after '%s'- item %d has lParam %d\n", type, i, (int)hdi.lParam);
1381         ok(hdi.iOrder == expected_order[i],
1382             "Invalid item order after '%s'- item %d has iOrder %d\n", type, i, hdi.iOrder);
1383     }
1384 }
1385
1386 static void test_header_order (void)
1387 {
1388     const int rand1[] = {0, 1, 1, 0, 4};
1389     const int rand2[] = {4, 5, 6, 7, 4};
1390     const int rand3[] = {5, 5, 1, 6, 1};
1391     const int rand4[] = {1, 5, 2, 7, 6, 1, 4, 2, 3, 2};
1392     const int rand5[] = {7, 8, 5, 6, 7, 2, 1, 9, 10, 10};
1393     const int rand6[] = {2, 8, 3, 4, 0};
1394
1395     const int ids1[] = {3, 0, 2, 1, 4};
1396     const int ord1[] = {0, 1, 2, 3, 4};
1397     const int ids2[] = {3, 9, 7, 0, 2, 1, 4, 8, 6, 5};
1398     const int ord2[] = {0, 4, 7, 1, 2, 3, 9, 8, 6, 5};
1399     const int ord3[] = {0, 3, 9, 2, 1, 8, 7, 6, 5, 4};
1400     const int ids4[] = {9, 0, 1, 8, 6};
1401     const int ord4[] = {1, 0, 4, 3, 2};
1402
1403     char buffer[20];
1404     HDITEMA hdi;
1405     int i;
1406
1407     hWndHeader = create_header_control();
1408
1409     ZeroMemory(&hdi, sizeof(HDITEMA));
1410     hdi.mask = HDI_TEXT | HDI_LPARAM;
1411     hdi.pszText = buffer;
1412     strcpy(buffer, "test");
1413
1414     for (i = 0; i < 5; i++)
1415     {
1416         hdi.lParam = i;
1417         SendMessage(hWndHeader, HDM_INSERTITEMA, rand1[i], (LPARAM)&hdi);
1418         rand();
1419     }
1420     check_order(ids1, ord1, 5, "insert without iOrder");
1421
1422     hdi.mask |= HDI_ORDER;
1423     for (i = 0; i < 5; i++)
1424     {
1425         hdi.lParam = i + 5;
1426         hdi.iOrder = rand2[i];
1427         SendMessage(hWndHeader, HDM_INSERTITEMA, rand3[i], (LPARAM)&hdi);
1428         rand(); rand();
1429     }
1430     check_order(ids2, ord2, 10, "insert with order");
1431
1432     hdi.mask = HDI_ORDER;
1433     for (i=0; i<10; i++)
1434     {
1435         hdi.iOrder = rand5[i];
1436         SendMessage(hWndHeader, HDM_SETITEMA, rand4[i], (LPARAM)&hdi);
1437         rand(); rand();
1438     }
1439     check_order(ids2, ord3, 10, "setitems changing order");
1440
1441     for (i=0; i<5; i++)
1442         SendMessage(hWndHeader, HDM_DELETEITEM, rand6[i], 0);
1443     check_order(ids4, ord4, 5, "deleteitem");
1444
1445     DestroyWindow(hWndHeader);
1446 }
1447
1448 static LRESULT CALLBACK HeaderTestWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1449 {
1450     DRAWITEMSTRUCT *di;
1451     switch(msg) {
1452
1453     case WM_NOTIFY:
1454     {
1455         NMHEADERA *hdr = (NMHEADER *)lParam;
1456         EXPECTEDNOTIFY *expected;
1457         int i;
1458
1459         if (hdr->hdr.code == NM_CUSTOMDRAW)
1460             if (g_CustomDrawProc)
1461                 return g_CustomDrawProc(g_CustomDrawCount++, (NMCUSTOMDRAW*)hdr);
1462
1463         for (i=0; i<nUnexpectedNotify; i++)
1464             ok(hdr->hdr.code != unexpectedNotify[i], "Received invalid notify %d\n", hdr->hdr.code);
1465         
1466         if (nReceivedNotify >= nExpectedNotify || hdr->hdr.hwndFrom != hWndHeader )
1467             break;
1468
1469         expected = &expectedNotify[nReceivedNotify];
1470         if (hdr->hdr.code != expected->iCode)
1471             break;
1472         
1473         nReceivedNotify++;
1474         compare_items(hdr->hdr.code, &expected->hdItem, hdr->pitem, expected->fUnicode);
1475         break;
1476     }
1477
1478     case WM_DRAWITEM:
1479         di = (DRAWITEMSTRUCT *)lParam;
1480         ok(g_DrawItem.CtlType != 0, "Unexpected WM_DRAWITEM\n");
1481         if (g_DrawItem.CtlType == 0) return 0;
1482         g_DrawItemReceived = TRUE;
1483         compare(di->CtlType,   g_DrawItem.CtlType, "%d");
1484         compare(di->CtlID,     g_DrawItem.CtlID, "%d");
1485         compare(di->hwndItem,  g_DrawItem.hwndItem, "%p");
1486         compare(di->itemID,    g_DrawItem.itemID, "%d");
1487         compare(di->itemState, g_DrawItem.itemState, "%d");
1488         compare(di->rcItem.left,   g_DrawItem.rcItem.left, "%d");
1489         compare(di->rcItem.top,    g_DrawItem.rcItem.top, "%d");
1490         compare(di->rcItem.right,  g_DrawItem.rcItem.right, "%d");
1491         compare(di->rcItem.bottom, g_DrawItem.rcItem.bottom, "%d");
1492         break;
1493
1494     case WM_DESTROY:
1495         PostQuitMessage(0);
1496         break;
1497   
1498     default:
1499         return DefWindowProcA(hWnd, msg, wParam, lParam);
1500     }
1501     
1502     return 0L;
1503 }
1504
1505 static int init(void)
1506 {
1507     HMODULE hComctl32;
1508     BOOL (WINAPI *pInitCommonControlsEx)(const INITCOMMONCONTROLSEX*);
1509     WNDCLASSA wc;
1510     INITCOMMONCONTROLSEX iccex;
1511     TEXTMETRICA tm;
1512     HFONT hOldFont;
1513     HDC hdc;
1514
1515     hComctl32 = GetModuleHandleA("comctl32.dll");
1516     pInitCommonControlsEx = (void*)GetProcAddress(hComctl32, "InitCommonControlsEx");
1517     if (!pInitCommonControlsEx)
1518     {
1519         skip("InitCommonControlsEx() is missing. Skipping the tests\n");
1520         return 0;
1521     }
1522
1523     iccex.dwSize = sizeof(iccex);
1524     iccex.dwICC  = ICC_USEREX_CLASSES;
1525     pInitCommonControlsEx(&iccex);
1526
1527     wc.style = CS_HREDRAW | CS_VREDRAW;
1528     wc.cbClsExtra = 0;
1529     wc.cbWndExtra = 0;
1530     wc.hInstance = GetModuleHandleA(NULL);
1531     wc.hIcon = NULL;
1532     wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
1533     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
1534     wc.lpszMenuName = NULL;
1535     wc.lpszClassName = "HeaderTestClass";
1536     wc.lpfnWndProc = HeaderTestWndProc;
1537     RegisterClassA(&wc);
1538
1539     /* The height of the header control depends on the height of the system font.
1540        The height of the system font is dpi dependent */
1541     hdc = GetDC(0);
1542     hOldFont = SelectObject(hdc, GetStockObject(SYSTEM_FONT));
1543     GetTextMetricsA(hdc, &tm);
1544     /* 2 dot extra space are needed for the border */
1545     g_customheight = tm.tmHeight + 2;
1546     trace("customdraw height: %d (dpi: %d)\n", g_customheight, GetDeviceCaps(hdc, LOGPIXELSY));
1547     SelectObject(hdc, hOldFont);
1548     ReleaseDC(0, hdc);
1549
1550     hHeaderParentWnd = CreateWindowExA(0, "HeaderTestClass", "Header test", WS_OVERLAPPEDWINDOW, 
1551       CW_USEDEFAULT, CW_USEDEFAULT, 672+2*GetSystemMetrics(SM_CXSIZEFRAME),
1552       226+GetSystemMetrics(SM_CYCAPTION)+2*GetSystemMetrics(SM_CYSIZEFRAME),
1553       NULL, NULL, GetModuleHandleA(NULL), 0);
1554     assert(hHeaderParentWnd != NULL);
1555     ShowWindow(hHeaderParentWnd, SW_SHOW);
1556     return 1;
1557 }
1558
1559 START_TEST(header)
1560 {
1561     HWND parent_hwnd;
1562
1563     if (!init())
1564         return;
1565
1566     test_header_control();
1567     test_header_order();
1568     test_customdraw();
1569
1570     DestroyWindow(hHeaderParentWnd);
1571
1572     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1573     parent_hwnd = create_custom_parent_window();
1574     ok_sequence(sequences, PARENT_SEQ_INDEX, create_parent_wnd_seq, "create parent windows", FALSE);
1575
1576     test_hdm_index_messages(parent_hwnd);
1577     test_hdm_getitemrect(parent_hwnd);
1578     test_hdm_hittest(parent_hwnd);
1579     test_hdm_layout(parent_hwnd);
1580     test_hdm_ordertoindex(parent_hwnd);
1581     test_hdm_sethotdivider(parent_hwnd);
1582     test_hdm_imageMessages(parent_hwnd);
1583     test_hdm_filterMessages(parent_hwnd);
1584     test_hdm_unicodeformatMessages(parent_hwnd);
1585     test_hdm_bitmapmarginMessages(parent_hwnd);
1586
1587     DestroyWindow(parent_hwnd);
1588
1589 }