1 #define _WIN32_WINNT 0x0601
3 #include <msp/core/application.h>
4 #include <msp/core/systemerror.h>
6 #include "window_private.h"
12 LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
16 CREATESTRUCT *cs = reinterpret_cast<CREATESTRUCT *>(lparam);
17 SetWindowLong(hwnd, 0, reinterpret_cast<LONG>(cs->lpCreateParams));
21 Msp::Graphics::Window *wnd = reinterpret_cast<Msp::Graphics::Window *>(GetWindowLong(hwnd, 0));
22 Msp::Graphics::Window::Event ev;
26 ev.extra = GetMessageExtraInfo();
27 if(wnd && wnd->event(ev))
31 return DefWindowProc(hwnd, msg, wparam, lparam);
39 void Window::platform_init()
41 static bool wndclass_created = false;
47 wndcl.cbSize = sizeof(WNDCLASSEX);
49 wndcl.lpfnWndProc = &wndproc_;
51 wndcl.cbWndExtra = sizeof(Window *);
52 wndcl.hInstance = reinterpret_cast<HINSTANCE>(Application::get_data());
54 wndcl.hCursor = LoadCursor(0, IDC_ARROW);
55 wndcl.hbrBackground = 0;
56 wndcl.lpszMenuName = 0;
57 wndcl.lpszClassName = "mspgui";
60 if(!RegisterClassEx(&wndcl))
61 throw system_error("RegisterClassEx");
63 wndclass_created = true;
67 SetRect(&rect, 0, 0, options.width, options.height);
69 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
70 if(!options.resizable)
71 style &= ~WS_THICKFRAME;
72 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
73 AdjustWindowRectEx(&rect, style, false, exstyle);
75 priv->window = CreateWindowEx(exstyle,
79 CW_USEDEFAULT, CW_USEDEFAULT,
80 rect.right-rect.left, rect.bottom-rect.top,
83 reinterpret_cast<HINSTANCE>(Application::get_data()),
86 throw system_error("CreateWindowEx");
89 void Window::platform_cleanup()
92 CloseWindow(priv->window);
95 void Window::set_title(const string &title)
97 SetWindowText(priv->window, title.c_str());
100 void Window::platform_reconfigure(bool fullscreen_changed)
103 SetRect(&rect, 0, 0, options.width, options.height);
105 int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW);
106 if(!options.resizable)
107 style &= ~WS_THICKFRAME;
108 int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW);
109 AdjustWindowRectEx(&rect, style, false, exstyle);
111 if(fullscreen_changed)
114 SetWindowLong(priv->window, GWL_EXSTYLE, exstyle);
115 SetWindowLong(priv->window, GWL_STYLE, style);
119 if(options.fullscreen)
120 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER);
122 SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER);
125 void Window::show_cursor(bool s)
130 void Window::warp_pointer(int, int)
134 void Window::platform_set_touch_input()
136 WORD winver = LOWORD(GetVersion);
137 if(winver<_WIN32_WINNT)
140 throw runtime_error("no touch support");
144 RegisterTouchWindow(priv->window, 3); // TWF_FINETOUCH|TWF_WANTPALM
146 UnregisterTouchWindow(priv->window);
149 void Window::platform_show()
151 ShowWindow(priv->window, SW_SHOWNORMAL);
154 void Window::platform_hide()
156 ShowWindow(priv->window, SW_HIDE);
159 bool Window::event(const Event &evnt)
175 signal_input_event.emit(evnt);
178 options.width = LOWORD(evnt.lparam);
179 options.height = HIWORD(evnt.lparam);
181 signal_resize.emit(options.width, options.height);
193 } // namespace Graphics