1 /* Unit test suite for static controls.
3 * Copyright 2007 Google (Mikolaj Zalewski)
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.
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.
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
26 #define WIN32_LEAN_AND_MEAN
30 #include "wine/test.h"
39 static int g_nReceivedColorStatic
;
41 /* try to make sure pending X events have been processed before continuing */
42 static void flush_events(void)
46 int min_timeout
= 100;
47 DWORD time
= GetTickCount() + diff
;
51 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
52 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
53 diff
= time
- GetTickCount();
57 static HWND
create_static(DWORD style
)
59 return CreateWindowA(WC_STATICA
, "Test", WS_VISIBLE
|WS_CHILD
|style
, 5, 5, 100, 100, hMainWnd
, (HMENU
)CTRL_ID
, NULL
, 0);
62 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
66 case WM_CTLCOLORSTATIC
:
68 HDC hdc
= (HDC
)wparam
;
69 HRGN hrgn
= CreateRectRgn(0, 0, 1, 1);
70 ok(GetClipRgn(hdc
, hrgn
) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
72 g_nReceivedColorStatic
++;
73 return (LRESULT
) GetStockObject(BLACK_BRUSH
);
78 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
81 static void test_updates(int style
, int flags
)
83 HWND hStatic
= create_static(style
);
84 RECT r1
= {20, 20, 30, 30};
88 g_nReceivedColorStatic
= 0;
89 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
90 InvalidateRect(hMainWnd
, NULL
, FALSE
);
91 UpdateWindow(hMainWnd
);
92 InvalidateRect(hMainWnd
, &r1
, FALSE
);
93 UpdateWindow(hMainWnd
);
94 InvalidateRect(hStatic
, &r1
, FALSE
);
95 UpdateWindow(hStatic
);
96 InvalidateRect(hStatic
, NULL
, FALSE
);
97 UpdateWindow(hStatic
);
99 if ((style
& SS_TYPEMASK
) == SS_BITMAP
)
101 HDC hdc
= GetDC(hStatic
);
102 COLORREF colour
= GetPixel(hdc
, 10, 10);
104 ok(colour
== 0, "Unexpected pixel color.\n");
105 ReleaseDC(hStatic
, hdc
);
108 if (style
!= SS_ETCHEDHORZ
&& style
!= SS_ETCHEDVERT
)
111 exp
= 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
113 if (flags
& TODO_COUNT
)
115 ok(g_nReceivedColorStatic
== exp
, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic
);
116 else if ((style
& SS_TYPEMASK
) == SS_ICON
|| (style
& SS_TYPEMASK
) == SS_BITMAP
)
117 ok(g_nReceivedColorStatic
== exp
, "Unexpected %u got %u\n", exp
, g_nReceivedColorStatic
);
119 ok(g_nReceivedColorStatic
== exp
, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic
);
120 DestroyWindow(hStatic
);
123 static void test_set_text(void)
125 HWND hStatic
= create_static(SS_SIMPLE
);
128 GetWindowTextA(hStatic
, buffA
, sizeof(buffA
));
129 ok(!strcmp(buffA
, "Test"), "got wrong text %s\n", buffA
);
131 SetWindowTextA(hStatic
, NULL
);
132 GetWindowTextA(hStatic
, buffA
, sizeof(buffA
));
133 ok(buffA
[0] == 0, "got wrong text %s\n", buffA
);
135 DestroyWindow(hStatic
);
140 static const char classname
[] = "testclass";
141 WNDCLASSEXA wndclass
;
142 ULONG_PTR ctx_cookie
;
145 if (!load_v6_module(&ctx_cookie
, &hCtx
))
148 wndclass
.cbSize
= sizeof(wndclass
);
149 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
;
150 wndclass
.lpfnWndProc
= WndProc
;
151 wndclass
.cbClsExtra
= 0;
152 wndclass
.cbWndExtra
= 0;
153 wndclass
.hInstance
= GetModuleHandleA(NULL
);
154 wndclass
.hIcon
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
155 wndclass
.hIconSm
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
156 wndclass
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
157 wndclass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
158 wndclass
.lpszClassName
= classname
;
159 wndclass
.lpszMenuName
= NULL
;
160 RegisterClassExA(&wndclass
);
162 hMainWnd
= CreateWindowA(classname
, "Test", WS_OVERLAPPEDWINDOW
, 0, 0, 500, 500, NULL
, NULL
,
163 GetModuleHandleA(NULL
), NULL
);
164 ShowWindow(hMainWnd
, SW_SHOW
);
167 test_updates(SS_SIMPLE
, 0);
168 test_updates(SS_ICON
, 0);
169 test_updates(SS_BITMAP
, 0);
170 test_updates(SS_BITMAP
| SS_CENTERIMAGE
, 0);
171 test_updates(SS_BLACKRECT
, TODO_COUNT
);
172 test_updates(SS_WHITERECT
, TODO_COUNT
);
173 test_updates(SS_ETCHEDHORZ
, TODO_COUNT
);
174 test_updates(SS_ETCHEDVERT
, TODO_COUNT
);
177 DestroyWindow(hMainWnd
);
179 unload_v6_module(ctx_cookie
, hCtx
);