使用Visual C ++ 6.0的DirectX和Win32类 [英] DirectX and Win32 Classes using Visual C++ 6.0

查看:118
本文介绍了使用Visual C ++ 6.0的DirectX和Win32类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在尝试将C DirectX代码转换为C ++,以便可以自学面向对象的编程.当我编译源代码时,我得到:

Ok I am trying to convert my C DirectX code into C++ so I can teach myself object oriented programming. When I compile my source code I get:

<pre lang="msil">Deleting intermediate files and output files for project ''WinAPI - Win32 Debug''.
--------------------Configuration: WinAPI - Win32 Debug--------------------
Compiling resources...
Compiling...
Error.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing '';'' before identifier ''DXApp''
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
Main.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing '';'' before identifier ''DXApp''
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
WinApp.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing '';'' before identifier ''DXApp''
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
WinProc.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing '';'' before identifier ''DXApp''
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
DirectX.cpp
c:\practice\final\src\includes\\main.h(20) : error C2146: syntax error : missing '';'' before identifier ''DXApp''
c:\practice\final\src\includes\\main.h(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

WinAPI.exe - 10 error(s), 0 warning(s)



这使我认为某些多重包含类型错误.任何帮助将不胜感激.

main.h



Which makes me think some multiple inclusion type error. Any help would be greatly appreciated.

main.h

#ifndef main_h
#define main_h

#include <windows.h>
#include <d3d9.h>
#include "Includes//WinApp.h"
#include "Includes//DirectX.h"
#pragma comment(lib, "d3d9.lib")
//Constants
#define TITLE				"DX Tutorial"
#define SCREEN_WIDTH		800
#define SCREEN_HEIGHT		600
//Globals
extern WinApp				DXApp;
extern DirectX				DX3D;
//Function Declarations
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
bool Error(char *Message);
#endif



WinApp.h



WinApp.h

#ifndef _WINAPP_H_
#define _WINAPP_H_

#include "Includes//Main.h"
class WinApp
{
	public:
		WinApp(void);
		~WinApp(void);
		bool InitWindow(void);
		void KillWindow(void);
		inline HWND	GetWindowHandle(void){ return Wnd; }
	private:
		//  Member Variables
		HWND Wnd;
		
		//  Member Functions
		bool RegClass(void);
		bool CreateWnd(void);
};
#endif



DirectX.h



DirectX.h

#ifndef _DIRECTX_H_
#define _DIRECTX_H_

#include "Includes//Main.h"
class DirectX{
	public:
		bool Setup();
		bool Render();
		DirectX(void);
		~DirectX(void);
	private:
		LPDIRECT3D9 D3D_Object;
		LPDIRECT3DDEVICE9 D3D_Device;
		LPDIRECT3DVERTEXBUFFER9 VertexBuffer;
		LPDIRECT3DINDEXBUFFER9  IndexBuffer;
		bool Initialize_D3D();
		bool SetupMatrices();
}
#endif



main.cpp



main.cpp

#include "Includes//Main.h"
WinApp DXApp;
DirectX DX3D;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
	if(!DX3D.Setup()){
		Error( "DirectX failed to initialize!\n
				Make sure you have DirectX 9.0\n
				Available from www.microsoft.com");
		delete DX3D;
		return 0;
	}
	
	if(DXApp.InitWindow() == FALSE){
		return 0;
	}
	
	ShowWindow(DXApp.GetWindowHandle(), nCmdShow);
	
	MSG Msg;
	ZeroMemory(&Msg, sizeof(Msg));
	while(TRUE){
		while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)){
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}
     
		if(Msg.message == WM_QUIT)
        break;
		DX3D.Render();
     }
	DX3D.~DirectX();
return 0;
}



DirectX.cpp



DirectX.cpp

