Code:
#include <windows.h>
#include "resource.h"
#include "KEYS.h"
#include "Ship.h"
#include "Player.h"
#include "createmask.h"
#include "creation.h"
#include "windowvars.h"
const char g_szClassName[] = "myWindowClass";
void MainLoop(HWND hWnd) //Main Game Loop
{
RECT rcClient;
HDC hDC = GetDC(hWnd);
GetClientRect(hWnd, &rcClient);
UpdateShip(left, right, up, down);
DrawShip(hDC, &rcClient);
ReleaseDC(hWnd, hDC);
}
//Step 4: The Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
{
InitVars(*phWnd);
}
break;
case WM_KEYDOWN:
{
switch((int)wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_PAINT:
{
RECT rcClient;
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps); //main DC
GetClientRect(hWnd, &rcClient);
DrawShip(hDC, &rcClient);
EndPaint(hWnd, &ps);
}
break;
case WM_TIMER:
{
return 0;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostQuitMessage(0);
break;
case ID_STUFF_GO:
MessageBox(hWnd, "You clicked go!", "GO!", MB_OK);
break;
}
break;
case WM_DESTROY:
KillTimer(hWnd, ID_TIMER);
DeleteObject(shipmask);
DeleteObject(shipvar);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)CreateSolidBrush(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);;
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Windows Regristration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//Step 2: Creating the Window
hWnd = CreateWindowEx( WS_EX_CLIENTEDGE,
g_szClassName,
"Lee's Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
800, 600,
NULL,
NULL,
hInstance,
NULL );
if(hWnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while( TRUE )
{
if( PeekMessage( &Msg, NULL, 0, 0, PM_REMOVE ) )
{
if( Msg.message == WM_QUIT )
break;
else
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
else
{
// Check for input
if(GetAsyncKeyState(VK_LEFT)) left = true;
if(GetAsyncKeyState(VK_RIGHT)) right = true;
if(GetAsyncKeyState(VK_UP)) up = true;
if(GetAsyncKeyState(VK_DOWN)) down = true;
// Main game loop
MainLoop(*phWnd);
}
}
return Msg.wParam;
}