1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 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"
29 static LRESULT CALLBACK win32WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
31 Win32Window* window = reinterpret_cast<Win32Window*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
33 return window->windowProc(uMsg, wParam, lParam);
35 return DefWindowProc(hWnd, uMsg, wParam, lParam);
38 Win32Window::Win32Window (HINSTANCE instance, int width, int height)
43 static const char s_className[] = "dEQP Test Process Class";
44 static const char s_windowName[] = "dEQP Test Process";
48 memset(&wndClass, 0, sizeof(wndClass));
49 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
50 wndClass.lpfnWndProc = win32WindowProc;
51 wndClass.cbClsExtra = 0;
52 wndClass.cbWndExtra = 0;
53 wndClass.hInstance = instance;
54 wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
55 wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
56 wndClass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
57 wndClass.lpszMenuName = NULL;
58 wndClass.lpszClassName = s_className;
60 RegisterClass(&wndClass);
63 m_window = CreateWindow(s_className, s_windowName,
64 WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
65 CW_USEDEFAULT, CW_USEDEFAULT,
67 NULL, NULL, instance, NULL);
70 TCU_THROW(ResourceError, "Failed to create Win32 window");
72 // Store this as userdata
73 SetWindowLongPtr(m_window, GWLP_USERDATA, (LONG_PTR)this);
75 setSize(width, height);
80 DestroyWindow(m_window);
86 Win32Window::~Win32Window (void)
90 // Clear this pointer from windowproc
91 SetWindowLongPtr(m_window, GWLP_USERDATA, 0);
94 DestroyWindow(m_window);
97 void Win32Window::setVisible (bool visible)
99 ShowWindow(m_window, visible ? SW_SHOW : SW_HIDE);
102 void Win32Window::setSize (int width, int height)
111 if (!AdjustWindowRect(&rc, GetWindowLong(m_window, GWL_STYLE), GetMenu(m_window) != NULL))
112 TCU_THROW(TestError, "AdjustWindowRect() failed");
114 if (!SetWindowPos(m_window, NULL, 0, 0,
115 rc.right - rc.left, rc.bottom - rc.top,
116 SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER))
117 TCU_THROW(TestError, "SetWindowPos() failed");
120 IVec2 Win32Window::getSize (void) const
123 if (!GetClientRect(m_window, &rc))
124 TCU_THROW(TestError, "GetClientRect() failed");
126 return IVec2(rc.right - rc.left,
130 void Win32Window::processEvents (void)
133 while (PeekMessage(&msg, m_window, 0, 0, PM_REMOVE))
134 DispatchMessage(&msg);
137 LRESULT Win32Window::windowProc (UINT uMsg, WPARAM wParam, LPARAM lParam)
141 // \todo [2014-03-12 pyry] Handle WM_SIZE?
148 if (wParam == VK_ESCAPE)
156 return DefWindowProc(m_window, uMsg, wParam, lParam);