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 window, | |
10 UINT message, | |
11 WPARAM w_param, | |
12 LPARAM l_param) { | |
13 // Injected keystroke via PostThreadMessage won't be dispatched to here. | |
14 // Have to use SendMessage or SendInput to trigger the keyboard hook. | |
15 switch (message) { | |
16 case WM_KEYDOWN: | |
17 break; | |
18 case WM_KEYUP: | |
19 break; | |
20 case WM_CLOSE: | |
21 ::DestroyWindow(window); | |
22 break; | |
23 case WM_DESTROY: | |
24 ::PostQuitMessage(0); | |
25 break; | |
26 default: | |
27 return ::DefWindowProc(window, message, w_param, l_param); | |
28 } | |
29 return 0; | |
30 } | |
31 | |
32 int WINAPI WinMain(HINSTANCE instance, | |
33 HINSTANCE prev_instance, | |
34 LPSTR cmd_line, | |
35 int cmd_show) { | |
36 // The parent process should have set up this named event already. | |
37 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, g_winproc_event); | |
38 if (event == NULL || event == INVALID_HANDLE_VALUE) | |
39 return 1; | |
40 | |
41 // Step 1: Registering the Window Class. | |
42 WNDCLASSEX window_class; | |
43 window_class.cbSize = sizeof(WNDCLASSEX); | |
44 window_class.style = 0; | |
45 window_class.lpfnWndProc = WndProc; | |
46 window_class.cbClsExtra = 0; | |
47 window_class.cbWndExtra = 0; | |
48 window_class.hInstance = instance; | |
49 window_class.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); | |
50 window_class.hCursor = ::LoadCursor(NULL, IDC_ARROW); | |
51 window_class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | |
Will Harris
2016/05/18 09:02:29
nit: c++ cast (e.g. static_cast<>) - is it even ne
penny
2016/06/14 21:45:09
Yes, the cast is needed, otherwise "int" can't be
| |
52 window_class.lpszMenuName = NULL; | |
53 window_class.lpszClassName = g_winproc_class_name; | |
54 window_class.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); | |
55 | |
56 if (!::RegisterClassEx(&window_class)) | |
57 return 1; | |
58 | |
59 // Step 2: Create the Window. | |
60 HWND window = ::CreateWindowExW(WS_EX_CLIENTEDGE, g_winproc_class_name, | |
61 g_winproc_window_name, WS_OVERLAPPEDWINDOW, | |
62 CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, | |
63 NULL, instance, NULL); | |
64 | |
65 if (window == NULL) | |
66 return 1; | |
67 | |
68 ::ShowWindow(window, cmd_show); | |
69 ::UpdateWindow(window); | |
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 MSG message; | |
78 while (::GetMessageW(&message, NULL, 0, 0) > 0) { | |
79 ::TranslateMessage(&message); | |
80 ::DispatchMessageW(&message); | |
81 } | |
82 | |
83 ::SetEvent(event); | |
84 ::CloseHandle(event); | |
85 | |
86 return message.wParam; | |
87 } | |
OLD | NEW |