summaryrefslogtreecommitdiff
path: root/Source/tests/win32/01-window/02_multi_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/tests/win32/01-window/02_multi_window.cpp')
-rw-r--r--Source/tests/win32/01-window/02_multi_window.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/Source/tests/win32/01-window/02_multi_window.cpp b/Source/tests/win32/01-window/02_multi_window.cpp
new file mode 100644
index 0000000..e83f1a3
--- /dev/null
+++ b/Source/tests/win32/01-window/02_multi_window.cpp
@@ -0,0 +1,110 @@
+#include "config.h"
+
+#if _run_app == _multi_window
+
+#include <windows.h>
+#include <GL/GfxDevice.h>
+#include <GL/glu.h>
+#define MAX_LOADSTRING 100
+HINSTANCE hInstance;
+HWND hWnd, hWnd2;
+
+struct WindowData {
+ HWND window;
+ HDC deviceContext;
+ HGLRC renderContext;
+};
+
+LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ static PAINTSTRUCT ps;
+ int pf;
+ PIXELFORMATDESCRIPTOR pfd;
+ HDC deviceContext;
+ HGLRC renderContext;
+ struct WindowData * windowData = (struct WindowData *) GetWindowLongPtr(hWnd, 0);
+ switch (uMsg) {
+ case WM_NCCREATE:
+ deviceContext = GetDC(hWnd);
+ renderContext = wglCreateContext(deviceContext);
+
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+
+ pf = ChoosePixelFormat(deviceContext, &pfd);
+ SetPixelFormat(deviceContext, pf, &pfd);
+ DescribePixelFormat(deviceContext, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+ ReleaseDC(hWnd, deviceContext);
+ renderContext = wglCreateContext(deviceContext);
+ wglMakeCurrent(deviceContext, renderContext);
+
+ windowData = (struct WindowData *) malloc(sizeof(struct WindowData));
+ windowData->window = hWnd;
+ windowData->deviceContext = deviceContext;
+ windowData->renderContext = renderContext;
+ SetWindowLongPtr(hWnd, 0, (LONG)windowData);
+ return TRUE;
+ case WM_ACTIVATE:
+ wglMakeCurrent(windowData->deviceContext, windowData->renderContext);
+ break;
+ case WM_PAINT:
+ wglMakeCurrent(windowData->deviceContext, windowData->renderContext);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glBegin(GL_TRIANGLES);
+ glVertex2i(0, 1);
+ glVertex2i(-1, -1);
+ glVertex2i(1, -1);
+ glEnd();
+ glFlush();
+ wglMakeCurrent(NULL, NULL);
+ BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps);
+ return 0;
+ case WM_SIZE:
+ glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); PostMessage(hWnd, WM_PAINT, 0, 0); return 0;
+ case WM_CHAR:
+ if (wParam == 27) { PostQuitMessage(0); break; }
+ else { return 0; }
+ case WM_DESTROY:
+ ReleaseDC(hWnd, windowData->deviceContext);
+ wglDeleteContext(windowData->renderContext);
+ return 0;
+ case WM_CLOSE:
+ PostQuitMessage(0); return 0;
+ }
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+
+int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) {
+ MSG msg;
+ WNDCLASS wc;
+ int pf;
+ PIXELFORMATDESCRIPTOR pfd;
+ hInstance = GetModuleHandle(NULL);
+
+ wc.style = CS_OWNDC;
+ wc.lpfnWndProc = (WNDPROC)WindowProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = sizeof(struct WindowData *);
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = NULL;
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = "OpenGL2";
+
+ RegisterClass(&wc);
+ hWnd = CreateWindow("OpenGL2", "Hi there", WS_VSCROLL|WS_TILEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);
+ hWnd2 = CreateWindow("OpenGL2", "Hi there", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 110, 110, 640, 480, NULL, NULL, hInstance, NULL);
+ ShowWindow(hWnd, nCmdShow);
+ ShowWindow(hWnd2, nCmdShow);
+ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
+ wglMakeCurrent(NULL, NULL);
+ DestroyWindow(hWnd);
+ return msg.wParam;
+}
+
+#endif // _run_app == _multi_window \ No newline at end of file