Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Sir_Spritely

Simple basic window problem - Please Help

This topic is 5853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using the M.S DX SDK example and trying to split it into a more suitable OO format rather than one file. The code compiles with no errors but will not bring up the window. I can only presume I''m missing the big picture when seperating the bits and peices. If anyone could take a quick look and let me know what I''m doing wrong it would be a big help, my code: - File OS.cpp
  
//---------------------------------------------------------------------------------------------

// Name: OS.cpp

//

// Desc: Contains the actual code for both WinMain and the message handler, creates an

//       instance of the application object.

//

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

#include "stdafx.h"
#include "OS.h"
#include "Version.h"



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

// Name: WinMain()

// Desc: The applications entry point.

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

INT WINAPI WinMain ( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
			          GetModuleHandle (NULL), NULL, NULL, NULL, NULL,
					  "Game Window", NULL };
	RegisterClassEx ( &wc );

	HWND hWnd = CreateWindow ( "Game Window", "Game Window", 
		                       WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
							   GetDesktopWindow(), NULL, wc.hInstance, NULL );
}



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

// Name: MsgProc()

// Desc: The windows message handler

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

LRESULT WINAPI MsgProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch ( msg )
	{
	case WM_DESTROY:
		PostQuitMessage( 0 );
		return 0;

	case WM_PAINT:
		// This will be put in when D3D is implemented.

		//Render();

		ValidateRect ( hWnd, NULL );
		return 0;
	}

	return DefWindowProc ( hWnd, msg, wParam, lParam );
}
  
File OS.h
  
//---------------------------------------------------------------------------------------------

// File: OS.h

//

// Desc: This header file will hold all the prototypes for the functions which are used by

//       the OS to communicate with this application.  It defines the code called by the OS.

//

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

#include <windows.h>

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

// Name: WinMain()

// Desc: Prototype for the WinMain function, called by the OS to start the application.

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

INT WINAPI WinMain ( HINSTANCE hInst, HINSTANCE, LPSTR, INT );


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

// Name: MsgProc()

// Desc: Prototype for the EntryMessageHandler function which is called everytime a message

//       has to be sent to the application by the OS.

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

LRESULT WINAPI MsgProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
  
File Version.cpp
  
//---------------------------------------------------------------------------------------------

// File: Version.cpp

//

// Desc: Creates a basic window application.

//

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

#include "stdafx.h"
#include "OS.h"
#include "Version.h"


Application::Application()
{
	m_WindowWidth = 640;
	m_WindowHeight = 480;
}



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

// Name: StartProc()

// Desc: Creates the window and starts pumping messages through the application.  when the app

//       recieves a quit message this functions returns and the app quits.

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

void Application::StartProc()
{
	ShowWindow ( hWnd, SW_SHOWDEFAULT );
	UpdateWindow ( hWnd );

	MSG msg;
	while ( GetMessage ( &msg, NULL, 0, 0 ) )
	{
		TranslateMessage( &msg );
		DispatchMessage ( &msg );
	}
}



Application::~Application()
{
	if (hWnd)
		DestroyWindow ( hWnd );
}
  
File Version.h (This is the last one)
  
//---------------------------------------------------------------------------------------------

// File: Version.h

//

// Desc: This header file contains the class definitions for the application class.

//

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

#include <d3d8.h>

class Application
{
public:
	Application();
	virtual ~Application();
	void StartProc();

protected:
	HWND hWnd;
	long m_WindowWidth;
	long m_WindowHeight;
};
  

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you don''t create an Application object, so you don''t end up running updateWindow and showWindow

Share this post


Link to post
Share on other sites
Your WinMain will just exit.. you create the window and then leave.. your Application object doesn''t get created and isn''t attached to your window anyway.. did you copy this code from somewhere?

Share this post


Link to post
Share on other sites
Like I said I am using the code from the M.S DX8.1 example, CreateDevice.cpp.

It''s all in one file and I''m trying to split up to give it a more OO feel. I also find it easier than having one huge pile of code to stare at for hours on end.

Share this post


Link to post
Share on other sites
Maybe it is a bit complicated... How about this: Have a look at http://www.mvps.org/directx/articles/simpledx8frame.htm

Robert Dunlop was kind enough to offer us a very minimalist (yet pleasantly functional) DX8 startup engine.

To just create your DX8 window, it''s the friendliest I''ve found.

^o.o^ Leaders and teachers should remember: It is best to offer others what they Need not what they Want.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!