⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsobj.h

📁 经典飞机游戏的源代码 dx实现
💻 H
字号:
#ifndef DSOBJ_H
#define DSOBJ_H

#include <windows.h>
#include "wave.h"
#include <dsound.h>

typedef struct DsBuffer_Info
{
	LPDIRECTSOUNDBUFFER lpDSBuffer;
	DWORD dwWaveSize;
	LPSTR szFileName;
	WAVEFORMATEX * lpWFmtEX;
	char * lpWaveData;
} DSBUF_INFO;

class CDSObj
{
public:
	// CDSObj()
	//		- default constructor, initialize all the member
	// INPUT: none;
	// OUTPUT: none;
	CDSObj();

	// ~CDSObj()
	//		- destructor, destroy all the memor we allocated
	// INPUT: none;
	// OUTPUT: none;
	~CDSObj();

	// Initialize()
	//		- construct DirectSound object and set the correct cooperative level
	// INPUT: HWND object - the application window object.
	// OUTPUT: none;
	BOOL Initialize(HWND hwnd);

	// Terminate()
	//		- terminate DirectSound object and all the buffers we allocated.
	// INPUT: none;
	// OUTPUT: none;
	void Terminate();

	// DestroySoundBuffer()
	//		- destroy a sound buffer with index num.
	// INTPUT: num - the index of DSBufStack array.
	// OUTPUT: none;
	void DestroySoundBuffer(int num);

	// GetSoundFromFile
	//		- Get sound data from a file.
	// INPUT: 1. fn - the name of the file.
	//        2. num - the index.
	// OUTPUT: TRUE if this operation success, FALSE otherwise.
	BOOL GetSoundDataFromFile(LPSTR fn, int num);
	
	// CreateBuffer
	//		-create buffer with specified index.
	//      * remember one thing: call GetSoundDataFrom() first.
	// INPUT: num - the index.
	// OUTPUT: TRUE if this operation success, FALSE otherwise.
	BOOL CreateBuffer(int num);
	
	// LoadDataToBuffer
	//		- After create the sound buffer, load data to buffer.
	//		* remember one thing: call CreateBuffer() first.
	// INPUT: num - the index.
	// OUTPUT: TRUE if this operation success, FALSE otherwise.
	BOOL LoadDataToBuffer(int num);

	// SetSoundTrack()
	//		-load a valid sound file into specified dsound buffer.
	//		* This method:
	//			1. GetSoundDataFromFile()
	//			2. CreateBuffer()
	//			3. LoadSoundDataToBuffer().
	// INPUT: 1. fn - the name of the file.
	//        2. num - the index.
	// OUTPUT: TRUE if this operation success, FALSE otherwise.
	BOOL SetSoundTrack(LPSTR fn, int num);

	// PlaySound()
	//		- play the sound in the specified sound buffer with index num.
	// INPUT: 1. loop - specify loop the sound. 
	//        2. num - the index.
	// OUTPUT: TRUE if this operation success, FALSE otherwise.
	BOOL PlaySound(BOOL loop, int num);
	
	// StopSound()
	//		-stop the sound in a specified sound buffer with index num.
	// INPUT: num - the index.
	// OUTPUT: none;
	void StopSound(int num);

	// IsStackFull()
	//		-check if the array is full, and all buffer used.
	// INPUT: none;
	// OUTPUT: TRUE or FALSE
	BOOL IsStackFull()
	{return size == 50;}

	// IsIndexValid()
	//		- check if the index num is valid.
	// INPUT: num - the index
	// OUTPUT: TRUE or FALSE
	BOOL IsIndexValid(int num)
	{return (num >= 0 && num < 50);}

	// IsBufferExisting?
	//		- does buffer exist? Have we allocate memory for this buffer.
	// INPUT: num - the index
	// OUTPUT: TRUE or FALSE
	BOOL IsBufferExisting(int num)
	{
		if(IsIndexValid(num))
		{
			if(DSBufStack[num].lpDSBuffer != NULL)
				return TRUE;
		}
		return FALSE;
	}

private:
	LPDIRECTSOUND lpDS;
	DSBUF_INFO    DSBufStack[50];
	int size;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -