1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#include "RenderWindow.h"
#include "BuildConfig.h"
/*=================================================
Global Variables.
=================================================*/
RenderWindow *MyRenderWindow = NULL;
/*=================================================
bool RenderWindow::SetupRenderWindow(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd, UINT Style, LPCTSTR lpszClassName)
----------------
Set up a render window. Set all of the settings
and get it ready to be created and shown.
=================================================*/
bool RenderWindow::SetupRenderWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd, WNDPROC msgproc, UINT Style, LPCTSTR lpszClassName)
{
hInstMain = NULL;
hPrevInst = NULL;
hWndMain = NULL;
hInstMain = hInstance;
hPrevInst = hPrevInstance;
RightClick = false;
LeftClick = false;
RenderWindow::lpClassName = lpszClassName;
ZeroMemory(&wcx, sizeof(WNDCLASSEX));
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = Style;
//If this build option has been defind in the options use the msg
//proc that is passed into the function. Otherwise use the default one.
#if defined(OVERRIDE_DFLT_MSG_PROC)
wcx.lpfnWndProc = msgproc;
#else
wcx.lpfnWndProc = MyWindowProc;
#endif
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;//window extra
wcx.hInstance = hInstMain;//application handle
wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION);//icon
wcx.hCursor = LoadCursor(NULL,IDC_ARROW);//cursor
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);//background color
wcx.lpszMenuName = NULL;//menu
wcx.lpszClassName = lpszClassName;//class name
wcx.hIconSm = NULL;//small icon
//register the window class, return 0 if not successful
if(!RegisterClassEx(&wcx)) return(false);
MyRenderWindow = this;
return true;
}
/*=================================================
bool RenderWindow::CreateRenderWindow(DWORD dwStyle,
LPCTSTR lpWindowName, int iWidth, int iHeight)
----------------
Take the window creation paramters and create
a render window.
=================================================*/
bool RenderWindow::CreateRenderWindow(DWORD dwStyle, LPCTSTR lpWindowName, int iWidth, int iHeight)
{
RenderWindow::hWndMain = CreateWindowEx(NULL,
RenderWindow::lpClassName,
lpWindowName,
dwStyle,
0, 0, iWidth, iHeight,
NULL,
NULL,
hInstMain,
NULL);
if(!RenderWindow::hWndMain) return false;
return true;
}
/*=================================================
HWND RenderWindow::ExposeHandle()
----------------
Expose the private window handle
=================================================*/
HWND RenderWindow::ExposeHandle()
{
return(hWndMain);
}
/*=================================================
LRESULT CALLBACK RenderWindow::MyWindowProc(
HWND hWndMain, UINT uMsg, WPARAM wParam,
LPARAM lParam)
----------------
The default message proc for the render window
system.
=================================================*/
LRESULT CALLBACK RenderWindow::MyWindowProc(HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_LBUTTONUP:
{
MyRenderWindow->LeftClick = true;
}break;
//case WM_RBUTTONDOWN:
//{
// MyRenderWindow->RightClick = true;
//}break;
case WM_RBUTTONUP:
{
MyRenderWindow->RightClick = true;
}break;
case WM_CHAR:
{
MyRenderWindow->LastKeyPress = wParam;
MyRenderWindow->KeyPressed = true;
}break;
case WM_KEYDOWN:
{
}break;
case WM_DESTROY://the window is being destroyed
{
PostQuitMessage(0);//tell the application we are quitting
}break;
case WM_PAINT://the window needs repainting
{
//PAINTSTRUCT ps;//a variable needed for painting information
//HDC hdc = BeginPaint(hWndMain, &ps);//start painting
//EndPaint(hWndMain, &ps);//end painting
}break;
}
return(DefWindowProc(hWndMain,uMsg,wParam,lParam));
}
|