OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "integration_tests_common.h" | |
6 | |
7 #include <windows.h> | |
8 | |
9 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.
| |
10 // Injected keystroke via PostThreadMessage won't be dispatched to here. | |
11 // Have to use SendMessage or SendInput to trigger the keyboard hook. | |
12 switch (msg) { | |
13 case WM_KEYDOWN: | |
14 break; | |
15 case WM_KEYUP: | |
16 break; | |
17 case WM_CLOSE: | |
18 ::DestroyWindow(hwnd); | |
19 break; | |
20 case WM_DESTROY: | |
21 ::PostQuitMessage(0); | |
22 break; | |
23 default: | |
24 return ::DefWindowProc(hwnd, msg, wParam, lParam); | |
25 } | |
26 return 0; | |
27 } | |
28 | |
29 int WINAPI WinMain(HINSTANCE hInstance, | |
30 HINSTANCE hPrevInstance, | |
31 LPSTR lpCmdLine, | |
32 int nCmdShow) { | |
33 WNDCLASSEX wc; | |
34 HWND hwnd; | |
35 MSG msg; | |
36 | |
37 // The parent process should have set up this named event already. | |
38 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_winproc_event); | |
39 if (event == NULL || event == INVALID_HANDLE_VALUE) | |
40 return 1; | |
41 | |
42 // Step 1: Registering the Window Class. | |
43 wc.cbSize = sizeof(WNDCLASSEX); | |
44 wc.style = 0; | |
45 wc.lpfnWndProc = WndProc; | |
46 wc.cbClsExtra = 0; | |
47 wc.cbWndExtra = 0; | |
48 wc.hInstance = hInstance; | |
49 wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); | |
50 wc.hCursor = ::LoadCursor(NULL, IDC_ARROW); | |
51 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | |
52 wc.lpszMenuName = NULL; | |
53 wc.lpszClassName = g_winproc_class_name; | |
54 wc.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); | |
55 | |
56 if (!::RegisterClassEx(&wc)) | |
57 return 1; | |
58 | |
59 // Step 2: Create the Window. | |
60 hwnd = ::CreateWindowExW(WS_EX_CLIENTEDGE, g_winproc_class_name, | |
61 g_winproc_window_name, WS_OVERLAPPEDWINDOW, | |
62 CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, | |
63 hInstance, NULL); | |
64 | |
65 if (hwnd == NULL) | |
66 return 1; | |
67 | |
68 ::ShowWindow(hwnd, nCmdShow); | |
69 ::UpdateWindow(hwnd); | |
70 | |
71 // Step 3: Signal that WinProc is up and running. | |
72 ::SetEvent(event); | |
73 | |
74 // Step 4: The Message Loop | |
75 // WM_QUIT results in a 0 value from GetMessageW, | |
76 // breaking the loop. | |
77 while (::GetMessageW(&msg, NULL, 0, 0) > 0) { | |
78 ::TranslateMessage(&msg); | |
79 ::DispatchMessageW(&msg); | |
80 } | |
81 | |
82 ::SetEvent(event); | |
83 ::CloseHandle(event); | |
84 | |
85 return msg.wParam; | |
86 } | |
OLD | NEW |