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
25 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
36 #define expect_eq(expr, value, type, fmt) { type val = expr; ok(val == (value), #expr " expected " fmt " got " fmt "\n", (value), val); }
37 #define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
38 r.bottom == _bottom && r.right == _right, "Invalid rect (%d,%d) (%d,%d) vs (%d,%d) (%d,%d)\n", \
39 r.left, r.top, r.right, r.bottom, _left, _top, _right, _bottom);
41 static int g_nReceivedColorStatic = 0;
43 static HWND build_static(DWORD style)
45 return CreateWindow("static", "Test", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)CTRL_ID, NULL, 0);
48 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
52 case WM_CTLCOLORSTATIC:
54 HDC hdc = (HDC)wparam;
55 HRGN hrgn = CreateRectRgn(0, 0, 1, 1);
56 ok(GetClipRgn(hdc, hrgn) == 1, "Static controls during a WM_CTLCOLORSTATIC must have a clipping region\n");
58 g_nReceivedColorStatic++;
59 return (LRESULT) GetStockObject(BLACK_BRUSH);
64 return DefWindowProc(hwnd, msg, wparam, lparam);
67 static void test_updates(int style, int flags)
69 RECT r1 = {20, 20, 30, 30};
70 HWND hStatic = build_static(style);
73 trace("Testing style 0x%x\n", style);
74 g_nReceivedColorStatic = 0;
75 /* during each update parent WndProc will test the WM_CTLCOLORSTATIC message */
76 InvalidateRect(hMainWnd, NULL, FALSE);
77 UpdateWindow(hMainWnd);
78 InvalidateRect(hMainWnd, &r1, FALSE);
79 UpdateWindow(hMainWnd);
80 InvalidateRect(hStatic, &r1, FALSE);
81 UpdateWindow(hStatic);
82 InvalidateRect(hStatic, NULL, FALSE);
83 UpdateWindow(hStatic);
85 if( (style & SS_TYPEMASK) == SS_BITMAP) {
86 HDC hdc = GetDC( hStatic);
87 COLORREF colour = GetPixel( hdc, 10, 10);
88 ok ( colour != 0, "pixel should NOT be painted black!\n");
90 if (style != SS_ETCHEDHORZ && style != SS_ETCHEDVERT)
93 exp = 1; /* SS_ETCHED* seems to send WM_CTLCOLORSTATIC only sometimes */
95 if (flags & TODO_COUNT)
96 todo_wine { expect_eq(g_nReceivedColorStatic, exp, int, "%d"); }
97 else if ((style & SS_TYPEMASK) == SS_ICON || (style & SS_TYPEMASK) == SS_BITMAP)
98 ok( g_nReceivedColorStatic == exp ||
99 broken(g_nReceivedColorStatic == 0), /* win9x */
100 "expected %u got %u\n", exp, g_nReceivedColorStatic );
102 expect_eq(g_nReceivedColorStatic, exp, int, "%d");
103 DestroyWindow(hStatic);
108 static char szClassName[] = "testclass";
111 wndclass.cbSize = sizeof(wndclass);
112 wndclass.style = CS_HREDRAW | CS_VREDRAW;
113 wndclass.lpfnWndProc = WndProc;
114 wndclass.cbClsExtra = 0;
115 wndclass.cbWndExtra = 0;
116 wndclass.hInstance = GetModuleHandle(NULL);
117 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
118 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
119 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
120 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
121 wndclass.lpszClassName = szClassName;
122 wndclass.lpszMenuName = NULL;
123 RegisterClassEx(&wndclass);
125 hMainWnd = CreateWindow(szClassName, "Test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, GetModuleHandle(NULL), NULL);
126 ShowWindow(hMainWnd, SW_SHOW);
127 UpdateWindow(hMainWnd);
130 test_updates(SS_SIMPLE, 0);
131 test_updates(SS_ICON, 0);
132 test_updates(SS_BITMAP, 0);
133 test_updates(SS_BITMAP | SS_CENTERIMAGE, 0);
134 test_updates(SS_BLACKRECT, TODO_COUNT);
135 test_updates(SS_WHITERECT, TODO_COUNT);
136 test_updates(SS_ETCHEDHORZ, TODO_COUNT);
137 test_updates(SS_ETCHEDVERT, TODO_COUNT);
139 DestroyWindow(hMainWnd);