1 /*
2  * Copyright (C) 2016 Google, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef SHELL_WIN32_H
24 #define SHELL_WIN32_H
25 
26 #include <windows.h>
27 #include "Shell.h"
28 
29 class ShellWin32 : public Shell {
30 public:
31     ShellWin32(Game &game);
32     ~ShellWin32();
33 
34     void run();
35     void quit();
36 
37 private:
38 
39     PFN_vkGetInstanceProcAddr load_vk();
40     bool can_present(VkPhysicalDevice phy, uint32_t queue_family);
41 
42     void create_window();
43     VkSurfaceKHR create_surface(VkInstance instance);
44 
window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)45     static LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
46     {
47         ShellWin32 *shell = reinterpret_cast<ShellWin32 *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
48 
49         // called from constructor, CreateWindowEx specifically.  But why?
50         if (!shell)
51             return DefWindowProc(hwnd, uMsg, wParam, lParam);
52 
53         return shell->handle_message(uMsg, wParam, lParam);
54     }
55     LRESULT handle_message(UINT msg, WPARAM wparam, LPARAM lparam);
56 
57     HINSTANCE hinstance_;
58     HWND hwnd_;
59 
60     HMODULE hmodule_;
61 };
62 
63 #endif // SHELL_WIN32_H
64