1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2016 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Generic Win32 window class.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuWin32Window.hpp"
31 static LRESULT CALLBACK windowProcCallback (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
33 Window* window = reinterpret_cast<Window*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
35 return window->windowProc(uMsg, wParam, lParam);
37 return DefWindowProc(hWnd, uMsg, wParam, lParam);
40 Window::Window (HINSTANCE instance, int width, int height)
45 static const char s_className[] = "dEQP Test Process Class";
46 static const char s_windowName[] = "dEQP Test Process";
50 memset(&wndClass, 0, sizeof(wndClass));
51 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
52 wndClass.lpfnWndProc = windowProcCallback;
53 wndClass.cbClsExtra = 0;
54 wndClass.cbWndExtra = 0;
55 wndClass.hInstance = instance;
56 wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
57 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
58 wndClass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
59 wndClass.lpszMenuName = NULL;
60 wndClass.lpszClassName = s_className;
62 RegisterClass(&wndClass);
65 m_window = CreateWindow(s_className, s_windowName,
66 WS_CLIPCHILDREN | WS_POPUP,
67 CW_USEDEFAULT, CW_USEDEFAULT,
69 NULL, NULL, instance, NULL);
72 TCU_THROW(ResourceError, "Failed to create Win32 window");
74 // Store this as userdata
75 SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR)this);
77 setSize(width, height);
82 DestroyWindow(m_window);
88 Window::~Window (void)
92 // Clear this pointer from windowproc
93 SetWindowLongPtr(m_window, GWLP_USERDATA, 0);
96 DestroyWindow(m_window);
99 void Window::setVisible (bool visible)
101 ShowWindow(m_window, visible ? SW_SHOW : SW_HIDE);
104 void Window::setSize (int width, int height)
113 if (!AdjustWindowRect(&rc, GetWindowLong(m_window, GWL_STYLE), GetMenu(m_window) != NULL))
114 TCU_THROW(TestError, "AdjustWindowRect() failed");
116 if (!SetWindowPos(m_window, NULL, 0, 0,
117 rc.right - rc.left, rc.bottom - rc.top,
118 SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER))
119 TCU_THROW(TestError, "SetWindowPos() failed");
122 IVec2 Window::getSize (void) const
125 if (!GetClientRect(m_window, &rc))
126 TCU_THROW(TestError, "GetClientRect() failed");
128 return IVec2(rc.right - rc.left,
132 void Window::processEvents (void)
135 while (PeekMessage(&msg, m_window, 0, 0, PM_REMOVE))
136 DispatchMessage(&msg);
139 LRESULT Window::windowProc (UINT uMsg, WPARAM wParam, LPARAM lParam)
143 // \todo [2014-03-12 pyry] Handle WM_SIZE?
150 if (wParam == VK_ESCAPE)
158 return DefWindowProc(m_window, uMsg, wParam, lParam);