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
|
#include "mainWnd.h"
mainWin::mainWin( HINSTANCE hInstanceParam )
{
szClassName = "mainClass";
//Handle to the main program
hInstance = hInstanceParam;
//Register window class and create window
setWndProp();
createWin();
}
void mainWin::setWndProp()
{
//Window class properties
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.style = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.hCursor = LoadCursor( hInstance, IDC_ARROW );
wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION );
wc.hIconSm = LoadIcon( hInstance, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = mWndProc;
wc.lpszClassName = szClassName;
wc.lpszMenuName = NULL;
//Throw error if class does not register
if( !RegisterClassEx( &wc ) )
throw CLASS_REG_FAIL;
}
void mainWin::createWin()
{
hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, szClassName, "Test Window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
1024, 768, NULL, NULL, hInstance, NULL );
//Throw error if window creation fails
if( hWnd == NULL )
throw WIN_CREATE_FAIL;
}
LRESULT CALLBACK mainWin::mWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_CLOSE:
DestroyWindow( hWnd );
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox( hWnd, "You Clicked on the screen", "CLICKETY CLICK", NULL );
break;
default:
return DefWindowProc( hWnd, msg, wParam, lParam );
}
return 0;
}
void mainWin::msgLoop()
{
while( GetMessage( &msg, hWnd, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
void mainWin::displayWindow()
{
ShowWindow( hWnd, SW_SHOW );
UpdateWindow( hWnd );
}
|