GteMSWWindowSystem.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.2 (2016/11/12)
7 
8 #pragma once
9 
11 #include <map>
12 #include <memory>
13 
14 namespace gte
15 {
16 
18 {
19 public:
20  // Abstract base class. The derived classes are instantiable and
21  // singletons.
22  virtual ~MSWWindowSystem();
23 protected:
25 
26 public:
27  // Create and destroy windows. Derived classes may extend the inputs
28  // using a nested class derived from Window::Parameters
29  template <typename WindowType>
30  std::shared_ptr<WindowType> Create(typename WindowType::Parameters& parameters);
31 
32  template <typename WindowType>
33  void Destroy(std::shared_ptr<WindowType>& window);
34 
35  enum
36  {
37  DEFAULT_ACTION = 0,
38  NO_IDLE_LOOP = 1
39  };
40 
41  template <typename WindowType>
42  void MessagePump(std::shared_ptr<WindowType> const& window, unsigned int flags);
43 
44 protected:
45  // Get the true window size for the specified client size. The true size
46  // includes extra space for window decorations (window border, menu bar,
47  // and so on). This information is useful to know before creating a
48  // window to ensure the to-be-created window fits within the monitor
49  // resolution.
50  static bool GetWindowRectangle(int xClientSize, int yClientSize,
51  DWORD style, RECT& windowRectangle);
52 
53  // Window creation and destruction.
54  void CreateFrom(MSWWindow::Parameters& parameters);
55  virtual void CreateEngineAndProgramFactory(MSWWindow::Parameters& parameters) = 0;
56 
57  // Extraction of cursor location, avoiding the extraction in <windows.h>
58  // that does not work when you have dual monitors.
59  static void Extract(LPARAM lParam, int& x, int& y);
60  static void Extract(WPARAM wParam, int& x, int& y);
61 
62  // The event handler.
63  static LRESULT CALLBACK WindowProcedure(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
64 
65  wchar_t const* mWindowClassName;
66  ATOM mAtom;
67  std::map<HWND, std::shared_ptr<MSWWindow>> mHandleMap;
68 };
69 
70 
71 template <typename WindowType>
72 std::shared_ptr<WindowType> MSWWindowSystem::Create(typename WindowType::Parameters& parameters)
73 {
74  CreateFrom(parameters);
75  if (parameters.created)
76  {
77  std::shared_ptr<WindowType> window = std::make_shared<WindowType>(parameters);
78  mHandleMap[parameters.handle] = window;
79  if (parameters.created)
80  {
81  return window;
82  }
83  Destroy(window);
84  }
85  // else: CreateFrom will report the problem via the logger system.
86  return nullptr;
87 }
88 
89 template <typename WindowType>
90 void MSWWindowSystem::Destroy(std::shared_ptr<WindowType>& window)
91 {
92  if (window)
93  {
94  HWND handle = window->GetHandle();
95  mHandleMap.erase(handle);
96  window = nullptr;
97  DestroyWindow(handle);
98  }
99 }
100 
101 template <typename WindowType>
102 void MSWWindowSystem::MessagePump(std::shared_ptr<WindowType> const& window, unsigned int flags)
103 {
104  if (window)
105  {
106  HWND handle = window->GetHandle();
107  ShowWindow(handle, SW_SHOW);
108  UpdateWindow(handle);
109 
110  for (;;)
111  {
112  if (flags & NO_IDLE_LOOP)
113  {
114  WaitMessage();
115  }
116 
117  MSG msg;
118  if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
119  {
120  if (msg.message == WM_QUIT)
121  {
122  break;
123  }
124 
125  TranslateMessage(&msg);
126  DispatchMessage(&msg);
127  }
128  else
129  {
130  if (!(flags & NO_IDLE_LOOP))
131  {
132  if (!window->IsMinimized())
133  {
134  window->OnIdle();
135  }
136  }
137  }
138  }
139  }
140 }
141 
142 }
std::map< HWND, std::shared_ptr< MSWWindow > > mHandleMap
GLint GLenum GLint x
Definition: glcorearb.h:404
void MessagePump(std::shared_ptr< WindowType > const &window, unsigned int flags)
void Destroy(std::shared_ptr< WindowType > &window)
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2538
GLbitfield flags
Definition: glcorearb.h:1591
std::shared_ptr< WindowType > Create(typename WindowType::Parameters &parameters)
wchar_t const * mWindowClassName
typedef UINT(WINAPI *PFNWGLGETGPUIDSAMDPROC)(UINT maxCount
GLint y
Definition: glcorearb.h:98
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01