Winows pre built code issue.

So I am attempting to build a rather prehistoric snake game. These are my types..Cell,Grid, Snake, and now the introduction of a GameObject.
The task at hand was to create a game, then try our best to make it oop...So right now my goal was to use the GameObject to just show the board, and load the snake on the board. Irronically enough the program breaks in the built in method
APIENTRY _tWinMain(.........lots of stuff) I cant seem to figure out why?

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
  int APIENTRY _tWinMain(HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPTSTR    lpCmdLine,
                        int       nCmdShow)
{
   hInst = hInstance;
   //srand( (unsigned) time(NULL) ); // ctime

	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_SNAKEGAME, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SNAKEGAME));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return (int) msg.wParam;
}

this is where it breaks in the Code generated by VS2008.
This is where I load the game...
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;
}

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
GAMEOBJECT::GAMEOBJECT(HINSTANCE hInstance, HWND hWnd)
{
    myHWND = hWnd;
    myHINST = hInstance;
   //loadGame(hInstance, hWnd);
};
GAMEOBJECT::~GAMEOBJECT()
{
}
///////////////////////////////////////////////////////////
void GAMEOBJECT::loadGame(  )
{
   CELL::loadArt( myHINST );
   //Loading the inital grid
   gameObjGrid.init(myHINST,myHWND);
   //Loading the inital snake
   gameObjSnake.init( gameObjGrid.numRows() / 2, gameObjGrid.numCols() / 2 );
   SetTimer( myHWND,1,128,NULL);
}
/////////////////////////////////////////////////////////////
bool Grid::init( HINSTANCE hInst,HWND hParent ) 
{
   RECT gridRect;
   RECT rect;
   
   GetClientRect( hParent, &rect); 
   // taking the Window grid, and establising a width/height to work with
   int width =   rect.right  - rect.left;
   int height =  rect.bottom - rect.top;
   

   myCol = ( width   / ( CELL::width()  +1) )  ;
   myRow = ( (height / ( CELL::height() +1)) - 2 );
   
   // here Allocated dynmaic grid is built
   myGrid = (CELL**)new CELL*[ myRow ];
   for( int r = 0; r < myRow; r++ )
   {
      myGrid[r] = new CELL[ myCol ];
   }
  // initialize the member panel here...so set all to a 
   // agreed number or value for the array.
   // 2D array
   for( int r = 0; r < myRow; r++ )
   {
      for( int c = 0; c < myCol; c++)
      {
         CELL& currCell = myGrid[r][c];
         ;
         int xPixPos = c * ( CELL::width()  + 1 );
         int yPixPos = r * ( CELL::height() + 1 );
         currCell.create( xPixPos, yPixPos, -1, -1, hParent,hInst );
      }
   }
   myLevel = 0;
   startLevel(hInst, hParent);
   myLevel++;
   return true;
}

//----------------------------------------------------------------------------


//------------------------------------------------------------------------
bool Grid::destroy()
{
   for( int r = 0; r < myRow; r++ )
   {
      for( int c = 0; c < myCol; c++)
      {
         //CELL& currCell = myGrid[r][c];
         //TBitmapPanel& currPanel = currCell.myPanel;
         //currPanel.destroy();
        
      }
   }
for( int r = 0; r < myRow; r++ )
   {
    delete[] myGrid[r];
   }
   delete [] myGrid;

   return true;

}
/////////////////////////////////////////////////////////////////// 
I notice when I run this through the debugger, It breaks here DispatchMessage(&msg);....
Topic archived. No new replies allowed.