useDirectMusic.rar

  • PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 43KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 4
    下载次数
  • 2006-07-05 08:02
    上传日期
代码实现如何创建和使用自己的DirectMusic工具。
useDirectMusic.rar
  • 实例二
  • MusicTool.dsp
    4.9KB
  • MusicTool.rc
    3.1KB
  • musictool.cpp
    19.1KB
  • _desktop.ini
    8B
  • MusicTool.opt
    76KB
  • meastool.h
    1.1KB
  • meastool.cpp
    7.8KB
  • echotool.cpp
    8.1KB
  • musictool.gif
    2.5KB
  • MusicTool.vcproj
    4.8KB
  • MusicTool.sln
    918B
  • MusicTool.dsw
    541B
  • MusicTool.plg
    2.1KB
  • MusicTool.positions
    318B
  • resource.h
    677B
  • MusicTool.suo
    3.5KB
  • echotool.h
    1.1KB
  • MusicTool.ncb
    89KB
  • www.pudn.com.txt
    218B
内容介绍
//----------------------------------------------------------------------------- // 文件名: MusicTool.cpp // // 描 述: 使用DirectMusic,播放主片段 //----------------------------------------------------------------------------- #define STRICT #include <windows.h> #include <basetsd.h> #include <commdlg.h> #include <commctrl.h> #include <dmusicc.h> #include <dmusici.h> #include <dmusicf.h> #include <dxerr9.h> #include <cguid.h> #include <tchar.h> #include <stdio.h> #include "resource.h" #include "DMUtil.h" #include "DXUtil.h" #include "EchoTool.h" #include "MeasTool.h" INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ); HRESULT OnInitDialog( HWND hDlg ); HRESULT ProcessDirectMusicMessages( HWND hDlg ); VOID OnOpenSoundFile( HWND hDlg ); HRESULT LoadSegmentFile( HWND hDlg, TCHAR* strFileName ); HRESULT OnPlaySegment( HWND hDlg ); VOID EnablePlayUI( HWND hDlg, BOOL bEnable ); HRESULT OnChangeTool( HWND hDlg ); HINSTANCE g_hInst = NULL; CMusicManager* g_pMusicManager = NULL; CMusicSegment* g_pMusicSegment = NULL; CEchoTool* g_pEchoTool = NULL; CMeasureTool* g_pMeasureTool1 = NULL; CMeasureTool* g_pMeasureTool2 = NULL; IDirectMusicTool* g_pCurrentTool = NULL; IDirectMusicGraph* g_pGraph = NULL; HANDLE g_hDMusicMessageEvent = NULL; //----------------------------------------------------------------------------- // 函数名: WinMain() // 描 述: 应用程序的入口。使用简单的对话框与用户交互 //----------------------------------------------------------------------------- INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow ) { HWND hDlg = NULL; BOOL bDone = FALSE; int nExitCode = 0; HRESULT hr; DWORD dwResult; MSG msg; g_hInst = hInst; // 显示主对话框。 hDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc ); while( !bDone ) { dwResult = MsgWaitForMultipleObjects( 1, &g_hDMusicMessageEvent, FALSE, INFINITE, QS_ALLEVENTS ); switch( dwResult ) { case WAIT_OBJECT_0 + 0: // 发信号给g_hDPMessageEvent,因此有可用的messages消息。 if( FAILED( hr = ProcessDirectMusicMessages( hDlg ) ) ) { DXTRACE_ERR_MSGBOX( TEXT("ProcessDirectMusicMessages"), hr ); return FALSE; } break; case WAIT_OBJECT_0 + 1: // Windows消息可用。 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { if( !IsDialogMessage( hDlg, &msg ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } if( msg.message == WM_QUIT ) { nExitCode = (int)msg.wParam; bDone = TRUE; DestroyWindow( hDlg ); } } break; } } return nExitCode; } //----------------------------------------------------------------------------- // 函数名: MainDlgProc() // 描 述: 处理对话框消息 //----------------------------------------------------------------------------- INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { HRESULT hr; switch( msg ) { case WM_INITDIALOG: if( FAILED( hr = OnInitDialog( hDlg ) ) ) { DXTRACE_ERR_MSGBOX( TEXT("OnInitDialog"), hr ); MessageBox( hDlg, "Error initializing DirectMusic. Sample will now exit.", "DirectMusic Sample", MB_OK | MB_ICONERROR ); PostQuitMessage( IDABORT ); return FALSE; } break; case WM_COMMAND: switch( LOWORD(wParam) ) { case IDC_SOUNDFILE: OnOpenSoundFile( hDlg ); break; case IDCANCEL: PostQuitMessage( IDCANCEL ); break; case IDC_PLAY: if( FAILED( hr = OnPlaySegment( hDlg ) ) ) { DXTRACE_ERR_MSGBOX( TEXT("OnPlaySegment"), hr ); MessageBox( hDlg, "Error playing DirectMusic segment. " "Sample will now exit.", "DirectMusic Sample", MB_OK | MB_ICONERROR ); PostQuitMessage( IDABORT ); } break; case IDC_STOP: // 播放片段时,简单调用Stop()不会停止任何MIDI sustain pedals, // 但调用StopAll()可以。 if( g_pMusicManager ) g_pMusicManager->StopAll(); EnablePlayUI( hDlg, TRUE ); break; case IDC_TOOL_COMBO: OnChangeTool( hDlg ); break; case IDHELP: DXUtil_LaunchReadme( hDlg ); break; default: // 不处理消息 return FALSE; } break; case WM_DESTROY: // 清除一切 SAFE_RELEASE( g_pGraph ); SAFE_DELETE( g_pMusicSegment ); SAFE_DELETE( g_pMusicManager ); SAFE_DELETE( g_pEchoTool ); SAFE_DELETE( g_pMeasureTool1 ); SAFE_DELETE( g_pMeasureTool2 ); CloseHandle( g_hDMusicMessageEvent ); break; default: // 不处理消息 return FALSE; } return TRUE; } //----------------------------------------------------------------------------- // 函数名: OnInitDialog() // 描 述: 初始化对话框(建立UI控制等) //----------------------------------------------------------------------------- HRESULT OnInitDialog( HWND hDlg ) { HRESULT hr; LONG lIndex; // 为对话框设置icon HICON hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) ); SendMessage( hDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon ); // 设置大icon SendMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon ); // 设置小icon g_hDMusicMessageEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); g_pMusicManager = new CMusicManager(); if( NULL == g_pMusicManager ) return E_OUTOFMEMORY; // 使用缺省音轨初始化DirectMusic hr = g_pMusicManager->Initialize( hDlg ); if( FAILED(hr) ) return DXTRACE_ERR_MSGBOX( TEXT("Initialize"), hr ); IDirectMusicPerformance8* pPerformance = g_pMusicManager->GetPerformance(); IDirectMusicAudioPath8* pDefaultAudioPath = g_pMusicManager->GetDefaultAudioPath(); // 产生一个DirectMusicGraph,并告知相关的参数 hr = pDefaultAudioPath->GetObjectInPath( 0, DMUS_PATH_PERFORMANCE_GRAPH, 0, GUID_NULL, 0, IID_IDirectMusicGraph, (LPVOID*) &g_pGraph ); SAFE_RELEASE( pDefaultAudioPath ); if( FAILED( hr ) ) return DXTRACE_ERR_MSGBOX( TEXT("GetObjectInPath"), hr ); // 注册片段通知 if( FAILED( hr = pPerformance->AddNotificationType( GUID_NOTIFICATION_SEGMENT ) ) ) return DXTRACE_ERR_MSGBOX( TEXT("AddNotificationType"), hr ); if( FAILED( hr = pPerformanc
评论
    相关推荐