OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 <windows.h> |
| 6 |
| 7 namespace { |
| 8 |
| 9 const wchar_t* class_name = L"myWindowClass"; |
| 10 // WinProc event name |
| 11 const wchar_t* winproc_event = L"ChromeExtensionTestEvent"; |
| 12 |
| 13 } // namespace |
| 14 |
| 15 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 16 // Injected keystroke via PostThreadMessage won't be dispatched to here. |
| 17 // Have to use SendMessage or SendInput to trigger the keyboard hook. |
| 18 switch (msg) { |
| 19 case WM_KEYDOWN: |
| 20 break; |
| 21 case WM_KEYUP: |
| 22 break; |
| 23 case WM_CLOSE: |
| 24 ::DestroyWindow(hwnd); |
| 25 break; |
| 26 case WM_DESTROY: |
| 27 ::PostQuitMessage(0); |
| 28 break; |
| 29 default: |
| 30 return ::DefWindowProc(hwnd, msg, wParam, lParam); |
| 31 } |
| 32 return 0; |
| 33 } |
| 34 |
| 35 int WINAPI WinMain(HINSTANCE hInstance, |
| 36 HINSTANCE hPrevInstance, |
| 37 LPSTR lpCmdLine, |
| 38 int nCmdShow) { |
| 39 WNDCLASSEX wc; |
| 40 HWND hwnd; |
| 41 MSG msg; |
| 42 |
| 43 // Our parent should have set up this event already. |
| 44 HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, winproc_event); |
| 45 if (event == NULL || event == INVALID_HANDLE_VALUE) |
| 46 return 1; |
| 47 |
| 48 // Step 1: Registering the Window Class. |
| 49 wc.cbSize = sizeof(WNDCLASSEX); |
| 50 wc.style = 0; |
| 51 wc.lpfnWndProc = WndProc; |
| 52 wc.cbClsExtra = 0; |
| 53 wc.cbWndExtra = 0; |
| 54 wc.hInstance = hInstance; |
| 55 wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); |
| 56 wc.hCursor = ::LoadCursor(NULL, IDC_ARROW); |
| 57 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); |
| 58 wc.lpszMenuName = NULL; |
| 59 wc.lpszClassName = class_name; |
| 60 wc.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION); |
| 61 |
| 62 if (!::RegisterClassEx(&wc)) |
| 63 return 1; |
| 64 |
| 65 // Step 2: Creating the Window. |
| 66 hwnd = |
| 67 ::CreateWindowExW(WS_EX_CLIENTEDGE, class_name, |
| 68 L"ChromeMitigationTests", WS_OVERLAPPEDWINDOW, |
| 69 CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, |
| 70 hInstance, NULL); |
| 71 |
| 72 if (hwnd == NULL) |
| 73 return 1; |
| 74 |
| 75 ::ShowWindow(hwnd, nCmdShow); |
| 76 ::UpdateWindow(hwnd); |
| 77 |
| 78 // Step 3: Let 'em know we're up and running. |
| 79 ::SetEvent(event); |
| 80 |
| 81 // Step 4: The Message Loop |
| 82 // WM_QUIT results in a 0 value from GetMessageW, |
| 83 // breaking the loop. |
| 84 while (::GetMessageW(&msg, NULL, 0, 0) > 0) { |
| 85 ::TranslateMessage(&msg); |
| 86 ::DispatchMessageW(&msg); |
| 87 } |
| 88 |
| 89 ::SetEvent(event); |
| 90 ::CloseHandle(event); |
| 91 |
| 92 return msg.wParam; |
| 93 } |
OLD | NEW |