[COMCTL32_APITEST] -Add tests for the BST_HOT state.
[reactos.git] / rostests / apitests / comctl32 / button.c
index 275589f..2cf2f54 100644 (file)
@@ -6,12 +6,16 @@
  */
 
 #include "wine/test.h"
+#include <stdio.h>
 #include <windows.h>
 #include <commctrl.h>
 #include <uxtheme.h>
+#include <undocuser.h>
+#include <msgtrace.h>
+#include <user32testhelpers.h>
 
 #define ok_rect(rc, l,r,t,b) ok((rc.left == (l)) && (rc.right == (r)) && (rc.top == (t)) && (rc.bottom == (b)), "Wrong rect. expected %d, %d, %d, %d got %ld, %ld, %ld, %ld\n", l,t,r,b, rc.left, rc.top, rc.right, rc.bottom)
-#define ok_size(s, width, height) ok((s.cx == (width) && s.cy == (height)), "Expected size (%lu,%lu) got (%lu,%lu)\n", width, height, s.cx, s.cy)
+#define ok_size(s, width, height) ok((s.cx == (width) && s.cy == (height)), "Expected size (%lu,%lu) got (%lu,%lu)\n", (LONG)width, (LONG)height, s.cx, s.cy)
 
 void Test_TextMargin()
 {
@@ -52,6 +56,17 @@ void Test_TextMargin()
     ok_rect(rc, 1000, 1000, 1000, 1000);
     
     DestroyWindow(hwnd1);
+
+    hwnd1 = CreateWindowW(L"Button", L"Test1", BS_DEFPUSHBUTTON, 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowTheme(hwnd1, L"", L"");
+
+    ret = SendMessageW(hwnd1, BCM_GETTEXTMARGIN, 0, (LPARAM)&rc);
+    ok (ret == TRUE, "Expected BCM_GETTEXTMARGIN to succeed\n");
+    ok_rect(rc, 1, 1, 1, 1);
+
+    DestroyWindow(hwnd1);
+
 }
 
 void Test_Imagelist()
@@ -92,7 +107,7 @@ void Test_Imagelist()
 
 void Test_GetIdealSizeNoThemes()
 {
-    HWND hwnd1;
+    HWND hwnd1, hwnd2;
     BOOL ret;
     SIZE s, textent;
     HFONT font;
@@ -102,8 +117,12 @@ void Test_GetIdealSizeNoThemes()
     BUTTON_IMAGELIST imlData;
     RECT rc;
     LOGFONTW lf;
+    DWORD i;
 
-    hwnd1 = CreateWindowW(L"Button", L" ", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    hwnd2 = CreateWindowW(L"Static", L"", 0, 0, 0, 100, 100, 0, NULL, NULL, NULL);
+    ok (hwnd2 != NULL, "Expected CreateWindowW to succeed\n");
+
+    hwnd1 = CreateWindowW(L"Button", L" ", WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
@@ -121,24 +140,29 @@ void Test_GetIdealSizeNoThemes()
     DestroyWindow(hwnd1);
 
 
-
-
-    hwnd1 = CreateWindowW(L"Button", L"", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    hwnd1 = CreateWindowW(L"Button", L" ", BS_USERBUTTON | WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
     memset(&s, 0, sizeof(s));
     ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
     ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
-    ok (s.cx > 80, "Expected big cx\n");
-    ok (s.cy > 80, "Expected big cy\n");
+    ok_size(s, textent.cx + 5 + 2, 
+               textent.cy + 7 + 2); /* the last +2 is the text margin */
+
+    DestroyWindow(hwnd1);
+
+
+
+    hwnd1 = CreateWindowW(L"Button", L"", WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
+    ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowTheme(hwnd1, L"", L"");
 
     s.cx = 1;
     s.cy = 1;
     ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
     ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
-    ok (s.cx > 80, "Expected big cx\n");
-    ok (s.cy > 80, "Expected big cy\n");
+    ok_size(s, 100, 100);
 
     hbmp = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(5), IMAGE_BITMAP, 0, 0, 0);
     ok (hbmp != 0, "Expected LoadImage to succeed\n");
@@ -148,8 +172,7 @@ void Test_GetIdealSizeNoThemes()
     memset(&s, 0, sizeof(s));
     ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
     ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
-    ok (s.cx > 80, "Expected big cx\n");
-    ok (s.cy > 80, "Expected big cy\n");
+    ok_size(s, 100, 100);
 
     himl = ImageList_LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(5), 1, 1, 0, IMAGE_BITMAP, 0);
     ok (himl != 0, "Expected ImageList_LoadImage to succeed\n");
@@ -162,15 +185,29 @@ void Test_GetIdealSizeNoThemes()
     memset(&s, 0, sizeof(s));
     ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
     ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
-    ok (s.cx > 80, "Expected big cx\n");
-    ok (s.cy > 80, "Expected big cy\n");
+    ok_size(s, 100, 100);
+
+    DestroyWindow(hwnd1);
+
+
+
+
+
+    hwnd1 = CreateWindowW(L"Button", L"",  WS_CHILD, 10, 10, 5, 5, hwnd2, NULL, NULL, NULL);
+    ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowTheme(hwnd1, L"", L"");
+
+    memset(&s, 0, sizeof(s));
+    ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+    ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+    ok_size(s, 5, 5);
 
     DestroyWindow(hwnd1);
 
 
 
 
-    hwnd1 = CreateWindowW(L"Button", L" ", BS_BITMAP , 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    hwnd1 = CreateWindowW(L"Button", L" ", BS_BITMAP | WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
@@ -188,7 +225,7 @@ void Test_GetIdealSizeNoThemes()
 
 
 
-    hwnd1 = CreateWindowW(L"Button", L" ", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    hwnd1 = CreateWindowW(L"Button", L" ", WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
@@ -267,7 +304,7 @@ void Test_GetIdealSizeNoThemes()
 
 
 
-    hwnd1 = CreateWindowW(L"Button", L"Start", BS_VCENTER, 0, 0, 0, 0, 0, NULL, NULL, NULL);
+    hwnd1 = CreateWindowW(L"Button", L"Start", BS_VCENTER | WS_CHILD, 0, 0, 0, 0, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
@@ -291,7 +328,7 @@ void Test_GetIdealSizeNoThemes()
 
 
     /* Test again with some real text to see if the formula is correct */
-    hwnd1 = CreateWindowW(L"Button", L"Some test text", 0, 10, 10, 100, 100, 0, NULL, NULL, NULL);
+    hwnd1 = CreateWindowW(L"Button", L"Some test text", WS_CHILD, 10, 10, 100, 100, hwnd2, NULL, NULL, NULL);
     ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
     SetWindowTheme(hwnd1, L"", L"");
 
@@ -326,9 +363,425 @@ void Test_GetIdealSizeNoThemes()
 
     DestroyWindow(hwnd1);
 
+    for (i = BS_PUSHBUTTON; i <= BS_OWNERDRAW; i++)
+    {
+        if (i == BS_USERBUTTON)
+            continue;
+
+        if (i >= BS_CHECKBOX)
+        {
+            hwnd1 = CreateWindowW(L"Button", L" ", i|WS_CHILD, 0, 0, 72, 72, hwnd2, NULL, NULL, NULL);
+            ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+            memset(&s, 0, sizeof(s));
+            ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+            ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+            ok_size(s, 72, 72);
+
+            SetWindowTheme(hwnd1, L"", L"");
+            memset(&s, 0, sizeof(s));
+            ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+            ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+            ok_size(s, 72, 72);
+            DestroyWindow(hwnd1);
+
+            hwnd1 = CreateWindowW(L"Button", L" ", i|WS_CHILD, 0, 0, 12, 12, hwnd2, NULL, NULL, NULL);
+            ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+            memset(&s, 0, sizeof(s));
+            ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+            ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+            ok_size(s, 12, 12);
+            DestroyWindow(hwnd1);
+        }
+
+        hwnd1 = CreateWindowW(L"Button", L"", i|WS_CHILD, 0, 0, 72, 72, hwnd2, NULL, NULL, NULL);
+        ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+        memset(&s, 0, sizeof(s));
+        ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+        ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+        ok_size(s, 72, 72);
+        DestroyWindow(hwnd1);
+        
+        hwnd1 = CreateWindowW(L"Button", L"", i|WS_CHILD, 0, 0, 150, 72, hwnd2, NULL, NULL, NULL);
+        ok (hwnd1 != NULL, "Expected CreateWindowW to succeed\n");
+        memset(&s, 0, sizeof(s));
+        ret = SendMessageW(hwnd1, BCM_GETIDEALSIZE, 0, (LPARAM)&s);
+        ok (ret == TRUE, "Expected BCM_GETIDEALSIZE to succeed\n");
+        ok_size(s, 150, 72);
+        DestroyWindow(hwnd1);
+    }
+    DestroyWindow(hwnd2);
+}
+
+
+HWND hWnd1, hWnd2;
+
+#define MOVE_CURSOR(x,y) mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE ,                           \
+                                     x*(65535/GetSystemMetrics(SM_CXVIRTUALSCREEN)),                     \
+                                     y*(65535/GetSystemMetrics(SM_CYVIRTUALSCREEN)) , 0,0);
+
+static int get_iwnd(HWND hWnd)
+{
+    if(hWnd == hWnd1) return 1;
+    else if(hWnd == hWnd2) return 2;
+    else return 0;
+}
+
+static LRESULT CALLBACK subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR ref_data)
+{
+    int iwnd = get_iwnd(hwnd);
+
+    if(message > WM_USER || !iwnd )
+        return DefSubclassProc(hwnd, message, wParam, lParam);
+
+    switch(message)
+    {
+    case WM_IME_SETCONTEXT:
+    case WM_IME_NOTIFY :
+    case WM_GETICON :
+    case WM_GETTEXT:
+    case WM_GETTEXTLENGTH:
+        break;
+    case WM_NOTIFY:
+    {
+        NMHDR* pnmhdr = (NMHDR*)lParam;
+        RECORD_MESSAGE(iwnd, message, SENT, pnmhdr->idFrom,pnmhdr->code);
+        break;
+    }
+    default:
+        RECORD_MESSAGE(iwnd, message, SENT, 0,0);
+    }
+    return DefSubclassProc(hwnd, message, wParam, lParam);
+}
+
+static LRESULT CALLBACK TestProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    int iwnd = get_iwnd(hwnd);
+
+    if (iwnd != 0  && message == WM_NOTIFY)
+    {
+        NMHDR* pnmhdr = (NMHDR*)lParam;
+        RECORD_MESSAGE(iwnd, message, SENT, pnmhdr->idFrom,pnmhdr->code);
+    }
+    else if (iwnd != 0 && message < WM_USER && message != WM_GETICON)
+    {
+        RECORD_MESSAGE(iwnd, message, SENT, 0,0);
+    }
+
+    return DefWindowProc(hwnd, message, wParam, lParam);
+}
 
+static void FlushMessages()
+{
+    MSG msg;
+
+    while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
+    {
+        int iwnd = get_iwnd(msg.hwnd);
+        if(iwnd)
+        {
+            if(msg.message <= WM_USER && iwnd != 0)
+                RECORD_MESSAGE(iwnd, msg.message, POST,0,0);
+        }
+        DispatchMessageW( &msg );
+    }
+}
 
+MSG_ENTRY erase_sequence[]={
+    {2, WM_PAINT, POST},
+    {1, WM_ERASEBKGND},
+    {1, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY erase_nonthemed_sequence[]={
+    {2, WM_PAINT, POST},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY printclnt_nonthemed_sequence[]={
+    {2, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY printclnt_sequence[]={
+    {2, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY pseudomove_sequence[]={
+    {2, WM_MOUSEMOVE},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_MOUSELEAVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_ERASEBKGND},
+    {1, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY pseudomove_nonthemed_sequence[]={
+    {2, WM_MOUSEMOVE},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_MOUSELEAVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY pseudohover_sequence[]={
+    {2, WM_MOUSEHOVER},
+    {0,0}};
+
+MSG_ENTRY pseudoleave_sequence[]={
+    {2, WM_MOUSELEAVE},
+    {0,0}};
+
+MSG_ENTRY mouseenter_sequence[]={
+    {2, WM_NCHITTEST},
+    {2, WM_SETCURSOR},
+    {1, WM_SETCURSOR},
+    {2, WM_MOUSEMOVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_ERASEBKGND},
+    {1, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY mouseenter_nonthemed_sequence[]={
+    {2, WM_NCHITTEST},
+    {2, WM_SETCURSOR},
+    {1, WM_SETCURSOR},
+    {2, WM_MOUSEMOVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY mousemove_sequence[]={
+    {2, WM_NCHITTEST},
+    {2, WM_SETCURSOR},
+    {1, WM_SETCURSOR},
+    {2, WM_MOUSEMOVE, POST},
+    {0,0}};
+
+MSG_ENTRY mouseleave_sequence[]={
+    {2, WM_MOUSELEAVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_ERASEBKGND},
+    {1, WM_PRINTCLIENT},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+MSG_ENTRY mouseleave_nonthemed_sequence[]={
+    {2, WM_MOUSELEAVE, POST},
+    {1, WM_NOTIFY, SENT, 0, BCN_HOTITEMCHANGE},
+    {2, WM_PAINT, POST},
+    {2, WM_ERASEBKGND},
+    {1, WM_CTLCOLORBTN},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {1, WM_NOTIFY, SENT, 0, NM_CUSTOMDRAW},
+    {0,0}};
+
+void Test_MessagesNonThemed()
+{
+    DWORD state;
+
+    MOVE_CURSOR(0,0);
+    EMPTY_CACHE();
+
+    RegisterSimpleClass(TestProc, L"testClass");
+    hWnd1 = CreateWindowW(L"testClass", L"Test parent", WS_POPUP | WS_VISIBLE, 100, 100, 200, 200, 0, NULL, NULL, NULL);
+    ok (hWnd1 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowTheme(hWnd1, L"", L"");
+    UpdateWindow(hWnd1);
+
+    hWnd2 = CreateWindowW(L"Button", L"test button", /*BS_RADIOBUTTON | */WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, hWnd1, NULL, NULL, NULL);
+    ok (hWnd2 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowTheme(hWnd2, L"", L"");
+    SetWindowSubclass(hWnd2, subclass_proc, 0, 0);
+    UpdateWindow(hWnd2);
+
+    FlushMessages();
+    EMPTY_CACHE();
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_ERASE);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_FRAME);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_INTERNALPAINT);
+    FlushMessages();
+    COMPARE_CACHE(erase_nonthemed_sequence);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_INVALIDATE);
+    FlushMessages();
+    COMPARE_CACHE(erase_nonthemed_sequence);
+
+    SendMessageW(hWnd2, WM_PRINTCLIENT, 0, PRF_ERASEBKGND);
+    FlushMessages();
+    COMPARE_CACHE(printclnt_nonthemed_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSEMOVE, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudomove_nonthemed_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSEHOVER, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudohover_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSELEAVE, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudoleave_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == 0, "Expected state 0, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(150,150);
+    FlushMessages();
+    COMPARE_CACHE(mouseenter_nonthemed_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == BST_HOT, "Expected state BST_HOT, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(151,151);
+    FlushMessages();
+    COMPARE_CACHE(mousemove_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == BST_HOT, "Expected state BST_HOT, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(0,0);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+    FlushMessages();
+    COMPARE_CACHE(mouseleave_nonthemed_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == 0, "Expected state 0, got %lu", state);
+    EMPTY_CACHE();
+
+    DestroyWindow(hWnd1);
+    DestroyWindow(hWnd2);
+}
 
+void Test_MessagesThemed()
+{
+    DWORD state;
+
+    MOVE_CURSOR(0,0);
+    EMPTY_CACHE();
+
+    RegisterSimpleClass(TestProc, L"testClass");
+    hWnd1 = CreateWindowW(L"testClass", L"Test parent", WS_POPUP | WS_VISIBLE, 100, 100, 200, 200, 0, NULL, NULL, NULL);
+    ok (hWnd1 != NULL, "Expected CreateWindowW to succeed\n");
+    UpdateWindow(hWnd1);
+
+    hWnd2 = CreateWindowW(L"Button", L"test button", /*BS_RADIOBUTTON | */WS_CHILD | WS_VISIBLE, 0, 0, 100, 100, hWnd1, NULL, NULL, NULL);
+    ok (hWnd2 != NULL, "Expected CreateWindowW to succeed\n");
+    SetWindowSubclass(hWnd2, subclass_proc, 0, 0);
+    UpdateWindow(hWnd2);
+
+    FlushMessages();
+    EMPTY_CACHE();
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_ERASE);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_FRAME);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_INTERNALPAINT);
+    FlushMessages();
+    COMPARE_CACHE(erase_sequence);
+
+    RedrawWindow(hWnd2, NULL, NULL, RDW_INVALIDATE);
+    FlushMessages();
+    COMPARE_CACHE(erase_sequence);
+
+    SendMessageW(hWnd2, WM_PRINTCLIENT, 0, PRF_ERASEBKGND);
+    FlushMessages();
+    COMPARE_CACHE(printclnt_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSEMOVE, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudomove_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSEHOVER, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudohover_sequence);
+
+    SendMessageW(hWnd2, WM_MOUSELEAVE, 0, 0);
+    FlushMessages();
+    COMPARE_CACHE(pseudoleave_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == 0, "Expected state 0, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(150,150);
+    FlushMessages();
+    COMPARE_CACHE(mouseenter_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == BST_HOT, "Expected state BST_HOT, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(151,151);
+    FlushMessages();
+    COMPARE_CACHE(mousemove_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == BST_HOT, "Expected state BST_HOT, got %lu", state);
+    EMPTY_CACHE();
+
+    MOVE_CURSOR(0,0);
+    FlushMessages();
+    COMPARE_CACHE(empty_chain);
+    FlushMessages();
+    COMPARE_CACHE(mouseleave_sequence);
+
+    state = SendMessageW(hWnd2, BM_GETSTATE,0,0);
+    ok(state == 0, "Expected state 0, got %lu", state);
+    EMPTY_CACHE();
+
+    DestroyWindow(hWnd1);
+    DestroyWindow(hWnd2);
 }
 
 START_TEST(button)
@@ -337,5 +790,12 @@ START_TEST(button)
     Test_TextMargin();
     Test_Imagelist();
     Test_GetIdealSizeNoThemes();
+
+    Test_MessagesNonThemed();
+    if (IsThemeActive())
+        Test_MessagesThemed();
+    else
+        skip("No active theme, skipping Test_MessagesThemed\n");
+
 }