@@ -25,13 +25,17 @@ SOFTWARE.*/
2525#include < OGL3D/Window/OWindow.h>
2626#include < OGL3D/Game/OGame.h>
2727#include < Windows.h>
28- #include < stdexcept>
29- #include < functional>
28+ #include < assert.h>
3029
3130LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3231{
3332 switch (msg)
3433 {
34+ case WM_DESTROY:
35+ {
36+ OWindow* window = (OWindow*)GetWindowLongPtr (hwnd, GWLP_USERDATA);
37+ break ;
38+ }
3539 case WM_CLOSE:
3640 {
3741 PostQuitMessage (0 );
@@ -46,32 +50,26 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4650
4751OWindow::OWindow ()
4852{
49- static const ATOM windowClassId = std::invoke (
50- []() -> ATOM
51- {
52- WNDCLASSEX wc = {};
53- wc.cbSize = sizeof (WNDCLASSEX);
54- wc.lpszClassName = L" OGL3DWindow" ;
55- wc.lpfnWndProc = &WndProc;
56- return RegisterClassEx (&wc);
57- }
58- );
59-
60- if (!windowClassId) throw std::runtime_error (" RegisterClassEx failed" );
61-
53+ WNDCLASSEX wc = {};
54+ wc.cbSize = sizeof (WNDCLASSEX);
55+ wc.lpszClassName = L" OGL3DWindow" ;
56+ wc.lpfnWndProc = &WndProc;
57+
58+ auto classId = RegisterClassEx (&wc);
59+ assert (classId);
60+
6261 RECT rc = { 0 ,0 ,1024 ,768 };
6362 AdjustWindowRect (&rc, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, false );
6463
65- m_handle = CreateWindowEx (NULL , MAKEINTATOM (windowClassId), L" PardCode | OpenGL 3D Game" , WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
66- CW_USEDEFAULT, CW_USEDEFAULT,
67- rc.right - rc.left , rc.bottom - rc.top , HWND (), HMENU (), HINSTANCE (), NULL );
64+ m_handle = CreateWindowEx (NULL , MAKEINTATOM (classId), L" PardCode | OpenGL 3D Game" , WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT,
65+ rc.right - rc.left , rc.bottom - rc.top , NULL , NULL , NULL , NULL );
6866
69- if (! m_handle) throw std::runtime_error ( " CreateWindowEx failed " );
67+ assert ( m_handle);
7068
7169 SetWindowLongPtr ((HWND)m_handle, GWLP_USERDATA, (LONG_PTR)this );
7270
73- ShowWindow (HWND (m_handle) , SW_SHOW);
74- UpdateWindow (HWND (m_handle) );
71+ ShowWindow ((HWND)m_handle , SW_SHOW);
72+ UpdateWindow ((HWND)m_handle );
7573}
7674
7775OWindow::~OWindow ()
0 commit comments