diff options
author | chai <chaifix@163.com> | 2019-04-01 08:57:51 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-01 08:57:51 +0800 |
commit | 1b45a791cfa9f2ee9f00c40108e621b9e462eced (patch) | |
tree | bd954d5069610c51be346716d15e4896c723101d /source/tests/win32/01-window/02_multi_window.cpp | |
parent | fa2bf295fa9646a3052ab0498a4577f586eadef0 (diff) |
+win32 test
Diffstat (limited to 'source/tests/win32/01-window/02_multi_window.cpp')
-rw-r--r-- | source/tests/win32/01-window/02_multi_window.cpp | 104 |
1 files changed, 104 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..99a943f --- /dev/null +++ b/source/tests/win32/01-window/02_multi_window.cpp @@ -0,0 +1,104 @@ +#include "config.h" + +#if _run_app == _multi_window + +#include <windows.h> +#include <GL/gl.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 = CreateWindowEx(WS_EX_WINDOWEDGE,"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 |