Skip to content

Commit 13944ba

Browse files
committed
ISSUE-21: Added a basic Win32RenderWindow implementation for managing a window's lifetime.
1 parent a7ea59d commit 13944ba

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

win32/N3888_RefImpl/N3888_RefImpl.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ cmd /c copy "$(ProjectDir)DLLs\$(PlatformTarget)\$(Configuration)\zlib1.dll" "$(
181181
<ClInclude Include="Resource.h" />
182182
<ClInclude Include="targetver.h" />
183183
<ClInclude Include="throw_helpers.h" />
184+
<ClInclude Include="Win32RenderWindow.h" />
184185
<ClInclude Include="xcairoenumhelpers.h" />
185186
<ClInclude Include="xdrawing.h" />
186187
<ClInclude Include="xdrawinghelpers.h" />
@@ -208,6 +209,7 @@ cmd /c copy "$(ProjectDir)DLLs\$(PlatformTarget)\$(Configuration)\zlib1.dll" "$(
208209
<ClCompile Include="surface_pattern.cpp" />
209210
<ClCompile Include="toy_font_face.cpp" />
210211
<ClCompile Include="user_data_key.cpp" />
212+
<ClCompile Include="Win32RenderWindow.cpp" />
211213
</ItemGroup>
212214
<ItemGroup>
213215
<ResourceCompile Include="N3888_RefImpl.rc" />

win32/N3888_RefImpl/N3888_RefImpl.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<ClInclude Include="xcairoenumhelpers.h">
4646
<Filter>Header Files</Filter>
4747
</ClInclude>
48+
<ClInclude Include="Win32RenderWindow.h">
49+
<Filter>Header Files</Filter>
50+
</ClInclude>
4851
</ItemGroup>
4952
<ItemGroup>
5053
<ClCompile Include="entrypoint-win32.cpp">
@@ -113,6 +116,9 @@
113116
<ClCompile Include="radial_pattern.cpp">
114117
<Filter>Source Files</Filter>
115118
</ClCompile>
119+
<ClCompile Include="Win32RenderWindow.cpp">
120+
<Filter>Source Files</Filter>
121+
</ClCompile>
116122
</ItemGroup>
117123
<ItemGroup>
118124
<ResourceCompile Include="N3888_RefImpl.rc">
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
#ifndef _WIN32RENDERWINDOW_
3+
#define _WIN32RENDERWINDOW_
4+
5+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
6+
#include <windows.h>
7+
8+
class Win32RenderWindow
9+
{
10+
public:
11+
12+
Win32RenderWindow( unsigned int width, unsigned int height );
13+
~Win32RenderWindow();
14+
15+
LRESULT WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
16+
17+
private:
18+
HWND handle;
19+
};
20+
21+
#endif // _WIN32RENDERWINDOW_

win32/N3888_RefImpl/entrypoint-win32.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <wrl.h>
1212
#include "throw_helpers.h"
1313
#include "drawing.h"
14+
#include "Win32RenderWindow.h"
1415

1516
#pragma comment(linker,"\"/manifestdependency:type='win32' \
1617
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
@@ -187,6 +188,8 @@ int WINAPI wWinMain(
187188

188189
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_N3888_REFIMPL));
189190

191+
Win32RenderWindow window( 320, 240 );
192+
190193
// Main message loop:
191194
while (msg.message != WM_QUIT) {
192195
if (!PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {

0 commit comments

Comments
 (0)