#include "Includes//main.h"
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
struct CUSTOM_VERTEX { float x, y, z; DWORD Color; };
DirectX::DirectX(){
}
DirectX::~DirectX(){
    D3D_Device->Release();    // close and release the 3D device
    D3D_Object->Release();    // close and release Direct3D
}
bool DirectX::Initialize_D3D(){
	D3D_Object = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
	if(!D3D_Object){
		return false;
	}
    D3DPRESENT_PARAMETERS D3Dpp;    // create a struct to hold various device information
    ZeroMemory(&D3Dpp, sizeof(D3Dpp));    // clear out the struct for use
    D3Dpp.Windowed  = TRUE;
	D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	D3Dpp.hDeviceWindow = DXApp.GetWindowHandle();
    // create a device class using this information and the info from the d3dpp stuct
    D3D_Object->CreateDevice(D3DADAPTER_DEFAULT,
							 D3DDEVTYPE_HAL,
							 DXApp.GetWindowHandle(),
							 D3DCREATE_SOFTWARE_VERTEXPROCESSING,
							 &D3Dpp,
							 &D3D_Device);
}
bool DirectX::SetupMatrices(){
}
bool DirectX::Setup(){
	return DX3D.Initialize_D3D();
}
bool DirectX::Render(){
    // clear the window to a deep blue
    D3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    D3D_Device->BeginScene();    // begins the 3D scene
    // do 3D rendering on the back buffer here
    
	D3D_Device->EndScene();    // ends the 3D scene
    D3D_Device->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}



WinApp.cpp



WinApp.cpp

#include "Includes//Main.h"
#include "Resources//Resource.h"

WinApp::WinApp(void)
{
}

bool WinApp::RegClass(void)
{
    WNDCLASSEX WindowClass;

    WindowClass.cbSize = sizeof(WNDCLASSEX);
    WindowClass.style = CS_HREDRAW | CS_VREDRAW;
    WindowClass.lpfnWndProc = WndProc;
    WindowClass.cbClsExtra = 0;
    WindowClass.cbWndExtra = 0;
    WindowClass.hInstance = GetModuleHandle(NULL);
    WindowClass.hIcon = LoadIcon(GetModuleHandle(NULL),
                                 MAKEINTRESOURCE(IDI_ICON1));
    WindowClass.hCursor = NULL;
    WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    WindowClass.lpszMenuName = NULL;
    WindowClass.lpszClassName = "ClassName";
    WindowClass.hIconSm = LoadIcon(GetModuleHandle(NULL),
                                   MAKEINTRESOURCE(IDI_ICON1));

    if(!RegisterClassEx(&WindowClass)){
        return FALSE;
    }
    return TRUE;
}

bool WinApp::CreateWnd(void){
    Wnd = CreateWindowEx( WS_EX_CLIENTEDGE, "ClassName", TITLE,
                          WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH,
                          SCREEN_HEIGHT, NULL, NULL, GetModuleHandle(NULL),
                          NULL);
    if(Wnd==NULL){
        return FALSE;
    }
    return TRUE;
}

bool WinApp::InitWindow(void){
    if(DXApp.RegClass() == FALSE){
        return Error( "Class Registration Failed!");
    }
    if(DXApp.CreateWnd() == FALSE){
        return Error("Window Creation Failed!");
    }
    return TRUE;
}

void WinApp::KillWindow(void){
    UnregisterClass("ClassName",GetModuleHandle(NULL));
}

WinApp::~WinApp(void){
    KillWindow();
}

推荐答案

您有以下形式的语句:
You have statements of the form
#include "Includes//Main.h"


我认为路径名中只能有一个"/"字符.


I think there should only be a single ''/'' character in the path name.


我唯一能找到的收费解决方案是将这两个类结合起来.如果还有其他人找到更好的方法,请让我知道我想将我的代码分隔开(或者您将其拼写).

再次感谢您查看我的情况,并感谢Richard的帮助.

--Steve
The only feesible solution I was able to find was to combine the two classes. If anyone else finds a better way PLEASE let me know I like to keep my code compartmentalized(or however you spell it).

Thanks again for taking a look at my situation and thank you Richard for your help.

--Steve


这篇关于使用Visual C ++ 6.0的DirectX和Win32类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