Sign in to follow this  
EvilNando

Im starting to loose hair with this

Recommended Posts

EvilNando    96
i cant sleep til this compiles nicely again i was just playing with the boolean value b_mWindowed to see the effects and well when i changed it to true from false it started crashing at compile time i reverted all my changes manually but it still chrases dont know what to do
//**************************************************/
// CApplication.cpp
// Declarations for Applciation.h
// Armando Alva@2004
//**************************************************/

#include "Application.h"
#include "System.h"

// This header is so we can assign this message handler to the WNDCLASSEX structure
LRESULT WINAPI MainMessageProcedure(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

CApplication::CApplication(void)
{
	// Initiliaze all Class Members //
	
	m_bWindowed		= false;
	m_hWnd			= NULL;
	m_iWndWidth		= 800;
	m_iWndHeight	= 600;
	m_bActive		= true;
	m_bAlive		= true;	
	m_bPaused		= false;

	strcpy(m_strClass, "WindowsClass");
	strcpy(m_strTitle, "Game Program");
}

CApplication::~CApplication(void)
{
	// If our window is still there, destroy it.
    if(m_hWnd)
		DestroyWindow(m_hWnd);

    // Unregister our class, so that windows knows that
    // this CApplication is no longer valid
    UnregisterClass(m_strClass, GetModuleHandle(NULL));
}

// This Function Creates a Window //
bool CApplication::MakeWindow(int iWidth, int iHeight, bool bWindowed)
{
    WNDCLASSEX wcex;	// structure for defining the window class

	// Fill in the members

	wcex.cbClsExtra		= 0;								// extra bytes for the wcex structure
	wcex.cbSize			= sizeof(WNDCLASSEX);				// Size of this structure 
	wcex.cbWndExtra		= 0;								// Extra bytes for the window structure
	wcex.hbrBackground	= NULL;								// Window Background 
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);		// CApplication Cursor
	wcex.hIcon			= LoadIcon(NULL, IDI_APPLICATION);	// CApplication Icon (big)
	wcex.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);	// CApplication Icon (small)
	wcex.hInstance		= GetModuleHandle(NULL);			// Unique Handle Instance is assigned here
	wcex.lpfnWndProc	= MainMessageProcedure;				// This is the callback function
	wcex.lpszClassName  = m_strClass;						// The app class name
	wcex.lpszMenuName	= NULL;								// This app dosent have a menu
	wcex.style			= CS_CLASSDC;						// assign ONE DC, and share it between all
															// windows of this class.

	// Register the structure so windows knows that this app is in use.
    RegisterClassEx(&wcex);

	if(!bWindowed)
    {
        iWidth = GetSystemMetrics(SM_CXFULLSCREEN);
        iHeight = GetSystemMetrics(SM_CYFULLSCREEN);
    }

	// Creating window.... if success m_hWnd will hold the new Window handle
	m_hWnd = CreateWindow(m_strClass,		// Window Class Name
						  m_strTitle,		// Window Title
		((bWindowed)?WS_OVERLAPPEDWINDOW:WS_POPUPWINDOW),	// Window Style if its windowed or not
						  0,				// Window X Position
						  0,				// Window Y Postion
						  iWidth,			// Window Width
						  iHeight,			// Window Height
						  NULL,				// Window Parent Name
						  NULL,				// Window Menu Name
						  wcex.hInstance,	// Window Instance Handle
						  NULL);			// Window Extra Parameters

	
	// Test for a valid Handle
	if(m_hWnd == NULL)
	{
		return false;
	}

	// make sure windows ...
	ShowWindow(m_hWnd, SW_SHOW);	// - Shows our window
	UpdateWindow(m_hWnd);           // - Updates our window
	ShowCursor(TRUE);               // - Shows the cursor

	return true;
}

// This Function starts the whole CApplication processes
void CApplication::Run(void)
{
    // 1st Create the Window
	if(!MakeWindow(800, 600, true))
	{
		return;
	}

	// Call Initialize Window
	if(!FirstInitialize())
	{
		return;
	}

	// Get into the Main game Loop
	GameLoop();

	// When the loop is terminated finish the app
	FinalCleanup();
}


// Here is the Main Game Loop this will not ever be terminated 
// unless the CApplication is terminated

void CApplication::GameLoop(void)
{
	// This variable is going to store messages that the CApplication receives from windows or the user.
    MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	// While the meesage received was not a QUIT message, keep on going
	while(msg.message != WM_QUIT && m_bActive != false)
	{
		// Check to see if there is a message. If there is
        // store the message in 'msg' and remove it (PM_REMOVE)
        // from the message queue.
		// PeekMessage() returns 0 if there is no message to process
		// and a non 0 value if there is a message
		// The second parameter fo PeekMessage is the handle to our window
        // but setting it to NULL will make it check for messages from other windows
        // **THAT BELONG TO THE SAME THREAD AS THIS WINDOW**
		// The 3rd and 4th parameters are for specifying the range of windows
        // messages that you want processed. specify 0, 0 for ALL mesasages
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{			
            // TranslateMessage translates virtual-key messages into character messages
			TranslateMessage(&msg);
            // This function sends the message to our message handler.
			DispatchMessage(&msg);
		}
		else
		{
			// There was no message to process by the CApplication
			// The rendering is possible now, but first check if app is active
			if(m_bActive)
			{
				//then make sure CApplication isnt paused
				if(!m_bPaused)
				{
					// Call the PreRender function
					if(!PreRender())
					{
						break;
					}

					// Call the Render function
					if(!Render())
					{
						break;
					}
				}
			}
		}
	}
}


// Long explanation for the following code
	//**************************************************************************************//
// This is 'in the backgroud' message handler. These are the messages
// that will be handled by our app on default. If we want to add more messages
// to handle then we can put them in our derived class's message handler, 
// namely in our CGame class's message handler.
//**************************************************************************************//	

LRESULT WINAPI CApplication::MessageProcedure(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	switch(iMsg)
	{
		// Check to see if it is a WM_ACTIVATE message
	case WM_ACTIVATE:			// check the WM_ACTIVATE possibilities
		switch(wParam)
		{
		case WA_ACTIVE:			// somehow the app was activated
			m_bActive = true;	// activate the app then
			break;

		case WA_CLICKACTIVE:	// the app was activate by mouse clicking
			m_bActive = true;	// activate the app then
			break;

		case WA_INACTIVE:		// the app has lost focus
			m_bActive = false;	// deactivate everything
			break;
		}
		return 0;
		break;

	
	case WM_DESTROY:			// this is called when the window is being destroyed
		PostQuitMessage(0);
		return 0;
		break;

	
	case WM_KEYDOWN:			// when there is a keyboard press this is called
		switch(wParam)
		{
		case VK_ESCAPE:			// the ESC key was pressed
			PostQuitMessage(0);	// then quit
			break;

		case VK_PAUSE:			// the Pause key was pressed
								// if it was paused , unpause it and viceversa
			m_bPaused = !m_bPaused;
			break;
		}
		return 0;
		break;

	default:												// If the message was not on this list
		return DefWindowProc(hWnd, iMsg, wParam, lParam);	// send it to the default case
	}
}
it crashes right before here // Test for a valid Handle if(m_hWnd == NULL) { return false; } and on the debugger lpzClassName & lpszMenuName have bad pointers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this