OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Window_win.h" | 8 #include "Window_win.h" |
9 | 9 |
10 #include <tchar.h> | 10 #include <tchar.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (!window->init(hInstance)) { | 26 if (!window->init(hInstance)) { |
27 delete window; | 27 delete window; |
28 return nullptr; | 28 return nullptr; |
29 } | 29 } |
30 | 30 |
31 return window; | 31 return window; |
32 } | 32 } |
33 | 33 |
34 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | 34 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
35 | 35 |
| 36 |
36 bool Window_win::init(HINSTANCE hInstance) { | 37 bool Window_win::init(HINSTANCE hInstance) { |
37 fHInstance = hInstance ? hInstance : GetModuleHandle(nullptr); | 38 fHInstance = hInstance ? hInstance : GetModuleHandle(nullptr); |
38 | 39 |
39 WNDCLASSEX wcex; | |
40 // The main window class name | 40 // The main window class name |
41 static const TCHAR gSZWindowClass[] = _T("SkiaApp"); | 41 static const TCHAR gSZWindowClass[] = _T("SkiaApp"); |
42 | 42 |
43 wcex.cbSize = sizeof(WNDCLASSEX); | 43 static WNDCLASSEX wcex; |
| 44 static bool wcexInit = false; |
| 45 if (!wcexInit) { |
| 46 wcex.cbSize = sizeof(WNDCLASSEX); |
44 | 47 |
45 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; | 48 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; |
46 wcex.lpfnWndProc = WndProc; | 49 wcex.lpfnWndProc = WndProc; |
47 wcex.cbClsExtra = 0; | 50 wcex.cbClsExtra = 0; |
48 wcex.cbWndExtra = 0; | 51 wcex.cbWndExtra = 0; |
49 wcex.hInstance = fHInstance; | 52 wcex.hInstance = fHInstance; |
50 wcex.hIcon = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO); | 53 wcex.hIcon = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO); |
51 wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);; | 54 wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);; |
52 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | 55 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); |
53 wcex.lpszMenuName = nullptr; | 56 wcex.lpszMenuName = nullptr; |
54 wcex.lpszClassName = gSZWindowClass; | 57 wcex.lpszClassName = gSZWindowClass; |
55 wcex.hIconSm = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO);; | 58 wcex.hIconSm = LoadIcon(fHInstance, (LPCTSTR)IDI_WINLOGO);; |
56 | 59 |
57 if (!RegisterClassEx(&wcex)) { | 60 if (!RegisterClassEx(&wcex)) { |
58 return false; | 61 return false; |
| 62 } |
| 63 wcexInit = true; |
59 } | 64 } |
60 | 65 |
61 /* | 66 /* |
62 if (fullscreen) | 67 if (fullscreen) |
63 { | 68 { |
64 DEVMODE dmScreenSettings; | 69 DEVMODE dmScreenSettings; |
65 // If full screen set the screen to maximum size of the users desktop an
d 32bit. | 70 // If full screen set the screen to maximum size of the users desktop an
d 32bit. |
66 memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); | 71 memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); |
67 dmScreenSettings.dmSize = sizeof(dmScreenSettings); | 72 dmScreenSettings.dmSize = sizeof(dmScreenSettings); |
68 dmScreenSettings.dmPelsWidth = (unsigned long)width; | 73 dmScreenSettings.dmPelsWidth = (unsigned long)width; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 173 |
169 switch (message) { | 174 switch (message) { |
170 case WM_PAINT: | 175 case WM_PAINT: |
171 hdc = BeginPaint(hWnd, &ps); | 176 hdc = BeginPaint(hWnd, &ps); |
172 window->onPaint(); | 177 window->onPaint(); |
173 EndPaint(hWnd, &ps); | 178 EndPaint(hWnd, &ps); |
174 eventHandled = true; | 179 eventHandled = true; |
175 break; | 180 break; |
176 | 181 |
177 case WM_CLOSE: | 182 case WM_CLOSE: |
178 case WM_DESTROY: | |
179 PostQuitMessage(0); | 183 PostQuitMessage(0); |
180 eventHandled = true; | 184 eventHandled = true; |
181 break; | 185 break; |
182 | 186 |
183 case WM_ACTIVATE: | 187 case WM_ACTIVATE: |
184 // disable/enable rendering here, depending on wParam != WA_INACTIVE | 188 // disable/enable rendering here, depending on wParam != WA_INACTIVE |
185 break; | 189 break; |
186 | 190 |
187 case WM_SIZE: | 191 case WM_SIZE: |
188 window->onResize(LOWORD(lParam), HIWORD(lParam)); | 192 window->onResize(LOWORD(lParam), HIWORD(lParam)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 285 } |
282 | 286 |
283 return (SkToBool(fWindowContext)); | 287 return (SkToBool(fWindowContext)); |
284 } | 288 } |
285 | 289 |
286 void Window_win::onInval() { | 290 void Window_win::onInval() { |
287 InvalidateRect(fHWnd, nullptr, false); | 291 InvalidateRect(fHWnd, nullptr, false); |
288 } | 292 } |
289 | 293 |
290 } // namespace sk_app | 294 } // namespace sk_app |
OLD | NEW |