Hi
I'm a begining C++ programer. I'm working from a book called Beginning Game Programing by Johnathan Harbour. I'm up to using the DirectX API. I have the latest Direct X SDK, the book was written with 9.0b and beyond in mind. Im using Visual C++ 6.
The program is meant to have a black background (windowed at 640 x 480) and have a sprite of a cat walking. All that happens is that the screen flicks up and then disapears. Its not meant to do this. I will go back and check for a return 0 instead of something else in my code but i dont think that is the problem...
This is the code of my WinMain...
Code:
// Beging Game Programing
// Chapter 7
// winmain.cpp -- windows code framework
// header files
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>
#include <stdio.h>
#include "dxgraphics.h"
#include "game.h"
//windows event call back function
LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch ( msg )
{
case WM_DESTROY:
//release the direct 3d device
if (d3ddev != NULL)
d3ddev->Release();
//release the direct 3d object
if (d3d != NULL)
d3d->Release();
//call the 'front end' shut-down function
Game_End(hWnd);
// tell windows to kill this program
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam);
}
//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
//fill the struct with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;
//set up the window with the class info
return RegisterClassEx(&wc);
}
//entry point for a windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd;
//Register the class
MyRegisterClass(hInstance);
//set up the screen in windowed or full-screen mode?
DWORD style;
if (FULLSCREEN)
style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;
else
style = WS_OVERLAPPED;
//Create new window
hWnd = CreateWindow(
APPTITLE, //window class
APPTITLE, //title bar
style, //window style
CW_USEDEFAULT, //x position of window
CW_USEDEFAULT, //y position of window
SCREEN_WIDTH, //width of the window
SCREEN_HEIGHT, //height of the window
NULL, //parent window
NULL, //menu
hInstance, //application instance
NULL); //window parameters
//Was there an error creating the window?
if (!hWnd)
return false;
//display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if (!Init_Direct3D(hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, FULLSCREEN))
{
MessageBox(hWnd, "Error initializing Direct 3D", "Error", MB_OK);
return 0;
}
//initalize the game
if (!Game_Init(hWnd))
{
MessageBox(hWnd, "Error initializing the game", "Error", MB_OK);
return 0;
}
//main message loop
int done = 0;
while (!done)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//look for quit message
if (msg.message == WM_QUIT)
done = 1;
//decode and pass messages on to WndProc
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
//process game loop ('else' prevents running after close)
Game_Run(hWnd);
return 0;
}
return msg.wParam;
}
The one line that has a warning is
return msg.wParam, just at the end. It says...
warning C4700: local variable 'msg' used without having been initialized
This is the only warning/error in my entire program and it doesnt work. I can post the other files if need be, but i think it is this one line.
Any help would be appreciated, will go and check for other errors manualy now.
Cheers
Manaxter