设为首页 加入收藏

TOP

Windows API 搭建OpenGL窗口(二)
2019-05-25 22:08:47 】 浏览:171
Tags:Windows API 搭建 OpenGL 窗口
ture
windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = MainWindowProc; //当窗体触发任何一个事件时,便会调用该函数 windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow windowClass.hbrBackground = NULL; // don't need background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = L"Windows API"; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon // register the windows class if (!RegisterClassEx(&windowClass)) { puts("Register Class Failed"); } dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // class registered, so now create our window hwnd = CreateWindowEx(NULL, // extended style L"Windows API", // class name L"OpenGL", // app name dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, // x,y coordinate windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, // width, height NULL, // handle to parent NULL, // handle to menu hInstance, // application instance NULL); // no extra params ShowWindow(hwnd, SW_SHOW); // display the window UpdateWindow(hwnd); // update the window hDC = GetDC(hwnd); glContext.Setup(hwnd,hDC); } LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int height, width; // dispatch messages switch (uMsg) { case WM_CREATE: // window creation break; case WM_DESTROY: // window destroy case WM_QUIT: CloseWindow(hWnd); break; case WM_CLOSE: // windows is closing // deselect rendering context and delete it //wglMakeCurrent(hDC, NULL); //wglDeleteContext(hRC); // send WM_QUIT to message queue PostQuitMessage(0); break; case WM_SIZE: height = HIWORD(lParam); // retrieve width and height width = LOWORD(lParam); break; case WM_ACTIVATEAPP: // activate app break; case WM_PAINT: // paint PAINTSTRUCT ps; BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: // left mouse button break; case WM_RBUTTONDOWN: // right mouse button break; case WM_MOUSEMOVE: // mouse movement break; case WM_LBUTTONUP: // left button release break; case WM_RBUTTONUP: // right button release break; case WM_KEYUP: break; case WM_KEYDOWN: int fwKeys; LPARAM keyData; fwKeys = (int)wParam; // virtual-key code keyData = lParam; // key data switch (fwKeys) { case VK_ESCAPE: PostQuitMessage(0); break; default: break; } break; default: break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } void GLWindow::Run() { while (true) { (*Display)(); SwapBuffers(hDC); while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) { exiting = true; break; } TranslateMessage(&msg); DispatchMessage(&msg); } } }

 

主函数调用代码示例:

#include <Windows.h>
#include <cameras/phc.h>
#inclu
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇memset 下一篇[NOI2006] 神奇口袋

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目