Index: sandbox/win/tests/integration_tests/hooking_win_proc.cc |
diff --git a/sandbox/win/tests/integration_tests/hooking_win_proc.cc b/sandbox/win/tests/integration_tests/hooking_win_proc.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..227c899b5ea0fb4c203c38ca2aad2feaf4187d27 |
--- /dev/null |
+++ b/sandbox/win/tests/integration_tests/hooking_win_proc.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2016 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 "integration_tests_common.h" |
+ |
+#include <windows.h> |
+ |
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
robertshield
2016/04/14 03:57:29
similar nits around parameter naming conventions,
penny
2016/04/24 18:50:49
Done.
|
+ // Injected keystroke via PostThreadMessage won't be dispatched to here. |
+ // Have to use SendMessage or SendInput to trigger the keyboard hook. |
+ switch (msg) { |
+ case WM_KEYDOWN: |
+ break; |
+ case WM_KEYUP: |
+ break; |
+ case WM_CLOSE: |
+ ::DestroyWindow(hwnd); |
+ break; |
+ case WM_DESTROY: |
+ ::PostQuitMessage(0); |
+ break; |
+ default: |
+ return ::DefWindowProc(hwnd, msg, wParam, lParam); |
+ } |
+ return 0; |
+} |
+ |
+int WINAPI WinMain(HINSTANCE hInstance, |
+ HINSTANCE hPrevInstance, |
+ LPSTR lpCmdLine, |
+ int nCmdShow) { |
+ WNDCLASSEX wc; |
+ HWND hwnd; |
+ MSG msg; |
+ |
+ // The parent process should have set up this named event already. |
+ HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_winproc_event); |
+ if (event == NULL || event == INVALID_HANDLE_VALUE) |
+ return 1; |
+ |
+ // Step 1: Registering the Window Class. |
+ wc.cbSize = sizeof(WNDCLASSEX); |
+ wc.style = 0; |
+ wc.lpfnWndProc = WndProc; |
+ wc.cbClsExtra = 0; |
+ wc.cbWndExtra = 0; |
+ wc.hInstance = hInstance; |
+ wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); |
+ wc.hCursor = ::LoadCursor(NULL, IDC_ARROW); |
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); |
+ wc.lpszMenuName = NULL; |
+ wc.lpszClassName = g_winproc_class_name; |
+ wc.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); |
+ |
+ if (!::RegisterClassEx(&wc)) |
+ return 1; |
+ |
+ // Step 2: Create the Window. |
+ hwnd = ::CreateWindowExW(WS_EX_CLIENTEDGE, g_winproc_class_name, |
+ g_winproc_window_name, WS_OVERLAPPEDWINDOW, |
+ CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, |
+ hInstance, NULL); |
+ |
+ if (hwnd == NULL) |
+ return 1; |
+ |
+ ::ShowWindow(hwnd, nCmdShow); |
+ ::UpdateWindow(hwnd); |
+ |
+ // Step 3: Signal that WinProc is up and running. |
+ ::SetEvent(event); |
+ |
+ // Step 4: The Message Loop |
+ // WM_QUIT results in a 0 value from GetMessageW, |
+ // breaking the loop. |
+ while (::GetMessageW(&msg, NULL, 0, 0) > 0) { |
+ ::TranslateMessage(&msg); |
+ ::DispatchMessageW(&msg); |
+ } |
+ |
+ ::SetEvent(event); |
+ ::CloseHandle(event); |
+ |
+ return msg.wParam; |
+} |