1+
2+ #include " Win32RenderWindow.h"
3+
4+ LRESULT CALLBACK InternalWindowProc ( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
5+ {
6+ LONG_PTR ObjPtr = GetWindowLongPtr (hwnd, 0 );
7+
8+ if (ObjPtr == 0 ) {
9+ return ( DefWindowProc ( hwnd, msg, wparam, lparam ) );
10+ } else {
11+ return ( reinterpret_cast <Win32RenderWindow*>(ObjPtr)->WindowProc (hwnd, msg, wparam, lparam) );
12+ }
13+ }
14+
15+
16+
17+ Win32RenderWindow::Win32RenderWindow ( unsigned int width, unsigned int height ) :
18+ handle( 0 )
19+ {
20+ WNDCLASSEX wc;
21+
22+ // Setup the window class
23+ memset (&wc, 0 , sizeof (wc));
24+
25+ wc.cbSize = sizeof (WNDCLASSEX);
26+ wc.style = CS_HREDRAW | CS_VREDRAW;
27+ wc.lpfnWndProc = InternalWindowProc;
28+ wc.cbClsExtra = 0 ;
29+ wc.cbWndExtra = sizeof (this );
30+ wc.hInstance = 0 ;
31+ wc.hIcon = LoadIcon (NULL , IDI_APPLICATION);
32+ wc.hCursor = LoadCursor (NULL , IDC_ARROW);
33+ wc.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
34+ wc.lpszMenuName = NULL ;
35+ wc.lpszClassName = L" HieroglyphWin32" ;
36+ wc.hIconSm = LoadIcon (NULL , IDI_APPLICATION);
37+
38+
39+ // Register the window class
40+ RegisterClassEx (&wc);
41+
42+ // Record the desired device size
43+ RECT rc;
44+ rc.top = rc.left = 0 ;
45+ rc.right = width;
46+ rc.bottom = height;
47+
48+ // Adjust the window size for correct device size
49+ AdjustWindowRect (&rc, (WS_OVERLAPPEDWINDOW | WS_VISIBLE), FALSE );
50+
51+ long lwidth = rc.right - rc.left ;
52+ long lheight = rc.bottom - rc.top ;
53+
54+ long lleft = 10 ;
55+ long ltop = 10 ;
56+
57+
58+ // Create an instance of the window
59+ handle = CreateWindowEx (
60+ NULL , // extended style
61+ wc.lpszClassName , // class name
62+ L" N3888_RefImpl" , // instance title
63+ (WS_OVERLAPPEDWINDOW | WS_VISIBLE), // window style
64+ lleft, ltop, // initial x, y
65+ lwidth, // initial width
66+ lheight, // initial height
67+ NULL , // handle to parent
68+ NULL , // handle to menu
69+ NULL , // instance of this application
70+ NULL ); // extra creation parms
71+
72+ if ( handle != 0 ) {
73+ // Set in the "extra" bytes the pointer to the 'this' pointer
74+ // so it can handle messages for itself.
75+ SetWindowLongPtr ( handle, 0 , (LONG_PTR)this );
76+
77+ // Initially display the window
78+ ShowWindow (handle, SW_SHOWNORMAL);
79+ UpdateWindow (handle);
80+ }
81+
82+
83+ }
84+
85+ Win32RenderWindow::~Win32RenderWindow ()
86+ {
87+ if (handle != 0 )
88+ {
89+ DestroyWindow (handle);
90+ handle = 0 ;
91+ }
92+ }
93+
94+
95+ LRESULT Win32RenderWindow::WindowProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
96+ {
97+
98+ switch (msg)
99+ {
100+ case WM_CREATE:
101+ {
102+ // Automatically return 0 to allow the window to proceed in the
103+ // creation process.
104+ return (0 );
105+ } break ;
106+
107+ case WM_PAINT:
108+ {
109+ // This message is handled by the default handler to avoid a
110+ // repeated sending of the message. This results in the ability
111+ // to process all pending messages at once without getting stuck
112+ // in an eternal loop.
113+ } break ;
114+
115+ case WM_CLOSE:
116+ {
117+ // This message is sent when a window or an application should
118+ // terminate.
119+ } break ;
120+
121+ case WM_DESTROY:
122+ {
123+ // This message is sent when a window has been destroyed.
124+ PostQuitMessage (0 );
125+ return (0 );
126+ } break ;
127+
128+ case WM_SIZE:
129+ {
130+ // EvtWindowResizePtr pEvent = EvtWindowResizePtr(new EvtWindowResize(hwnd, wparam, lparam));
131+ // EvtManager.ProcessEvent(pEvent);
132+ } break ;
133+
134+ }
135+
136+ return (DefWindowProc (hwnd, msg, wparam, lparam));
137+
138+ }
0 commit comments