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
|
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
//////// you can see here I am trying to play with the object, because
/////// I do require hand to Instance and window...
GAMEOBJECT gObject(hInst,hWnd);
// loadGame(hInst,hWnd);
//gObject(hInst,hWnd);
gObject.loadGame( );
//ShowWindow(hWnd, nCmdShow);
//UpdateWindow(hWnd);
return TRUE;
}
///////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// return onCommand( hWnd, message, wParam, lParam );
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_SIZE:
// wparam = flag ==>> tell us weither maxiumize or minimize
if(true)
{
//// LO and HI gives us the windows height and width
//int width = LOWORD( lParam );
//int nCellColumns = ( width / (CELL::width() + 1) );
//int height = HIWORD( lParam );
//int nCellRow = ( height / (CELL::height() +1) );
//testGrid.init(hInst, hWnd,nCellRow, nCellColumns );
//testGrid.myGrid[(nCellRow/2)][(nCellColumns/2)].myPanel.setBitmap(CELL::hbSnakeHead);
}
break;
case WM_CHAR:
if( wParam == 'w')
{
}
break;
case WM_KEYDOWN:
// I have this part already done ... handleKeyStroke(wParam);
if(true)
{
if( isDirectionKey(wParam) )
{
gameSnake.dir = (Direction) wParam;
}
}
break;
case WM_KEYUP:
//handleKeyStroke(wParam);
break;
case WM_TIMER:
gObject.gameRun();
//gameRun();
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
|