Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Unified Diff: ui/base/win/hwnd_subclass.cc

Issue 10256008: Adds a class that makes it easy to subclass a HWND and filter messages sent to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/win/hwnd_subclass.h ('k') | ui/base/win/hwnd_subclass_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/win/hwnd_subclass.cc
===================================================================
--- ui/base/win/hwnd_subclass.cc (revision 0)
+++ ui/base/win/hwnd_subclass.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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 "ui/base/win/hwnd_subclass.h"
+
+#include "base/logging.h"
+#include "ui/base/win/hwnd_util.h"
+
+namespace {
+const char kHWNDSubclassKey[] = "__UI_BASE_WIN_HWND_SUBCLASS_PROC__";
+
+LRESULT CALLBACK WndProc(HWND hwnd,
+ UINT message,
+ WPARAM w_param,
+ LPARAM l_param) {
+ ui::HWNDSubclass* wrapped_wnd_proc =
+ reinterpret_cast<ui::HWNDSubclass*>(
+ ui::ViewProp::GetValue(hwnd, kHWNDSubclassKey));
+ return wrapped_wnd_proc ? wrapped_wnd_proc->OnWndProc(hwnd,
+ message,
+ w_param,
+ l_param)
+ : DefWindowProc(hwnd, message, w_param, l_param);
+}
+
+WNDPROC GetCurrentWndProc(HWND target) {
+ return reinterpret_cast<WNDPROC>(GetWindowLong(target, GWL_WNDPROC));
+}
+
+} // namespace
+
+namespace ui {
+
+HWNDSubclass::HWNDSubclass(HWND target)
+ : target_(target),
+ original_wnd_proc_(GetCurrentWndProc(target)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) {
+ ui::SetWindowProc(target_, &WndProc);
+}
+
+HWNDSubclass::~HWNDSubclass() {
+}
+
+void HWNDSubclass::SetFilter(HWNDMessageFilter* filter) {
+ filter_.reset(filter);
+}
+
+LRESULT HWNDSubclass::OnWndProc(HWND hwnd,
+ UINT message,
+ WPARAM w_param,
+ LPARAM l_param) {
+ if (filter_.get()) {
+ LRESULT l_result = 0;
+ if (filter_->FilterMessage(hwnd, message, w_param, l_param, &l_result))
+ return l_result;
+ }
+
+ // In most cases, |original_wnd_proc_| will take care of calling
+ // DefWindowProc.
+ return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param);
+}
+
+} // namespace ui
Property changes on: ui\base\win\hwnd_subclass.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « ui/base/win/hwnd_subclass.h ('k') | ui/base/win/hwnd_subclass_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698