• 0

C++ / DirectX 9: Visual Studio Setup


Question

This is strange. I'm trying to get back into C++ (well, Direct3D 9.0c writing). I've forgotten how to set up a simple project.

1.) Install DirectX 9.0b SDK

2.) Install DirectX 9.0c SDK - October 2005 Update

3.) Install Visual Studio .NET 2003 (7.0)

1.) Open Visual Studio .NET 2003 (7.0)

2.) Tools > Options > Projects Folder > VC++ Directories

3.) Library files - add: "C:\DXSDK\Lib"

Now I'm stuck. Basically, I wanna' learn to create a 3D FPS game like UT2004 / Half Life 2 (yes, yes, I'll never get that advanced...but still). Using C++ and DirectX 9.0c.

I'm going through this Intro to 3D Prog. w/DX 9.0 book and I'm supposed to add "d3d9.lib d3dx9.lib winmm.lib" to the project. However, there are so many different types of projects etc. I want to be able to add the following piece of code that came with the book and compile/run it (removed the comments to shrink the size of this post). I don't pretend to understand it, but it would be nice to see a result. I intend to touch up on C++ but as long as I can get these code examples working, I would then better understand the topic.

#include <windows.h>

HWND MainWindowHandle = 0; 

bool InitWindowsApp(HINSTANCE instanceHandle, int show); 

int  Run();			   

LRESULT CALLBACK WndProc(HWND hWnd,
						 UINT msg,
						 WPARAM wParam,
						 LPARAM lParam); 

int WINAPI WinMain(HINSTANCE hInstance,  
				   HINSTANCE hPrevInstance, 
				   PSTR	  pCmdLine, 
				   int	   nShowCmd)
{
	if(!InitWindowsApp(hInstance, nShowCmd)) 
	{
		::MessageBox(0, "Init - Failed", "Error", MB_OK);
		return 0;
	}
	return Run(); // enter message loop
}

bool InitWindowsApp(HINSTANCE instanceHandle, int show)
{
	WNDCLASS wc; 

	wc.style		 = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra	= 0;
	wc.cbWndExtra	= 0;
	wc.hInstance	 = instanceHandle;
	wc.hIcon		 = ::LoadIcon(0, IDI_APPLICATION);
	wc.hCursor	   = ::LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = 
	static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "Hello";

	if(!::RegisterClass(&wc)) 
	{
		::MessageBox(0, "RegisterClass - Failed", 0, 0);
		return false;
	}

	MainWindowHandle = ::CreateWindow(
						   "Hello",
						   "Hello",
						   WS_OVERLAPPEDWINDOW,
						   CW_USEDEFAULT, 
						   CW_USEDEFAULT,
						   CW_USEDEFAULT,
						   CW_USEDEFAULT,
						   0,
						   0, 
						   instanceHandle,
						   0);

	if(MainWindowHandle == 0)
	{
		::MessageBox(0, "CreateWindow - Failed", 0, 0);
		return false;
	}

	::ShowWindow(MainWindowHandle, show);
	::UpdateWindow(MainWindowHandle);

	return true;
}

int Run()
{
	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

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

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND   windowHandle,
						 UINT   msg,	 
						 WPARAM wParam,
						 LPARAM lParam)
{
	switch( msg )
	{
	case WM_LBUTTONDOWN:
		::MessageBox(0, "Hello, World", "Hello", MB_OK);
		return 0;

	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(MainWindowHandle);
		return 0;

	case WM_DESTROY: 
		::PostQuitMessage(0); 
		return 0;
	}
	return ::DefWindowProc(windowHandle,
						   msg,
						   wParam,
						   lParam);
}

Any ideas on how I can accomplish this - every attempt results in error messages while building :(

Thanks in advance.

Link to comment
https://www.neowin.net/forum/topic/406186-c-directx-9-visual-studio-setup/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You need to create a Win32 application.

File->New->Project... Select the Win32 Project, name it, and click OK. In the Application Settings tab, select Empty Project.

Add a new C++ file(.cpp) to your Source folder in the Solution Explorer. Copy and paste your code into the file. Ctl-Shift-B to build, and F5 to debug, or Ctl-F5 to run without debugging.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.