OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef TOOLS_MEMORY_WATCHER_HOTKEY_H_ | 5 #ifndef TOOLS_MEMORY_WATCHER_HOTKEY_H_ |
6 #define TOOLS_MEMORY_WATCHER_HOTKEY_H_ | 6 #define TOOLS_MEMORY_WATCHER_HOTKEY_H_ |
7 | 7 |
8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
| 9 #include "ui/gfx/win/msg_util.h" |
9 #include "ui/gfx/win/window_impl.h" | 10 #include "ui/gfx/win/window_impl.h" |
10 | 11 |
11 // HotKey handler. | 12 // HotKey handler. |
12 // Programs wishing to register a hotkey can use this. | 13 // Programs wishing to register a hotkey can use this. |
13 class HotKeyHandler : public gfx::WindowImpl { | 14 class HotKeyHandler : public gfx::WindowImpl { |
14 public: | 15 public: |
15 HotKeyHandler(UINT modifiers, UINT vk) | 16 HotKeyHandler(UINT modifiers, UINT vk) |
16 : modifiers_(modifiers), | 17 : modifiers_(modifiers), |
17 vkey_(vk) { | 18 vkey_(vk) { |
18 Start(); | 19 Start(); |
19 } | 20 } |
20 ~HotKeyHandler() { Stop(); } | 21 ~HotKeyHandler() { Stop(); } |
21 | 22 |
22 BEGIN_MSG_MAP_EX(HotKeyHandler) | 23 CR_BEGIN_MSG_MAP_EX(HotKeyHandler) |
23 MESSAGE_HANDLER(WM_HOTKEY, OnHotKey) | 24 CR_MSG_WM_HOTKEY(OnHotKey) |
24 END_MSG_MAP() | 25 CR_END_MSG_MAP() |
25 | 26 |
26 private: | 27 private: |
27 static const int hotkey_id = 0x0000baba; | 28 static const int hotkey_id = 0x0000baba; |
28 | 29 |
29 bool Start() { | 30 bool Start() { |
30 set_window_style(WS_POPUP); | 31 set_window_style(WS_POPUP); |
31 Init(NULL, gfx::Rect()); | 32 Init(NULL, gfx::Rect()); |
32 return RegisterHotKey(hwnd(), hotkey_id, modifiers_, vkey_) == TRUE; | 33 return RegisterHotKey(hwnd(), hotkey_id, modifiers_, vkey_) == TRUE; |
33 } | 34 } |
34 | 35 |
35 void Stop() { | 36 void Stop() { |
36 UnregisterHotKey(hwnd(), hotkey_id); | 37 UnregisterHotKey(hwnd(), hotkey_id); |
37 DestroyWindow(hwnd()); | 38 DestroyWindow(hwnd()); |
38 } | 39 } |
39 | 40 |
40 // Handle the registered Hotkey being pressed. | 41 // Handle the registered Hotkey being pressed. |
41 virtual LRESULT OnHotKey(UINT /*uMsg*/, WPARAM /*wParam*/, | 42 virtual void OnHotKey(UINT /*uMsg*/, |
42 LPARAM /*lParam*/, BOOL& bHandled) = 0; | 43 WPARAM /*wParam*/, |
| 44 LPARAM /*lParam*/) = 0; |
43 | 45 |
44 UINT modifiers_; | 46 UINT modifiers_; |
45 UINT vkey_; | 47 UINT vkey_; |
46 }; | 48 }; |
47 | 49 |
48 #endif // TOOLS_MEMORY_WATCHER_HOTKEY_H_ | 50 #endif // TOOLS_MEMORY_WATCHER_HOTKEY_H_ |
OLD | NEW |