| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/system_message_window_win.h" | 5 #include "content/browser/system_message_window_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <dbt.h> | 8 #include <dbt.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/system_monitor/system_monitor.h" | 11 #include "base/system_monitor/system_monitor.h" |
| 12 #include "base/win/wrapped_window_proc.h" | 12 #include "base/win/wrapped_window_proc.h" |
| 13 | 13 |
| 14 static const wchar_t* const WindowClassName = L"Chrome_SystemMessageWindow"; | 14 static const wchar_t* const WindowClassName = L"Chrome_SystemMessageWindow"; |
| 15 | 15 |
| 16 | 16 |
| 17 SystemMessageWindowWin::SystemMessageWindowWin() { | 17 SystemMessageWindowWin::SystemMessageWindowWin() { |
| 18 HINSTANCE hinst = GetModuleHandle(NULL); | 18 WNDCLASSEX window_class; |
| 19 | 19 base::win::InitializeWindowClass( |
| 20 WNDCLASSEX wc = {0}; | 20 WindowClassName, |
| 21 wc.cbSize = sizeof(wc); | 21 &base::win::WrappedWindowProc<SystemMessageWindowWin::WndProcThunk>, |
| 22 wc.lpfnWndProc = | 22 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| 23 base::win::WrappedWindowProc<&SystemMessageWindowWin::WndProcThunk>; | 23 &window_class); |
| 24 wc.hInstance = hinst; | 24 instance_ = window_class.hInstance; |
| 25 wc.lpszClassName = WindowClassName; | 25 ATOM clazz = RegisterClassEx(&window_class); |
| 26 ATOM clazz = RegisterClassEx(&wc); | |
| 27 DCHECK(clazz); | 26 DCHECK(clazz); |
| 28 | 27 |
| 29 window_ = CreateWindow(WindowClassName, | 28 window_ = CreateWindow(WindowClassName, |
| 30 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0); | 29 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0); |
| 31 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); | 30 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); |
| 32 } | 31 } |
| 33 | 32 |
| 34 SystemMessageWindowWin::~SystemMessageWindowWin() { | 33 SystemMessageWindowWin::~SystemMessageWindowWin() { |
| 35 if (window_) { | 34 if (window_) { |
| 36 DestroyWindow(window_); | 35 DestroyWindow(window_); |
| 37 UnregisterClass(WindowClassName, GetModuleHandle(NULL)); | 36 UnregisterClass(WindowClassName, instance_); |
| 38 } | 37 } |
| 39 } | 38 } |
| 40 | 39 |
| 41 LRESULT SystemMessageWindowWin::OnDeviceChange(UINT event_type, DWORD data) { | 40 LRESULT SystemMessageWindowWin::OnDeviceChange(UINT event_type, DWORD data) { |
| 42 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 41 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
| 43 switch (event_type) { | 42 switch (event_type) { |
| 44 case DBT_DEVNODES_CHANGED: | 43 case DBT_DEVNODES_CHANGED: |
| 45 monitor->ProcessDevicesChanged(); | 44 monitor->ProcessDevicesChanged(); |
| 46 break; | 45 break; |
| 47 } | 46 } |
| 48 return TRUE; | 47 return TRUE; |
| 49 } | 48 } |
| 50 | 49 |
| 51 LRESULT CALLBACK SystemMessageWindowWin::WndProc(HWND hwnd, UINT message, | 50 LRESULT CALLBACK SystemMessageWindowWin::WndProc(HWND hwnd, UINT message, |
| 52 WPARAM wparam, LPARAM lparam) { | 51 WPARAM wparam, LPARAM lparam) { |
| 53 switch (message) { | 52 switch (message) { |
| 54 case WM_DEVICECHANGE: | 53 case WM_DEVICECHANGE: |
| 55 return OnDeviceChange(static_cast<UINT>(wparam), | 54 return OnDeviceChange(static_cast<UINT>(wparam), |
| 56 static_cast<DWORD>(lparam)); | 55 static_cast<DWORD>(lparam)); |
| 57 default: | 56 default: |
| 58 break; | 57 break; |
| 59 } | 58 } |
| 60 | 59 |
| 61 return ::DefWindowProc(hwnd, message, wparam, lparam); | 60 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 62 } | 61 } |
| OLD | NEW |