-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
131 lines (107 loc) · 3.04 KB
/
Copy pathwindow.cpp
File metadata and controls
131 lines (107 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "window.h"
Window::Window ()
{
}
Window::~Window ()
{
}
bool Window::create (char *title)
{
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
WNDCLASS wc;
hInstance = GetModuleHandle (NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";
if (!RegisterClass (&wc))
return false;
RtlZeroMemory (&screenSettings, sizeof (screenSettings));
p.nSize = sizeof (PIXELFORMATDESCRIPTOR);
p.nVersion = 1;
p.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
p.iPixelType = PFD_TYPE_RGBA;
p.cColorBits = 32;
p.cDepthBits = 16;
p.iLayerType = PFD_MAIN_PLANE;
RtlZeroMemory (&screenSettings, sizeof (screenSettings));
screenSettings.dmSize = sizeof (screenSettings);
screenSettings.dmPelsWidth = OPENGL_XRES;
screenSettings.dmPelsHeight = OPENGL_YRES;
screenSettings.dmBitsPerPel = 32;
screenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (OPENGL_FULLSCREEN)
{
DEVMODE dmScreenSettings;
memset (&dmScreenSettings, 0, sizeof (dmScreenSettings));
dmScreenSettings.dmSize = sizeof (dmScreenSettings);
dmScreenSettings.dmPelsWidth = OPENGL_XRES;
dmScreenSettings.dmPelsHeight = OPENGL_YRES;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
return false;
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
}
hwnd = CreateWindowEx (dwExStyle, "OpenGL", title, dwStyle, 0, 0, OPENGL_XRES, OPENGL_YRES, NULL, NULL, hInstance, NULL);
hdc = GetDC (hwnd);
pixelformat = ChoosePixelFormat (hdc, &p);
SetPixelFormat (hdc, pixelformat, &p);
hrc = wglCreateContext (hdc);
wglMakeCurrent (hdc, hrc);
if (OPENGL_FULLSCREEN)
ShowCursor (false);
else
ShowCursor (true);
ShowWindow (hwnd, SW_SHOW);
SetForegroundWindow (hwnd);
SetFocus (hwnd);
return true;
}
void Window::shut()
{
ChangeDisplaySettings (NULL, 0);
ReleaseDC (hwnd, hdc);
DestroyWindow (hwnd);
}
HDC Window::getDC()
{
return hdc;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CLOSE:
PostQuitMessage(0);
return 0;
break;
case WM_MOUSEMOVE:
mouseCoords [0] = LOWORD (lParam);
mouseCoords [1] = HIWORD (lParam);
break;
case WM_LBUTTONDOWN:
mouseLeftButtonClicked = true;
break;
case WM_LBUTTONUP:
mouseLeftButtonClicked = false;
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}