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
|
#include <windows.h>
#include <tchar.h>
HINSTANCE hInst;
HWND WndHandle;
int width =640;
int height = 480;
bool InitWindow(HINSTANCE hInstance,int width,int height);
LRESULT CALLBACK WndProc(HWND,UINT WPARAM,LPARAM);
int APIENTRY_tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPTSTR lpCmdline,int nCmdshow)
{
if(! InitWindow(hInstance,width,height))
{
return 0;
}
MSG msg = {0};
while(WM_QUIT != msg.message)
{
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE) == true)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
//more of the game loop;
}
}
return (int) msg.wParam;
}
bool InitWindow(HINSTANCE hInstance,int width,int height) //register window class
{
WNDCLASSEX wcex;
//set values for windows classex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectXExample");
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
RECT rect = {0,0,width,height};
AdjustWindowRect(&rect,WS_OVERLAPPEDWINDOW,FALSE);
//create window from class;
WndHandle = CreateWindow(TEXT("DirectXExample"),
TEXT("DirectXExample"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if(! WndHandle)
{
return 0;
}
ShowWindow(WndHandle,SW_SHOW);
UpdateWindow(WndHandle);
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
|