• 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.
  • Posts

    • https://youtu.be/QvsuYWvtlmw?t=46
    • Teams immersive sounds like a really fun 3D experience by Usama Jawad Microsoft Teams is heavily used in enterprise environments, especially where customers are well entrenched in Redmond's ecosystem. As such, it is imperative for Microsoft to regularly add new features to Teams to retain its existing customers while also attracting new ones. Now, the firm has announced immersive 3D virtual events for the communication and collaboration software. Teams immersive is basically a custom 3D environment that enables attendees and organizers to interact with each other in a more natural way. Managing and planning an immersive event is as easy as scheduling a regular Teams meeting as you can do so directly via the Teams calendar UX. The process to set up Teams immersive appears to be quite intuitive and, well, fun. You can add 3D models, logos, images, text, and video to the environment to customize it according to your preferences using the Editor utility, without knowing any coding language. But if that sounds too hectic, you can also leverage the existing templates from Microsoft. Teams immersive aims to make virtual events more interacting and engaging. Organizers can shine a spotlight on their avatar when they start an event, bring virtual attendees to the stage during the Q&A session, find a specific attendee, and see the crowd's reactions as you move between rooms like an actual host. Teams immersive also empowers more natural experiences through spatial audio, with people also having the ability to listen to someone better by just moving closer to them virtually. This could be very useful in large events, for example, virtual conferences or an all-hands meeting hosted in 3D on Teams. That said, it is important to note that Teams immersive is currently in public preview and requires the rather expensive Teams Premium add-on license, which costs a hefty $10 per user per month for an organization.
  • Recent Achievements

    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      656
    2. 2
      ATLien_0
      254
    3. 3
      Xenon
      167
    4. 4
      neufuse
      146
    5. 5
      +FloatingFatMan
      121
  • Tell a friend

    Love Neowin? Tell a friend!