<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Unuk: src/libUnuk/Win32Window.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/search.js"></script> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body onload='searchBox.OnSelectItem(0);'> <!-- Generated by Doxygen 1.7.4 --> <script type="text/javascript"><!-- var searchBox = new SearchBox("searchBox", "search",false,'Search'); --></script> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectlogo"><img alt="Logo" src="logo.png"/></td> <td style="padding-left: 0.5em;"> <div id="projectname">Unuk <span id="projectnumber">1.0</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li id="searchli"> <div id="MSearchBox" class="MSearchBoxInactive"> <span class="left"> <img id="MSearchSelect" src="search/mag_sel.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> </span><span class="right"> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </span> </div> </li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> </div> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> initNavTree('_win32_window_8cpp.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <div class="title">src/libUnuk/Win32Window.cpp</div> </div> </div> <div class="contents"> <a href="_win32_window_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include <ctime></span> <a name="l00002"></a>00002 <span class="preprocessor">#include <iostream></span> <a name="l00003"></a>00003 <span class="preprocessor">#include <windows.h></span> <a name="l00004"></a>00004 <span class="preprocessor">#include <GL/gl.h></span> <a name="l00005"></a>00005 <span class="preprocessor">#include "../Libs/wglext.h"</span> <a name="l00006"></a>00006 <span class="preprocessor">#include "<a class="code" href="_win32_window_8h.html">Win32Window.h</a>"</span> <a name="l00007"></a>00007 <span class="preprocessor">#include "../Unuk/Game.h"</span> <a name="l00008"></a>00008 <a name="l00009"></a><a class="code" href="_win32_window_8cpp.html#a3f7bf9695d032fb9ce78678b8d311901">00009</a> <span class="keyword">typedef</span> <a class="code" href="_win32_window_8cpp.html#a3f7bf9695d032fb9ce78678b8d311901">HGLRC</a>(<a class="code" href="glxext_8h.html#aef0d9e5e275e1b7becf54b6aa9ce3911">APIENTRYP</a> PFNWGLCREATECONTEXTATTRIBSARBPROC) (<a class="code" href="wglext_8h.html#aaf5a06bd464c6ec72cf68b4819afebe3">HDC</a>, <a class="code" href="_win32_window_8cpp.html#a3f7bf9695d032fb9ce78678b8d311901">HGLRC</a>, <span class="keyword">const</span> <span class="keywordtype">int</span>*); <a name="l00010"></a><a class="code" href="_win32_window_8cpp.html#a7ba1e8051e394591f1b2d8ed4d44fbe8">00010</a> PFNWGLCREATECONTEXTATTRIBSARBPROC <a class="code" href="_win32_window_8cpp.html#a7ba1e8051e394591f1b2d8ed4d44fbe8">wglCreateContextAttribsARB</a> = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; <a name="l00011"></a>00011 <a name="l00012"></a><a class="code" href="class_win32_window.html#aa35dcf493ad1afa40a834b99ee251042">00012</a> <a class="code" href="class_win32_window.html#aa35dcf493ad1afa40a834b99ee251042">Win32Window::Win32Window</a>(HINSTANCE hInstance) { <a name="l00013"></a>00013 m_isRunning = <span class="keyword">false</span>; <a name="l00014"></a>00014 m_game = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; <a name="l00015"></a>00015 m_hinstance = hInstance; <a name="l00016"></a>00016 m_lastTime = 0; <a name="l00017"></a>00017 } <a name="l00018"></a>00018 <a name="l00019"></a><a class="code" href="class_win32_window.html#aaf37e216644b98bf2744dde43f7dfeb6">00019</a> <a class="code" href="class_win32_window.html#aaf37e216644b98bf2744dde43f7dfeb6">Win32Window::~Win32Window</a>(<span class="keywordtype">void</span>) { <a name="l00020"></a>00020 <a name="l00021"></a>00021 } <a name="l00022"></a>00022 <a name="l00023"></a><a class="code" href="class_win32_window.html#a1399e25540a585c07cc9f8d0dedfabe9">00023</a> <span class="keywordtype">bool</span> <a class="code" href="class_win32_window.html#a1399e25540a585c07cc9f8d0dedfabe9">Win32Window::Create</a>(<span class="keywordtype">int</span> <a class="code" href="wglext_8h.html#ae6531b1788ca42a9ae8155b0c52e7630">width</a>, <span class="keywordtype">int</span> <a class="code" href="wglext_8h.html#ab2e63df950c3789599e1e43f477bc9e3">height</a>, <span class="keywordtype">int</span> bpp, <span class="keywordtype">bool</span> fullscreen) { <a name="l00024"></a>00024 <a class="code" href="_image_loader_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a> dwExStyle; <a name="l00025"></a>00025 <a class="code" href="_image_loader_8h.html#a798af1e30bc65f319c1a246cecf59e39">DWORD</a> dwStyle; <a name="l00026"></a>00026 <a name="l00027"></a>00027 m_isFullscreen = fullscreen; <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="comment">// Set up the window values.</span> <a name="l00030"></a>00030 m_windowRect.left = (long) 0; <a name="l00031"></a>00031 m_windowRect.right = (long) width; <a name="l00032"></a>00032 m_windowRect.top = (long) 0; <a name="l00033"></a>00033 m_windowRect.bottom = (long) height; <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="comment">// Set up the window class structure.</span> <a name="l00036"></a>00036 m_windowClass.cbSize = <span class="keyword">sizeof</span>(WNDCLASSEX); <a name="l00037"></a>00037 m_windowClass.style = CS_HREDRAW | CS_VREDRAW; <a name="l00038"></a>00038 m_windowClass.lpfnWndProc = <a class="code" href="class_win32_window.html#a122b796d5a3953827f20f27fe921f449">Win32Window::StaticWndProc</a>; <span class="comment">// Our static method is the event handler.</span> <a name="l00039"></a>00039 m_windowClass.cbClsExtra = 0; <a name="l00040"></a>00040 m_windowClass.cbWndExtra = 0; <a name="l00041"></a>00041 m_windowClass.hInstance = m_hinstance; <a name="l00042"></a>00042 m_windowClass.hIcon = LoadIcon(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, IDI_APPLICATION); <a name="l00043"></a>00043 m_windowClass.hCurser = LoadCursor(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, IDC_ARROW); <a name="l00044"></a>00044 m_windowClass.hbrBackground = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; <a name="l00045"></a>00045 m_windowClass.lpszMenuName = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; <a name="l00046"></a>00046 m_windowClass.lpszClassName = <span class="stringliteral">"Unuk"</span>; <a name="l00047"></a>00047 m_windowClass.hIconSm = LoadIcon(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, IDI_WINLOGO); <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="comment">// Register the window class.</span> <a name="l00050"></a>00050 <span class="keywordflow">if</span>(!RegisterClassEx(&m_windowClass)) { <a name="l00051"></a>00051 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="comment">// We need to change the display mode if we are running fullscreen.</span> <a name="l00055"></a>00055 <span class="keywordflow">if</span>(m_isFullsceen) { <a name="l00056"></a>00056 <span class="comment">// This is the device mode.</span> <a name="l00057"></a>00057 DEVMODE dmScreenSettings; <a name="l00058"></a>00058 memset(&dmScreenSettings, 0, <span class="keyword">sizeof</span>(smScreenSettings)); <a name="l00059"></a>00059 dmScreenSettings.dmSize = <span class="keyword">sizeof</span>(dmScreenSettings); <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="comment">// Set the screen width/height/bpp.</span> <a name="l00062"></a>00062 dmScreenSettings.dmPelsWidth = <a class="code" href="wglext_8h.html#ae6531b1788ca42a9ae8155b0c52e7630">width</a>; <a name="l00063"></a>00063 dmScreenSettings.dmPelsHeight = <a class="code" href="wglext_8h.html#ab2e63df950c3789599e1e43f477bc9e3">height</a>; <a name="l00064"></a>00064 dmScreenSettings.dmBitsPerPel = bpp; <a name="l00065"></a>00065 dmScreenSettings.dwFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordflow">if</span>(ChangeDisplaySettings(&dScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { <a name="l00068"></a>00068 <span class="comment">// Setting display mode failed, we will switch to windowed mode.</span> <a name="l00069"></a>00069 MessageBox(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, <span class="stringliteral">"Display mode failed"</span>, <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, MB_OK); <a name="l00070"></a>00070 m_isFullscreen = <span class="keyword">false</span>; <a name="l00071"></a>00071 } <a name="l00072"></a>00072 } <a name="l00073"></a>00073 <a name="l00074"></a>00074 <span class="comment">// Check to see if we are still in fullscreen mode.</span> <a name="l00075"></a>00075 <span class="keywordflow">if</span>(m_fullscreen) { <a name="l00076"></a>00076 dwExStyle = WS_EX_APPWINDOW; <a name="l00077"></a>00077 dwStyle = WS_POPUP; <a name="l00078"></a>00078 ShowCursor(<span class="keyword">false</span>); <a name="l00079"></a>00079 } <span class="keywordflow">else</span> { <a name="l00080"></a>00080 <span class="comment">// fullscreen mode must have failed.</span> <a name="l00081"></a>00081 dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; <a name="l00082"></a>00082 dwStyle = WS_OVERLAPPEDWINDOW <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="comment">// Adjusted the window to the requested size.</span> <a name="l00086"></a>00086 AdjustWindowRectEx(&m_windowRect, swStyle, <span class="keyword">false</span>, dwExStyle); <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="comment">// Now the class is regestered we can finaly create the window.</span> <a name="l00089"></a>00089 m_hWnd = CreateWindowEx(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, <span class="stringliteral">"Unuk"</span>, dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, <a name="l00090"></a>00090 m_windowRect.right - m_windowRect.left, m_windowRect.bottom - m_windowRect.top, <a name="l00091"></a>00091 <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, m_hinstance, <span class="keyword">this</span>); <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">// Let's make sure the window creation went as planned.</span> <a name="l00094"></a>00094 <span class="keywordflow">if</span>(!m_hWnd) <span class="keywordflow">return</span> 0; <a name="l00095"></a>00095 <a name="l00096"></a>00096 m_hdc = GetDC(m_hWnd); <a name="l00097"></a>00097 <a name="l00098"></a>00098 <span class="comment">// We know everything is ok, display and update the window now.</span> <a name="l00099"></a>00099 ShowWindow(m_hWnd, SW_SHOW); <a name="l00100"></a>00100 UpdateWindow(m_hWnd); <a name="l00101"></a>00101 <a name="l00102"></a>00102 m_lastTime = <a class="code" href="main_8cpp.html#aa17d85aacf437da3fe7e2cd86abf22c4">GetTickCount</a>() / 1000.0f; <a name="l00103"></a>00103 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00104"></a>00104 } <a name="l00105"></a>00105 <a name="l00106"></a><a class="code" href="class_win32_window.html#a6545dfce322862ad6318eb6102d59e06">00106</a> <span class="keywordtype">void</span> <a class="code" href="class_win32_window.html#a6545dfce322862ad6318eb6102d59e06">Win32Window::Destroy</a>(<span class="keywordtype">void</span>) { <a name="l00107"></a>00107 <span class="comment">// If we are in fullscreen we want to switch back to desktop, and show the mouse cursor.</span> <a name="l00108"></a>00108 <span class="keywordflow">if</span>(m_isFullscreen) { <a name="l00109"></a>00109 ChangeDisplaySettings(<a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, 0); <a name="l00110"></a>00110 ShowCursor(<span class="keyword">true</span>); <a name="l00111"></a>00111 } <a name="l00112"></a>00112 } <a name="l00113"></a>00113 <a name="l00114"></a><a class="code" href="class_win32_window.html#a53340f72e172303a30fc72161be4ac0a">00114</a> <span class="keywordtype">void</span> <a class="code" href="class_win32_window.html#a53340f72e172303a30fc72161be4ac0a">Win32Window::AttachGame</a>(<a class="code" href="class_game.html">Game</a>* game) { <a name="l00115"></a>00115 m_game = game; <a name="l00116"></a>00116 } <a name="l00117"></a>00117 <a name="l00118"></a><a class="code" href="class_win32_window.html#a881cc5d8e73332434b7596512c66b2ef">00118</a> <span class="keywordtype">bool</span> <a class="code" href="class_win32_window.html#a881cc5d8e73332434b7596512c66b2ef">Win32Window::IsRunning</a>(<span class="keywordtype">void</span>) { <a name="l00119"></a>00119 <span class="keywordflow">return</span> m_isRunning; <a name="l00120"></a>00120 } <a name="l00121"></a>00121 <a name="l00122"></a>00122 <span class="keywordtype">void</span> Win32Window::ProccessEvents(<span class="keywordtype">void</span>) { <a name="l00123"></a>00123 MSG msg; <a name="l00124"></a>00124 <a name="l00125"></a>00125 <span class="comment">// While there are messages in the queue, store them in msg.</span> <a name="l00126"></a>00126 <span class="keywordflow">while</span>(PeekMessage(&msg, <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, 0, 0, PM_REMOVE)) { <a name="l00127"></a>00127 <span class="comment">// Process the messages one at a time.</span> <a name="l00128"></a>00128 TranslateMessage(&msg); <a name="l00129"></a>00129 DispatchMessage(&msg); <a name="l00130"></a>00130 } <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <a name="l00133"></a>00133 <span class="keywordtype">void</span> Win32Window::SetupPixelFormat(<span class="keywordtype">void</span>) { <a name="l00134"></a>00134 <span class="keywordtype">int</span> pixelFormat; <a name="l00135"></a>00135 <a name="l00136"></a>00136 PIXELFORMATDESCRIPTOR pfd = { <a name="l00137"></a>00137 <span class="keyword">sizeof</span>(PIXELFORMATDESCRIPTOR), <span class="comment">// Size.</span> <a name="l00138"></a>00138 1, <span class="comment">// Version.</span> <a name="l00139"></a>00139 PFD_SUPPORT_OPENGL | <span class="comment">// OpenGL window.</span> <a name="l00140"></a>00140 PFD_DRAW_TO_WINDOW | <span class="comment">// Render to window.</span> <a name="l00141"></a>00141 PFD_DOUBLEBUFFER, <span class="comment">// Double buffer.</span> <a name="l00142"></a>00142 PFD_TYPE_RGBA, <span class="comment">// Color type.</span> <a name="l00143"></a>00143 32, <span class="comment">// Color Depth.</span> <a name="l00144"></a>00144 0, 0, 0, 0, 0, 0, <span class="comment">// Color bits (ignored).</span> <a name="l00145"></a>00145 0, <span class="comment">// No alpha buffer.</span> <a name="l00146"></a>00146 0, <span class="comment">// Alpha bits (ignored).</span> <a name="l00147"></a>00147 0, <span class="comment">// No accumulation buffer.</span> <a name="l00148"></a>00148 0, 0, 0, 0, <span class="comment">// Accumulation bits (ignored).</span> <a name="l00149"></a>00149 16, <span class="comment">// Depth buffer.</span> <a name="l00150"></a>00150 0, <span class="comment">// No stencil buffer.</span> <a name="l00151"></a>00151 0, <span class="comment">// No auxiliary buffers.</span> <a name="l00152"></a>00152 PFD_MAIN_PLANE, <span class="comment">// Main layer.</span> <a name="l00153"></a>00153 0, <span class="comment">// Reserved.</span> <a name="l00154"></a>00154 0, 0, 0, <span class="comment">// No layer, visible, damage masks.</span> <a name="l00155"></a>00155 }; <a name="l00156"></a>00156 <a name="l00157"></a>00157 pixelFormat = ChoosePixelFormat(m_hdc, &pfd); <a name="l00158"></a>00158 SetPixelFormat(m_hdc, pixelFormat, &pfd); <a name="l00159"></a>00159 } <a name="l00160"></a>00160 <a name="l00161"></a><a class="code" href="class_win32_window.html#ac17fafc962cee047adbdc883e4056544">00161</a> LRESULT <a class="code" href="class_win32_window.html#ac17fafc962cee047adbdc883e4056544">Win32Window::WndProc</a>(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { <a name="l00162"></a>00162 <span class="keywordflow">switch</span>(uMsg) { <a name="l00163"></a>00163 <span class="comment">// Create the window.</span> <a name="l00164"></a>00164 <span class="keywordflow">case</span> WM_CREATE: <a name="l00165"></a>00165 m_hdc = GetDC(hWnd); <a name="l00166"></a>00166 SetupPixelFormat(); <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="comment">// Setup the OpenGL version. We want to use 3.0.</span> <a name="l00169"></a>00169 <span class="keywordtype">int</span> attribs[] = { <a name="l00170"></a>00170 <a class="code" href="wglext_8h.html#a64d5f1fa63a1979e33aee2949f6f21ad">WGL_CONTEXT_MAJOR_VERSION_ARB</a>, 3, <a name="l00171"></a>00171 <a class="code" href="wglext_8h.html#a043b9ae0e73a1ff853339c02a3026096">WGL_CONTEXT_MINOR_VERSION_ARB</a>, 0, <a name="l00172"></a>00172 0 <a name="l00173"></a>00173 }; <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="comment">// Create a temporary context so we can get a pointer to the function.</span> <a name="l00176"></a>00176 <a class="code" href="_win32_window_8cpp.html#a3f7bf9695d032fb9ce78678b8d311901">HGLRC</a> tmpContext = wglCreateContext(m_hdc); <a name="l00177"></a>00177 <span class="comment">// Make it the current.</span> <a name="l00178"></a>00178 wglMakeCurrent(m_hdc, tmpContext); <a name="l00179"></a>00179 <a name="l00180"></a>00180 <span class="comment">// Get the function pointer.</span> <a name="l00181"></a>00181 <a class="code" href="_win32_window_8cpp.html#a7ba1e8051e394591f1b2d8ed4d44fbe8">wglCreateContextAttribsARB</a> = (PFNWGLCCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress(<span class="stringliteral">"wglCreateContextAttribsARB"</span>); <a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="comment">// If it is NULL, then GL 3.0 is not supported.</span> <a name="l00184"></a>00184 <span class="keywordflow">if</span>(!<a class="code" href="_win32_window_8cpp.html#a7ba1e8051e394591f1b2d8ed4d44fbe8">wglCreateContextAttribsARB</a>) { <a name="l00185"></a>00185 <a class="code" href="class_debug.html#ace75e2aa3105e64f9fc82c537b45135d">Debug::logger</a>-><a class="code" href="class_debug.html#a7f171818a11f4d6b8dee3b44c4d6f0a7">message</a>(<span class="stringliteral">"\nOpenGL 3.0 is not supported, falling back to GL 2.1"</span>); <a name="l00186"></a>00186 m_hglrc = tmpContext; <a name="l00187"></a>00187 } <span class="keywordflow">else</span> { <a name="l00188"></a>00188 <span class="comment">// Create an OpenGL 3.0 context using the new function.</span> <a name="l00189"></a>00189 m_hglrc = <a class="code" href="_win32_window_8cpp.html#a7ba1e8051e394591f1b2d8ed4d44fbe8">wglCreateContextAttribsARB</a>(m_hdc, 0, attribs); <a name="l00190"></a>00190 <span class="comment">// Delete then temp context.</span> <a name="l00191"></a>00191 wglDeleteContext(tmpContext); <a name="l00192"></a>00192 } <a name="l00193"></a>00193 <a name="l00194"></a>00194 <span class="comment">// Make the GL3 context current.</span> <a name="l00195"></a>00195 wglMakeCurrent(m_hdc, m_hglrc); <a name="l00196"></a>00196 <span class="comment">// Our window is now running.</span> <a name="l00197"></a>00197 m_isRunning = <span class="keyword">true</span>; <a name="l00198"></a>00198 <span class="keywordflow">break</span>; <a name="l00199"></a>00199 <span class="keywordflow">case</span> WM_DESTROY: <a name="l00200"></a>00200 <span class="keywordflow">case</span> WM_CLOSE: <a name="l00201"></a>00201 wglMakeCurrent(m_hdc, <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>); <a name="l00202"></a>00202 wglDeleteContext(m_hglrc); <a name="l00203"></a>00203 m_isRunning = <span class="keyword">false</span>; <a name="l00204"></a>00204 PostQuitMessage(0); <a name="l00205"></a>00205 <span class="keywordflow">return</span> 0; <a name="l00206"></a>00206 <span class="keywordflow">break</span>; <a name="l00207"></a>00207 <span class="keywordflow">case</span> WM_SIZE: <a name="l00208"></a>00208 <span class="comment">// Get the width and height.</span> <a name="l00209"></a>00209 <span class="keywordtype">int</span> <a class="code" href="wglext_8h.html#ab2e63df950c3789599e1e43f477bc9e3">height</a> = HIWORD(lParam); <a name="l00210"></a>00210 <span class="keywordtype">int</span> <a class="code" href="wglext_8h.html#ae6531b1788ca42a9ae8155b0c52e7630">width</a> = LOWORD(lParam); <a name="l00211"></a>00211 getAttachedExample()->onResize(width, height); <a name="l00212"></a>00212 <span class="keywordflow">break</span>; <a name="l00213"></a>00213 <span class="keywordflow">case</span> WM_KEYDOWN: <a name="l00214"></a>00214 <span class="comment">// If we detect the escape key, then please close the window.</span> <a name="l00215"></a>00215 <span class="keywordflow">if</span>(wParam == VK_ESCAPE) { <a name="l00216"></a>00216 DestroyWindow(m_hwnd); <a name="l00217"></a>00217 } <a name="l00218"></a>00218 <span class="keywordflow">break</span>; <a name="l00219"></a>00219 <span class="keywordflow">default</span>: <a name="l00220"></a>00220 <span class="keywordflow">break</span>; <a name="l00221"></a>00221 } <a name="l00222"></a>00222 <span class="keywordflow">return</span> DefWindowProc(hWnd, uMsg, wParam, lParam); <a name="l00223"></a>00223 } <a name="l00224"></a>00224 <a name="l00225"></a><a class="code" href="class_win32_window.html#a122b796d5a3953827f20f27fe921f449">00225</a> LRESULT CALLBACK <a class="code" href="class_win32_window.html#a122b796d5a3953827f20f27fe921f449">Win32Window::StaticWndProc</a>(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { <a name="l00226"></a>00226 <a class="code" href="class_win32_window.html">Win32Window</a>* window = <a class="code" href="_node_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; <a name="l00227"></a>00227 <a name="l00228"></a>00228 <span class="comment">// If we see the create message.</span> <a name="l00229"></a>00229 <span class="keywordflow">if</span>(uMsg == WM_CREATE) { <a name="l00230"></a>00230 <span class="comment">// Then get the pointer we stored during create.</span> <a name="l00231"></a>00231 window = (<a class="code" href="class_win32_window.html#aa35dcf493ad1afa40a834b99ee251042">Win32Window</a>)(LPCREATESTRUCT)lParam)->lpCreateParams; <a name="l00232"></a>00232 <span class="comment">// Associate the window pointer with the hWnd for the other events to access.</span> <a name="l00233"></a>00233 SetWindowLongPtr(hWnd, GWL_USERDAA, (LONG_PTR)window); <a name="l00234"></a>00234 } <span class="keywordflow">else</span> { <a name="l00235"></a>00235 <span class="comment">// If this aint a creation event, then we should have stored a pointer to the window.</span> <a name="l00236"></a>00236 window = (<a class="code" href="class_win32_window.html#aa35dcf493ad1afa40a834b99ee251042">Win32Window</a>)GetWindowLongPtr(hWnd, GWL_USERDATA); <a name="l00237"></a>00237 <span class="keywordflow">if</span>(!window) { <a name="l00238"></a>00238 <span class="keywordflow">return</span> DefWindowProc(hWnd, uMsg, wParam, lParam); <a name="l00239"></a>00239 } <a name="l00240"></a>00240 } <a name="l00241"></a>00241 <span class="comment">// Call our window's member WndProc (allows us to access member variables).</span> <a name="l00242"></a>00242 <span class="keywordflow">return</span> window-><a class="code" href="class_win32_window.html#ac17fafc962cee047adbdc883e4056544">WndProc</a>(hWnd, uMsg, wParam, lParam) <a name="l00243"></a>00243 } <a name="l00244"></a>00244 <a name="l00245"></a>00245 <span class="keywordtype">float</span> Win32Window::getElapsedSeconds() { <a name="l00246"></a>00246 <span class="keywordtype">float</span> currentTime = float(<a class="code" href="main_8cpp.html#aa17d85aacf437da3fe7e2cd86abf22c4">GetTickCount</a>()) / 1000.0f; <a name="l00247"></a>00247 <span class="keywordtype">float</span> seconds = float(currentTime - m_lastTime); <a name="l00248"></a>00248 m_lastTime = currentTime; <a name="l00249"></a>00249 <span class="keywordflow">return</span> seconds; <a name="l00250"></a>00250 } </pre></div></div> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="_win32_window_8cpp.html">Win32Window.cpp</a> </li> <li class="footer">Generated on Wed Nov 2 2011 23:04:26 for Unuk by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li> </ul> </div> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Defines</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> </body> </html>