OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/checks.h" | 11 #include "webrtc/base/checks.h" |
12 #include "webrtc/base/logging.h" | 12 #include "webrtc/base/logging.h" |
13 #include "webrtc/base/win32window.h" | 13 #include "webrtc/base/win32window.h" |
14 | 14 |
15 namespace rtc { | 15 namespace rtc { |
16 | 16 |
17 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
18 // Win32Window | 18 // Win32Window |
19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
20 | 20 |
21 static const wchar_t kWindowBaseClassName[] = L"WindowBaseClass"; | 21 static const wchar_t kWindowBaseClassName[] = L"WindowBaseClass"; |
22 HINSTANCE Win32Window::instance_ = NULL; | 22 HINSTANCE Win32Window::instance_ = nullptr; |
23 ATOM Win32Window::window_class_ = 0; | 23 ATOM Win32Window::window_class_ = 0; |
24 | 24 |
25 Win32Window::Win32Window() : wnd_(NULL) { | 25 Win32Window::Win32Window() : wnd_(nullptr) {} |
26 } | |
27 | 26 |
28 Win32Window::~Win32Window() { | 27 Win32Window::~Win32Window() { |
29 RTC_DCHECK(NULL == wnd_); | 28 RTC_DCHECK(nullptr == wnd_); |
30 } | 29 } |
31 | 30 |
32 bool Win32Window::Create(HWND parent, const wchar_t* title, DWORD style, | 31 bool Win32Window::Create(HWND parent, const wchar_t* title, DWORD style, |
33 DWORD exstyle, int x, int y, int cx, int cy) { | 32 DWORD exstyle, int x, int y, int cx, int cy) { |
34 if (wnd_) { | 33 if (wnd_) { |
35 // Window already exists. | 34 // Window already exists. |
36 return false; | 35 return false; |
37 } | 36 } |
38 | 37 |
39 if (!window_class_) { | 38 if (!window_class_) { |
(...skipping 11 matching lines...) Expand all Loading... |
51 wcex.cbSize = sizeof(wcex); | 50 wcex.cbSize = sizeof(wcex); |
52 wcex.hInstance = instance_; | 51 wcex.hInstance = instance_; |
53 wcex.lpfnWndProc = &Win32Window::WndProc; | 52 wcex.lpfnWndProc = &Win32Window::WndProc; |
54 wcex.lpszClassName = kWindowBaseClassName; | 53 wcex.lpszClassName = kWindowBaseClassName; |
55 window_class_ = ::RegisterClassEx(&wcex); | 54 window_class_ = ::RegisterClassEx(&wcex); |
56 if (!window_class_) { | 55 if (!window_class_) { |
57 LOG_GLE(LS_ERROR) << "RegisterClassEx failed"; | 56 LOG_GLE(LS_ERROR) << "RegisterClassEx failed"; |
58 return false; | 57 return false; |
59 } | 58 } |
60 } | 59 } |
61 wnd_ = ::CreateWindowEx(exstyle, kWindowBaseClassName, title, style, | 60 wnd_ = ::CreateWindowEx(exstyle, kWindowBaseClassName, title, style, x, y, cx, |
62 x, y, cx, cy, parent, NULL, instance_, this); | 61 cy, parent, nullptr, instance_, this); |
63 return (NULL != wnd_); | 62 return (nullptr != wnd_); |
64 } | 63 } |
65 | 64 |
66 void Win32Window::Destroy() { | 65 void Win32Window::Destroy() { |
67 const bool success = ::DestroyWindow(wnd_); | 66 const bool success = ::DestroyWindow(wnd_); |
68 RTC_DCHECK(success); | 67 RTC_DCHECK(success); |
69 } | 68 } |
70 | 69 |
71 void Win32Window::Shutdown() { | 70 void Win32Window::Shutdown() { |
72 if (window_class_) { | 71 if (window_class_) { |
73 ::UnregisterClass(MAKEINTATOM(window_class_), instance_); | 72 ::UnregisterClass(MAKEINTATOM(window_class_), instance_); |
(...skipping 28 matching lines...) Expand all Loading... |
102 LRESULT result; | 101 LRESULT result; |
103 bool handled = that->OnMessage(uMsg, wParam, lParam, result); | 102 bool handled = that->OnMessage(uMsg, wParam, lParam, result); |
104 if (WM_DESTROY == uMsg) { | 103 if (WM_DESTROY == uMsg) { |
105 for (HWND child = ::GetWindow(hwnd, GW_CHILD); child; | 104 for (HWND child = ::GetWindow(hwnd, GW_CHILD); child; |
106 child = ::GetWindow(child, GW_HWNDNEXT)) { | 105 child = ::GetWindow(child, GW_HWNDNEXT)) { |
107 LOG(LS_INFO) << "Child window: " << static_cast<void*>(child); | 106 LOG(LS_INFO) << "Child window: " << static_cast<void*>(child); |
108 } | 107 } |
109 } | 108 } |
110 if (WM_NCDESTROY == uMsg) { | 109 if (WM_NCDESTROY == uMsg) { |
111 ::SetWindowLongPtr(hwnd, GWLP_USERDATA, NULL); | 110 ::SetWindowLongPtr(hwnd, GWLP_USERDATA, NULL); |
112 that->wnd_ = NULL; | 111 that->wnd_ = nullptr; |
113 that->OnNcDestroy(); | 112 that->OnNcDestroy(); |
114 } | 113 } |
115 if (handled) { | 114 if (handled) { |
116 return result; | 115 return result; |
117 } | 116 } |
118 } | 117 } |
119 return ::DefWindowProc(hwnd, uMsg, wParam, lParam); | 118 return ::DefWindowProc(hwnd, uMsg, wParam, lParam); |
120 } | 119 } |
121 | 120 |
122 } // namespace rtc | 121 } // namespace rtc |
OLD | NEW |