summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/message_pump_win.cc24
-rw-r--r--base/win/wrapped_window_proc.cc33
-rw-r--r--base/win/wrapped_window_proc.h19
-rw-r--r--chrome/browser/media_gallery/media_device_notifications_window_win.cc43
-rw-r--r--chrome/browser/media_gallery/media_device_notifications_window_win.h6
-rw-r--r--chrome/browser/ui/views/status_icons/status_tray_win.cc30
-rw-r--r--chrome/browser/ui/views/status_icons/status_tray_win.h8
-rw-r--r--content/browser/renderer_host/render_widget_host_view_win.cc76
-rw-r--r--content/browser/system_message_window_win.cc21
-rw-r--r--content/browser/system_message_window_win.h1
-rw-r--r--content/shell/shell_win.cc21
-rw-r--r--remoting/host/host_service_win.cc27
-rw-r--r--ui/base/clipboard/clipboard_win.cc13
-rw-r--r--ui/base/win/window_impl.cc54
-rw-r--r--ui/views/controls/menu/native_menu_win.cc23
15 files changed, 238 insertions, 161 deletions
diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc
index 72657dc..7dc3da3 100644
--- a/base/message_pump_win.cc
+++ b/base/message_pump_win.cc
@@ -8,7 +8,6 @@
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
-#include "base/process_util.h"
#include "base/stringprintf.h"
#include "base/win/wrapped_window_proc.h"
@@ -253,18 +252,14 @@ void MessagePumpForUI::DoRunLoop() {
void MessagePumpForUI::InitMessageWnd() {
// Register a unique window class for each instance of UI pump.
string16 class_name = base::StringPrintf(kWndClassFormat, this);
- WNDPROC window_procedure = &base::win::WrappedWindowProc<WndProcThunk>;
-
- // RegisterClassEx uses a handle of the module containing the window procedure
- // to distinguish identically named classes registered in different modules.
- instance_ = GetModuleFromAddress(window_procedure);
-
- WNDCLASSEXW wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpfnWndProc = window_procedure;
- wc.hInstance = instance_;
- wc.lpszClassName = class_name.c_str();
- atom_ = RegisterClassEx(&wc);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ class_name.c_str(),
+ &base::win::WrappedWindowProc<WndProcThunk>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ instance_ = window_class.hInstance;
+ atom_ = RegisterClassEx(&window_class);
if (atom_ == 0) {
DCHECK(atom_);
return;
@@ -272,8 +267,7 @@ void MessagePumpForUI::InitMessageWnd() {
// Create the message-only window.
message_hwnd_ = CreateWindow(
- reinterpret_cast<const char16*>(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
- instance_, 0);
+ MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance_, 0);
if (message_hwnd_ == NULL) {
DCHECK(message_hwnd_);
return;
diff --git a/base/win/wrapped_window_proc.cc b/base/win/wrapped_window_proc.cc
index c94c5ae..04e59c5 100644
--- a/base/win/wrapped_window_proc.cc
+++ b/base/win/wrapped_window_proc.cc
@@ -1,10 +1,12 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/win/wrapped_window_proc.h"
#include "base/atomicops.h"
+#include "base/logging.h"
+#include "base/process_util.h"
namespace {
@@ -28,5 +30,34 @@ int CallExceptionFilter(EXCEPTION_POINTERS* info) {
EXCEPTION_CONTINUE_SEARCH;
}
+BASE_EXPORT void InitializeWindowClass(
+ const char16* class_name,
+ WNDPROC window_proc,
+ UINT style,
+ int class_extra,
+ int window_extra,
+ HCURSOR cursor,
+ HBRUSH background,
+ const char16* menu_name,
+ HICON large_icon,
+ HICON small_icon,
+ WNDCLASSEX* class_out) {
+ class_out->cbSize = sizeof(WNDCLASSEX);
+ class_out->style = style;
+ class_out->lpfnWndProc = window_proc;
+ class_out->cbClsExtra = class_extra;
+ class_out->cbWndExtra = window_extra;
+ class_out->hInstance = base::GetModuleFromAddress(window_proc);
+ class_out->hIcon = large_icon;
+ class_out->hCursor = cursor;
+ class_out->hbrBackground = background;
+ class_out->lpszMenuName = menu_name;
+ class_out->lpszClassName = class_name;
+ class_out->hIconSm = small_icon;
+
+ // Check if |window_proc| is valid.
+ DCHECK(class_out->hInstance != NULL);
+}
+
} // namespace win
} // namespace base
diff --git a/base/win/wrapped_window_proc.h b/base/win/wrapped_window_proc.h
index c9916504..6d887ae 100644
--- a/base/win/wrapped_window_proc.h
+++ b/base/win/wrapped_window_proc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,7 @@
#include <windows.h>
#include "base/base_export.h"
+#include "base/string16.h"
namespace base {
namespace win {
@@ -34,6 +35,22 @@ BASE_EXPORT WinProcExceptionFilter SetWinProcExceptionFilter(
// Calls the registered exception filter.
BASE_EXPORT int CallExceptionFilter(EXCEPTION_POINTERS* info);
+// Initializes the WNDCLASSEX structure |*class_out| to be passed to
+// RegisterClassEx() making sure that it is associated with the module
+// containing the window procedure.
+BASE_EXPORT void InitializeWindowClass(
+ const char16* class_name,
+ WNDPROC window_proc,
+ UINT style,
+ int class_extra,
+ int window_extra,
+ HCURSOR cursor,
+ HBRUSH background,
+ const char16* menu_name,
+ HICON large_icon,
+ HICON small_icon,
+ WNDCLASSEX* class_out);
+
// Wrapper that supplies a standard exception frame for the provided WindowProc.
// The normal usage is something like this:
//
diff --git a/chrome/browser/media_gallery/media_device_notifications_window_win.cc b/chrome/browser/media_gallery/media_device_notifications_window_win.cc
index 498ade9..e25e013 100644
--- a/chrome/browser/media_gallery/media_device_notifications_window_win.cc
+++ b/chrome/browser/media_gallery/media_device_notifications_window_win.cc
@@ -42,36 +42,45 @@ DWORD GetVolumeBitMaskFromBroadcastHeader(DWORD data) {
namespace chrome {
MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin()
- : volume_name_func_(&GetVolumeName) {
+ : atom_(0),
+ instance_(NULL),
+ window_(NULL),
+ volume_name_func_(&GetVolumeName) {
Init();
}
MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin(
- VolumeNameFunc volume_name_func) : volume_name_func_(volume_name_func) {
+ VolumeNameFunc volume_name_func)
+ : atom_(0),
+ instance_(NULL),
+ window_(NULL),
+ volume_name_func_(volume_name_func) {
Init();
}
void MediaDeviceNotificationsWindowWin::Init() {
- HINSTANCE hinst = GetModuleHandle(NULL);
-
- WNDCLASSEX wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpfnWndProc = base::win::WrappedWindowProc<
- &MediaDeviceNotificationsWindowWin::WndProcThunk>;
- wc.hInstance = hinst;
- wc.lpszClassName = WindowClassName;
- ATOM clazz = RegisterClassEx(&wc);
- DCHECK(clazz);
-
- window_ = CreateWindow(WindowClassName, 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ WindowClassName,
+ &base::win::WrappedWindowProc<
+ MediaDeviceNotificationsWindowWin::WndProcThunk>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ instance_ = window_class.hInstance;
+ atom_ = RegisterClassEx(&window_class);
+ DCHECK(atom_);
+
+ window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, 0, 0, instance_,
+ 0);
SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
}
MediaDeviceNotificationsWindowWin::~MediaDeviceNotificationsWindowWin() {
- if (window_) {
+ if (window_)
DestroyWindow(window_);
- UnregisterClass(WindowClassName, GetModuleHandle(NULL));
- }
+
+ if (atom_)
+ UnregisterClass(MAKEINTATOM(atom_), instance_);
}
LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type,
diff --git a/chrome/browser/media_gallery/media_device_notifications_window_win.h b/chrome/browser/media_gallery/media_device_notifications_window_win.h
index ebf7153..a8d96fe 100644
--- a/chrome/browser/media_gallery/media_device_notifications_window_win.h
+++ b/chrome/browser/media_gallery/media_device_notifications_window_win.h
@@ -38,6 +38,12 @@ class MediaDeviceNotificationsWindowWin {
WPARAM wparam,
LPARAM lparam);
+ // The window class of |window_|.
+ ATOM atom_;
+
+ // The handle of the module that contains the window procedure of |window_|.
+ HMODULE instance_;
+
HWND window_;
VolumeNameFunc volume_name_func_;
diff --git a/chrome/browser/ui/views/status_icons/status_tray_win.cc b/chrome/browser/ui/views/status_icons/status_tray_win.cc
index e078dcd..46a3256 100644
--- a/chrome/browser/ui/views/status_icons/status_tray_win.cc
+++ b/chrome/browser/ui/views/status_icons/status_tray_win.cc
@@ -13,16 +13,20 @@
static const UINT kStatusIconMessage = WM_APP + 1;
StatusTrayWin::StatusTrayWin()
- : next_icon_id_(1) {
+ : next_icon_id_(1),
+ atom_(0),
+ instance_(NULL),
+ window_(NULL) {
// Register our window class
- HINSTANCE hinst = GetModuleHandle(NULL);
- WNDCLASSEX wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpfnWndProc = base::win::WrappedWindowProc<StatusTrayWin::WndProcStatic>;
- wc.hInstance = hinst;
- wc.lpszClassName = chrome::kStatusTrayWindowClass;
- ATOM clazz = RegisterClassEx(&wc);
- DCHECK(clazz);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ chrome::kStatusTrayWindowClass,
+ &base::win::WrappedWindowProc<StatusTrayWin::WndProcStatic>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ instance_ = window_class.hInstance;
+ atom_ = RegisterClassEx(&window_class);
+ CHECK(atom_);
// If the taskbar is re-created after we start up, we have to rebuild all of
// our icons.
@@ -32,8 +36,8 @@ StatusTrayWin::StatusTrayWin()
// create a hidden WS_POPUP window instead of an HWND_MESSAGE window, because
// only top-level windows such as popups can receive broadcast messages like
// "TaskbarCreated".
- window_ = CreateWindow(chrome::kStatusTrayWindowClass,
- 0, WS_POPUP, 0, 0, 0, 0, 0, 0, hinst, 0);
+ window_ = CreateWindow(MAKEINTATOM(atom_),
+ 0, WS_POPUP, 0, 0, 0, 0, 0, 0, instance_, 0);
ui::CheckWindowCreated(window_);
ui::SetWindowUserData(window_, this);
}
@@ -88,7 +92,9 @@ LRESULT CALLBACK StatusTrayWin::WndProc(HWND hwnd,
StatusTrayWin::~StatusTrayWin() {
if (window_)
DestroyWindow(window_);
- UnregisterClass(chrome::kStatusTrayWindowClass, GetModuleHandle(NULL));
+
+ if (atom_)
+ UnregisterClass(MAKEINTATOM(atom_), instance_);
}
StatusIcon* StatusTrayWin::CreatePlatformStatusIcon() {
diff --git a/chrome/browser/ui/views/status_icons/status_tray_win.h b/chrome/browser/ui/views/status_icons/status_tray_win.h
index 684b1a4..636b931 100644
--- a/chrome/browser/ui/views/status_icons/status_tray_win.h
+++ b/chrome/browser/ui/views/status_icons/status_tray_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,6 +35,12 @@ class StatusTrayWin : public StatusTray {
// The unique icon ID we will assign to the next icon.
UINT next_icon_id_;
+ // The window class of |window_|.
+ ATOM atom_;
+
+ // The handle of the module that contains the window procedure of |window_|.
+ HMODULE instance_;
+
// The window used for processing events.
HWND window_;
diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc
index f40a284..c4f776a 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.cc
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc
@@ -569,31 +569,33 @@ void RenderWidgetHostViewWin::MovePluginWindows(
}
HWND RenderWidgetHostViewWin::ReparentWindow(HWND window) {
- static ATOM window_class = 0;
- if (!window_class) {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_DBLCLKS;
- wcex.lpfnWndProc = base::win::WrappedWindowProc<PluginWrapperWindowProc>;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = GetModuleHandle(NULL);
- wcex.hIcon = 0;
- wcex.hCursor = 0;
- wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = webkit::npapi::kWrapperNativeWindowClassName;
- wcex.hIconSm = 0;
- window_class = RegisterClassEx(&wcex);
- }
- DCHECK(window_class);
+ static ATOM atom = 0;
+ static HMODULE instance = NULL;
+ if (!atom) {
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ webkit::npapi::kWrapperNativeWindowClassName,
+ &base::win::WrappedWindowProc<PluginWrapperWindowProc>,
+ CS_DBLCLKS,
+ 0,
+ 0,
+ NULL,
+ reinterpret_cast<HBRUSH>(COLOR_WINDOW+1),
+ NULL,
+ NULL,
+ NULL,
+ &window_class);
+ instance = window_class.hInstance;
+ atom = RegisterClassEx(&window_class);
+ }
+ DCHECK(atom);
HWND orig_parent = ::GetParent(window);
HWND parent = CreateWindowEx(
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
- MAKEINTATOM(window_class), 0,
+ MAKEINTATOM(atom), 0,
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
- 0, 0, 0, 0, orig_parent, 0, GetModuleHandle(NULL), 0);
+ 0, 0, 0, 0, orig_parent, 0, instance, 0);
ui::CheckWindowCreated(parent);
// If UIPI is enabled we need to add message filters for parents with
// children that cross process boundaries.
@@ -2124,24 +2126,18 @@ gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() {
if (compositor_host_window_)
return gfx::GLSurfaceHandle(compositor_host_window_, true);
- static ATOM window_class = 0;
- if (!window_class) {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = 0;
- wcex.lpfnWndProc =
- base::win::WrappedWindowProc<CompositorHostWindowProc>;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = GetModuleHandle(NULL);
- wcex.hIcon = 0;
- wcex.hCursor = 0;
- wcex.hbrBackground = NULL;
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = L"CompositorHostWindowClass";
- wcex.hIconSm = 0;
- window_class = RegisterClassEx(&wcex);
- DCHECK(window_class);
+ static ATOM atom = 0;
+ static HMODULE instance = NULL;
+ if (!atom) {
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ L"CompositorHostWindowClass",
+ &base::win::WrappedWindowProc<CompositorHostWindowProc>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ instance = window_class.hInstance;
+ atom = RegisterClassEx(&window_class);
+ DCHECK(atom);
}
RECT currentRect;
@@ -2156,9 +2152,9 @@ gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() {
compositor_host_window_ = CreateWindowEx(
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
- MAKEINTATOM(window_class), 0,
+ MAKEINTATOM(atom), 0,
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED,
- 0, 0, width, height, m_hWnd, 0, GetModuleHandle(NULL), 0);
+ 0, 0, width, height, m_hWnd, 0, instance, 0);
ui::CheckWindowCreated(compositor_host_window_);
ui::SetWindowUserData(compositor_host_window_, this);
diff --git a/content/browser/system_message_window_win.cc b/content/browser/system_message_window_win.cc
index 347e717d..1f6fcb0 100644
--- a/content/browser/system_message_window_win.cc
+++ b/content/browser/system_message_window_win.cc
@@ -15,26 +15,25 @@ static const wchar_t* const WindowClassName = L"Chrome_SystemMessageWindow";
SystemMessageWindowWin::SystemMessageWindowWin() {
- HINSTANCE hinst = GetModuleHandle(NULL);
-
- WNDCLASSEX wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpfnWndProc =
- base::win::WrappedWindowProc<&SystemMessageWindowWin::WndProcThunk>;
- wc.hInstance = hinst;
- wc.lpszClassName = WindowClassName;
- ATOM clazz = RegisterClassEx(&wc);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ WindowClassName,
+ &base::win::WrappedWindowProc<SystemMessageWindowWin::WndProcThunk>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ instance_ = window_class.hInstance;
+ ATOM clazz = RegisterClassEx(&window_class);
DCHECK(clazz);
window_ = CreateWindow(WindowClassName,
- 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
+ 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0);
SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
}
SystemMessageWindowWin::~SystemMessageWindowWin() {
if (window_) {
DestroyWindow(window_);
- UnregisterClass(WindowClassName, GetModuleHandle(NULL));
+ UnregisterClass(WindowClassName, instance_);
}
}
diff --git a/content/browser/system_message_window_win.h b/content/browser/system_message_window_win.h
index 36c800c..fd94985 100644
--- a/content/browser/system_message_window_win.h
+++ b/content/browser/system_message_window_win.h
@@ -36,6 +36,7 @@ class CONTENT_EXPORT SystemMessageWindowWin {
return ::DefWindowProc(hwnd, message, wparam, lparam);
}
+ HMODULE instance_;
HWND window_;
DISALLOW_COPY_AND_ASSIGN(SystemMessageWindowWin);
diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc
index 2254378..3aeef3c 100644
--- a/content/shell/shell_win.cc
+++ b/content/shell/shell_win.cc
@@ -10,6 +10,7 @@
#include "base/string_piece.h"
#include "base/utf_string_conversions.h"
#include "base/win/resource_util.h"
+#include "base/win/wrapped_window_proc.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/shell/resource.h"
@@ -46,8 +47,6 @@ namespace content {
HINSTANCE Shell::instance_handle_;
void Shell::PlatformInitialize() {
- instance_handle_ = ::GetModuleHandle(NULL);
-
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_STANDARD_CLASSES;
@@ -190,21 +189,21 @@ void Shell::Close() {
}
ATOM Shell::RegisterWindowClass() {
- WNDCLASSEX wcex = {
- sizeof(WNDCLASSEX),
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ kWindowClass,
+ &Shell::WndProc,
CS_HREDRAW | CS_VREDRAW,
- Shell::WndProc,
0,
0,
- instance_handle_,
- NULL,
LoadCursor(NULL, IDC_ARROW),
- 0,
+ NULL,
MAKEINTRESOURCE(IDC_CONTENTSHELL),
- kWindowClass,
NULL,
- };
- return RegisterClassEx(&wcex);
+ NULL,
+ &window_class);
+ instance_handle_ = window_class.hInstance;
+ return RegisterClassEx(&window_class);
}
LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam,
diff --git a/remoting/host/host_service_win.cc b/remoting/host/host_service_win.cc
index c96c6e0..77d8cc7 100644
--- a/remoting/host/host_service_win.cc
+++ b/remoting/host/host_service_win.cc
@@ -19,7 +19,6 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/process_util.h"
#include "base/stringize_macros.h"
#include "base/stringprintf.h"
#include "base/threading/thread.h"
@@ -255,26 +254,24 @@ int HostService::RunInConsole() {
}
// Create a window for receiving session change notifications.
- LPCWSTR atom = NULL;
HWND window = NULL;
- WNDPROC window_proc =
- base::win::WrappedWindowProc<SessionChangeNotificationProc>;
- HINSTANCE instance = base::GetModuleFromAddress(window_proc);
-
- WNDCLASSEX wc = {0};
- wc.cbSize = sizeof(wc);
- wc.lpfnWndProc = window_proc;
- wc.hInstance = instance;
- wc.lpszClassName = kSessionNotificationWindowClass;
- atom = reinterpret_cast<LPCWSTR>(RegisterClassExW(&wc));
- if (atom == NULL) {
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ kSessionNotificationWindowClass,
+ &base::win::WrappedWindowProc<SessionChangeNotificationProc>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ HINSTANCE instance = window_class.hInstance;
+ ATOM atom = RegisterClassExW(&window_class);
+ if (atom == 0) {
LOG_GETLASTERROR(ERROR)
<< "Failed to register the window class '"
<< kSessionNotificationWindowClass << "'";
goto cleanup;
}
- window = CreateWindowW(atom, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance, 0);
+ window = CreateWindowW(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
+ instance, 0);
if (window == NULL) {
LOG_GETLASTERROR(ERROR)
<< "Failed to creat the session notificationwindow";
@@ -302,7 +299,7 @@ cleanup:
}
if (atom != 0) {
- UnregisterClass(atom, instance);
+ UnregisterClass(MAKEINTATOM(atom), instance);
}
// Unsubscribe from console events. Ignore the exit code. There is nothing
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index 8b2eaea..3fa071f 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -188,12 +188,13 @@ Clipboard::FormatType Clipboard::FormatType::Deserialize(
Clipboard::Clipboard() : create_window_(false) {
if (MessageLoop::current()->type() == MessageLoop::TYPE_UI) {
// Make a dummy HWND to be the clipboard's owner.
- WNDCLASSEX wcex = {0};
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.lpfnWndProc = base::win::WrappedWindowProc<ClipboardOwnerWndProc>;
- wcex.hInstance = GetModuleHandle(NULL);
- wcex.lpszClassName = L"ClipboardOwnerWindowClass";
- ::RegisterClassEx(&wcex);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ L"ClipboardOwnerWindowClass",
+ &base::win::WrappedWindowProc<ClipboardOwnerWndProc>,
+ 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
+ &window_class);
+ ::RegisterClassEx(&window_class);
create_window_ = true;
}
diff --git a/ui/base/win/window_impl.cc b/ui/base/win/window_impl.cc
index 31d0fe3..76d4065 100644
--- a/ui/base/win/window_impl.cc
+++ b/ui/base/win/window_impl.cc
@@ -51,7 +51,7 @@ class ClassRegistrar {
~ClassRegistrar() {
for (RegisteredClasses::iterator i = registered_classes_.begin();
i != registered_classes_.end(); ++i) {
- if (!UnregisterClass(i->name.c_str(), NULL)) {
+ if (!UnregisterClass(MAKEINTATOM(i->atom), i->instance)) {
LOG(ERROR) << "Failed to unregister class " << i->name.c_str()
<< ". Error = " << GetLastError();
}
@@ -77,8 +77,10 @@ class ClassRegistrar {
void RegisterClass(const ClassInfo& class_info,
const std::wstring& name,
- ATOM atom) {
- registered_classes_.push_back(RegisteredClass(class_info, name, atom));
+ ATOM atom,
+ HMODULE instance) {
+ registered_classes_.push_back(
+ RegisteredClass(class_info, name, atom, instance));
}
private:
@@ -86,20 +88,25 @@ class ClassRegistrar {
struct RegisteredClass {
RegisteredClass(const ClassInfo& info,
const std::wstring& name,
- ATOM atom)
+ ATOM atom,
+ HMODULE instance)
: info(info),
name(name),
- atom(atom) {
+ atom(atom),
+ instance(instance) {
}
// Info used to create the class.
ClassInfo info;
- // The name given to the window.
+ // The name given to the window class.
std::wstring name;
- // The ATOM returned from creating the window.
+ // The ATOM returned from registering the window class.
ATOM atom;
+
+ // The handle of the module containing the window procedure.
+ HMODULE instance;
};
ClassRegistrar() : registered_count_(0) { }
@@ -241,24 +248,25 @@ std::wstring WindowImpl::GetWindowClassName() {
// No class found, need to register one.
HBRUSH background = NULL;
- WNDCLASSEX class_ex = {
- sizeof(WNDCLASSEX),
- class_info.style,
- base::win::WrappedWindowProc<&WindowImpl::WndProc>,
- 0,
- 0,
- GetModuleHandle(NULL),
- icon,
- NULL,
- reinterpret_cast<HBRUSH>(background + 1),
- NULL,
- name.c_str(),
- icon
- };
- ATOM atom = RegisterClassEx(&class_ex);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ name.c_str(),
+ &base::win::WrappedWindowProc<WindowImpl::WndProc>,
+ class_info.style,
+ 0,
+ 0,
+ NULL,
+ reinterpret_cast<HBRUSH>(background + 1),
+ NULL,
+ icon,
+ icon,
+ &window_class);
+ HMODULE instance = window_class.hInstance;
+ ATOM atom = RegisterClassEx(&window_class);
CHECK(atom) << GetLastError();
- ClassRegistrar::GetInstance()->RegisterClass(class_info, name, atom);
+ ClassRegistrar::GetInstance()->RegisterClass(
+ class_info, name, atom, instance);
return name;
}
diff --git a/ui/views/controls/menu/native_menu_win.cc b/ui/views/controls/menu/native_menu_win.cc
index 3af5ca0..ba60cab 100644
--- a/ui/views/controls/menu/native_menu_win.cc
+++ b/ui/views/controls/menu/native_menu_win.cc
@@ -96,14 +96,21 @@ class NativeMenuWin::MenuHostWindow {
if (registered)
return;
- WNDCLASSEX wcex = {0};
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_DBLCLKS;
- wcex.lpfnWndProc = base::win::WrappedWindowProc<&MenuHostWindowProc>;
- wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1);
- wcex.lpszClassName = kWindowClassName;
- ATOM clazz = RegisterClassEx(&wcex);
- DCHECK(clazz);
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ kWindowClassName,
+ &base::win::WrappedWindowProc<MenuHostWindowProc>,
+ CS_DBLCLKS,
+ 0,
+ 0,
+ NULL,
+ reinterpret_cast<HBRUSH>(COLOR_WINDOW+1),
+ NULL,
+ NULL,
+ NULL,
+ &window_class);
+ ATOM clazz = RegisterClassEx(&window_class);
+ CHECK(clazz);
registered = true;
}