OpenGL (1) uses Win API to create a black window and openglapi
Create a black window as the GL container.
The Light3dWinAPP class handles window creation and destruction and distribution system events.
/*********************** File: Light3dWinAPP. h; * Author: chenpeng * Data: 2015/07/21; */# include <Windows. h> # include <tchar. h> namespace Light3d {class Light3dWinAPP {public: HINSTANCE m_hInstance; // instance handle; HWND m_hWnd; // window handle; int m_width; // width; int m_height; // height; public: Light3dWinAPP (HINSTANCE hInstance): m_hInstance (hInstance) {// to create a window, there must be a window class; WNDCLASSEX winClass; // window class name; winClass. lpszClassName = _ T ("Light3dWinAPP" ); WinClass. cbSize = sizeof (winClass); // when the H horizontal direction and V vertical direction change or move, redraw the window, // assign a unique device context for each window in the class; winClass. style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // point to the function's long pointer lp, processing the message loop in the window; winClass. lpfnWndProc = wndProc; // instance handle; winClass. hInstance = hInstance; // window minimization icon; winClass. hIcon = 0; winClass. hIconSm = 0; // mouse cursor; winClass. hCursor = LoadCursor (hInstance, IDC_ARROW); // window background color; winClass. hbrBackground = (HBRUSH) GetStockObjec T (BLACK_BRUSH); // Window menu; winClass. lpszMenuName = nullptr; winClass. cbClsExtra = 0; winClass. cbWndExtra = 0; RegisterClassEx (& winClass);} virtual ~ Light3dWinAPP () {UnregisterClass (_ T ("CELLWinAPP"), m_hInstance);} protected: static lresult callback wndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {Light3dWinAPP * pThis = (Light3dWinAPP *) GetWindowLong (hWnd, GWL_USERDATA); if (pThis) {return pThis-> onEvent (hWnd, msg, wParam, lParam );} if (WM_CREATE = msg) {CREATESTRUCT * pCreate = (CREATESTRUCT *) lParam; SetWindowLong (hWnd, GWL_USERDATA, (DWORD_PT R) pCreate-> lpCreateParams);} return DefWindowProc (hWnd, msg, wParam, lParam);} public: // window event; virtual LRESULT onEvent (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {switch (msg) {case WM_CLOSE: case WM_DESTROY :{:: PostQuitMessage (0);} break; case WM_MOUSEMOVE: break; case WM_LBUTTONDOWN: break; case WM_LBUTTONUP: break; case WM_RBUTTONDOWN: break; case WM_RBUTTONUP: break; case WM_KEYDOWN: {switch (wParam) {ca Se VK_LEFT :{} break; case VK_RIGHT: break; case VK_UP: break; default: break ;}} break; case WM_KEYUP: break; default: return DefWindowProc (hWnd, msg, wParam, lParam);} return S_ OK;} // main function; int main (int width, int height) {// create a window; m_hWnd = createmediawex (NULL, _ T ("Light3dWinAPP"), _ T ("Light3D"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, m_hInstance, this ); if (m_hWnd = 0) {return-1;} ShowWindow (m_hWnd, SW_SHOW); MSG msg = {0}; while (msg. message! = WM_QUIT) {if (msg. message = WM_DESTROY | msg. message = WM_CLOSE) {// jump out, exit; break;} // process the message when there is a message, rendering when there is no message; if (PeekMessage (& msg, NULL, 0, 0, PM_REMOVE) {TranslateMessage (& msg); DispatchMessage (& msg) ;}else {// rendering; Sleep (1 );}} return 0 ;}};}
The entry function for processing Win in main. cpp
/***********************File:main.cpp;*Author:chenpeng*Data:2015/07/21;*/#include "Light3dWinAPP.h"int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){UNREFERENCED_PARAMETER(hInstance);UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine);UNREFERENCED_PARAMETER(nCmdShow);Light3d::Light3dWinAPP app(hInstance);app.main(800, 600);}
Download example:
http://pan.baidu.com/s/1c0EtfR6
Copyright: This article