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

📄 ch4p3_searchdir.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// Ch4p3_SearchDir.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <mmreg.h>

#include "dsound.h"
#include "dxerr8.h"
#include "AudioEngine/dxutil.h"
#include "AudioEngine/AudioEngine.h"

#include <shlobj.h> // for SHGetSpecialFolderPath

using namespace std;
using namespace AudioEngine;

CAudioManager g_AudioMgr;

void Exit(int errorcode)
{
  #ifdef _DEBUG
  cout << endl << endl << "(Program ended, press a key to exit.)";
  // so that the console window doesn't disappear before we have
  // a chance to look at it.
  getch(); 
#endif

  exit(errorcode);
}

HWND GetConsoleWindowHandle()
{
  char title[512];
  HWND hWnd;
 
  GetConsoleTitle(title, sizeof(title));
  hWnd = FindWindow(NULL, title);
  return(hWnd);
}

void main(int argc, char* argv[])
{
  
  try {

    // initialize audio manager
    cout << "Initializing Audio Manager..." << endl;
    g_AudioMgr.Init(GetConsoleWindowHandle());

    // get path to user's desktop
    char desktop[MAX_PATH];
    SHGetSpecialFolderPath(GetConsoleWindowHandle(), desktop, CSIDL_DESKTOPDIRECTORY, false);
    cout << "Desktop Path: " << desktop << endl;

    cout << "Make sure test.wav is on your desktop, then press a key." << endl;

    getch();                                                
    // load a WAV file
    cout << "Loading WAV File..." << endl;
    g_AudioMgr.SetSearchDirectory(desktop);
    CSoundPtr snd = g_AudioMgr.LoadSound("test.wav");
    
    cout << "Playing..." << endl;
    snd->Play();

    // wait until it's finished
    Sleep(500);
    while (snd->IsPlaying()) Sleep(500);

    // uninit audio manager
    cout << "UnIniting audio manager..." << endl;
    g_AudioMgr.UnInit();
  } 
  catch(CError &e) {
    MessageBox(GetConsoleWindowHandle(), e.GetMessageBoxString().c_str(), "Ch4p3_SearchDir", MB_ICONSTOP);
    Exit(-1);
  }
  catch(...) {
    MessageBox(GetConsoleWindowHandle(), "This sample program has encountered an error and must close.", "Ch4p3_SearchDir", MB_ICONSTOP);
    Exit(-1);
  }
  Exit(0);
}

⌨️ 快捷键说明

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