1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4
5 #include "tests/cefclient/browser/temp_window_win.h"
6
7 #include <windows.h>
8
9 #include "include/base/cef_logging.h"
10
11 namespace client {
12
13 namespace {
14
15 const wchar_t kWndClass[] = L"Client_TempWindow";
16
17 // Create the temp window.
CreateTempWindow()18 HWND CreateTempWindow() {
19 HINSTANCE hInstance = ::GetModuleHandle(nullptr);
20
21 WNDCLASSEX wc = {0};
22 wc.cbSize = sizeof(wc);
23 wc.lpfnWndProc = DefWindowProc;
24 wc.hInstance = hInstance;
25 wc.lpszClassName = kWndClass;
26 RegisterClassEx(&wc);
27
28 // Create a 1x1 pixel hidden window.
29 return CreateWindow(kWndClass, 0, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 0, 0,
30 1, 1, nullptr, nullptr, hInstance, nullptr);
31 }
32
33 TempWindowWin* g_temp_window = nullptr;
34
35 } // namespace
36
TempWindowWin()37 TempWindowWin::TempWindowWin() : hwnd_(nullptr) {
38 DCHECK(!g_temp_window);
39 g_temp_window = this;
40
41 hwnd_ = CreateTempWindow();
42 CHECK(hwnd_);
43 }
44
~TempWindowWin()45 TempWindowWin::~TempWindowWin() {
46 g_temp_window = nullptr;
47 DCHECK(hwnd_);
48 DestroyWindow(hwnd_);
49 }
50
51 // static
GetWindowHandle()52 CefWindowHandle TempWindowWin::GetWindowHandle() {
53 DCHECK(g_temp_window);
54 return g_temp_window->hwnd_;
55 }
56
57 } // namespace client
58