musictool.cpp
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:19k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. // 文件名: MusicTool.cpp
  3. //
  4. // 描  述: 使用DirectMusic,播放主片段
  5. //-----------------------------------------------------------------------------
  6. #define STRICT
  7. #include <windows.h>
  8. #include <basetsd.h>
  9. #include <commdlg.h>
  10. #include <commctrl.h>
  11. #include <dmusicc.h>
  12. #include <dmusici.h>
  13. #include <dmusicf.h>
  14. #include <dxerr9.h>
  15. #include <cguid.h>
  16. #include <tchar.h>
  17. #include <stdio.h>
  18. #include "resource.h"
  19. #include "DMUtil.h"
  20. #include "DXUtil.h"
  21. #include "EchoTool.h"
  22. #include "MeasTool.h"
  23. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
  24. HRESULT OnInitDialog( HWND hDlg );
  25. HRESULT ProcessDirectMusicMessages( HWND hDlg );
  26. VOID    OnOpenSoundFile( HWND hDlg );
  27. HRESULT LoadSegmentFile( HWND hDlg, TCHAR* strFileName );
  28. HRESULT OnPlaySegment( HWND hDlg );
  29. VOID    EnablePlayUI( HWND hDlg, BOOL bEnable );
  30. HRESULT OnChangeTool( HWND hDlg );
  31. HINSTANCE               g_hInst                 = NULL;
  32. CMusicManager*          g_pMusicManager         = NULL;
  33. CMusicSegment*          g_pMusicSegment         = NULL;
  34. CEchoTool*              g_pEchoTool             = NULL;
  35. CMeasureTool*           g_pMeasureTool1         = NULL;
  36. CMeasureTool*           g_pMeasureTool2         = NULL;
  37. IDirectMusicTool*       g_pCurrentTool          = NULL;
  38. IDirectMusicGraph*      g_pGraph                = NULL;
  39. HANDLE                  g_hDMusicMessageEvent   = NULL;
  40. //-----------------------------------------------------------------------------
  41. // 函数名: WinMain()
  42. // 描  述: 应用程序的入口。使用简单的对话框与用户交互 
  43. //-----------------------------------------------------------------------------
  44. INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, 
  45.                       INT nCmdShow )
  46. {
  47.     HWND    hDlg = NULL;
  48.     BOOL    bDone = FALSE;
  49.     int     nExitCode = 0;
  50.     HRESULT hr; 
  51.     DWORD   dwResult;
  52.     MSG     msg;
  53.     g_hInst = hInst;
  54.     // 显示主对话框。
  55.     hDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_MAIN), 
  56.                          NULL, MainDlgProc );
  57.     while( !bDone ) 
  58.     { 
  59.         dwResult = MsgWaitForMultipleObjects( 1, &g_hDMusicMessageEvent, 
  60.                                               FALSE, INFINITE, QS_ALLEVENTS );
  61.         switch( dwResult )
  62.         {
  63.             case WAIT_OBJECT_0 + 0:
  64.                 // 发信号给g_hDPMessageEvent,因此有可用的messages消息。
  65.                 if( FAILED( hr = ProcessDirectMusicMessages( hDlg ) ) ) 
  66.                 {
  67.                     DXTRACE_ERR_MSGBOX( TEXT("ProcessDirectMusicMessages"), hr );
  68.                     return FALSE;
  69.                 }
  70.                 break;
  71.             case WAIT_OBJECT_0 + 1:
  72.                 // Windows消息可用。
  73.                 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
  74.                 { 
  75.                     if( !IsDialogMessage( hDlg, &msg ) )  
  76.                     {
  77.                         TranslateMessage( &msg ); 
  78.                         DispatchMessage( &msg ); 
  79.                     }
  80.                     if( msg.message == WM_QUIT )
  81.                     {
  82.                         nExitCode = (int)msg.wParam;
  83.                         bDone     = TRUE;
  84.                         DestroyWindow( hDlg );
  85.                     }
  86.                 }
  87.                 break;
  88.         }
  89.     }
  90.     return nExitCode;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // 函数名: MainDlgProc()
  94. // 描  述: 处理对话框消息
  95. //-----------------------------------------------------------------------------
  96. INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
  97. {
  98.     HRESULT hr;
  99.     switch( msg ) 
  100.     {
  101.         case WM_INITDIALOG:
  102.             if( FAILED( hr = OnInitDialog( hDlg ) ) )
  103.             {
  104.                 DXTRACE_ERR_MSGBOX( TEXT("OnInitDialog"), hr );
  105.                 MessageBox( hDlg, "Error initializing DirectMusic.  Sample will now exit.", 
  106.                                   "DirectMusic Sample", MB_OK | MB_ICONERROR );
  107.                 PostQuitMessage( IDABORT );
  108.                 return FALSE;
  109.             }
  110.             break;
  111.         case WM_COMMAND:
  112.             switch( LOWORD(wParam) )
  113.             {
  114.                 case IDC_SOUNDFILE:
  115.                     OnOpenSoundFile( hDlg );
  116.                     break;
  117.                 case IDCANCEL:
  118.                     PostQuitMessage( IDCANCEL );
  119.                     break;
  120.                 case IDC_PLAY:
  121.                     if( FAILED( hr = OnPlaySegment( hDlg ) ) )
  122.                     {
  123.                         DXTRACE_ERR_MSGBOX( TEXT("OnPlaySegment"), hr );
  124.                         MessageBox( hDlg, "Error playing DirectMusic segment. "
  125.                                     "Sample will now exit.", "DirectMusic Sample", 
  126.                                     MB_OK | MB_ICONERROR );
  127.                         PostQuitMessage( IDABORT );
  128.                     }
  129.                     break;
  130.                 case IDC_STOP:
  131.                     // 播放片段时,简单调用Stop()不会停止任何MIDI sustain pedals, 
  132. // 但调用StopAll()可以。
  133.                     if( g_pMusicManager )
  134.                         g_pMusicManager->StopAll(); 
  135.                     EnablePlayUI( hDlg, TRUE );
  136.                     break;
  137.                 case IDC_TOOL_COMBO:
  138.                     OnChangeTool( hDlg );
  139.                     break;
  140.                 case IDHELP:
  141.                     DXUtil_LaunchReadme( hDlg );
  142.                     break;
  143.                 default:
  144. // 不处理消息
  145.                     return FALSE; 
  146.             }
  147.             break;
  148.         case WM_DESTROY:
  149.             // 清除一切
  150.             SAFE_RELEASE( g_pGraph );
  151.             SAFE_DELETE( g_pMusicSegment );
  152.             SAFE_DELETE( g_pMusicManager );
  153.             SAFE_DELETE( g_pEchoTool );
  154.             SAFE_DELETE( g_pMeasureTool1 );
  155.             SAFE_DELETE( g_pMeasureTool2 );
  156.             CloseHandle( g_hDMusicMessageEvent );
  157.             break; 
  158.         default:
  159. // 不处理消息
  160.             return FALSE; 
  161.     }
  162.     return TRUE; 
  163. }
  164. //-----------------------------------------------------------------------------
  165. // 函数名: OnInitDialog()
  166. // 描  述: 初始化对话框(建立UI控制等)
  167. //-----------------------------------------------------------------------------
  168. HRESULT OnInitDialog( HWND hDlg )
  169. {
  170.     HRESULT hr;
  171.     LONG lIndex;
  172.     // 为对话框设置icon
  173.     HICON hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDR_MAINFRAME ) );
  174.     SendMessage( hDlg, WM_SETICON, ICON_BIG,   (LPARAM) hIcon );  // 设置大icon
  175.     SendMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon );  // 设置小icon
  176.     g_hDMusicMessageEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
  177.     g_pMusicManager = new CMusicManager();
  178.     if( NULL == g_pMusicManager )
  179.         return E_OUTOFMEMORY;
  180.     // 使用缺省音轨初始化DirectMusic
  181.     hr = g_pMusicManager->Initialize( hDlg );
  182.     if( FAILED(hr) )
  183.         return DXTRACE_ERR_MSGBOX( TEXT("Initialize"), hr );
  184.     
  185.     IDirectMusicPerformance8* pPerformance    = g_pMusicManager->GetPerformance();
  186.     IDirectMusicAudioPath8* pDefaultAudioPath = g_pMusicManager->GetDefaultAudioPath();
  187.     // 产生一个DirectMusicGraph,并告知相关的参数
  188.     hr = pDefaultAudioPath->GetObjectInPath( 0, DMUS_PATH_PERFORMANCE_GRAPH, 0,
  189.                                              GUID_NULL, 0, IID_IDirectMusicGraph, 
  190.                                              (LPVOID*) &g_pGraph );
  191.     SAFE_RELEASE( pDefaultAudioPath );
  192.     if( FAILED( hr ) )
  193.         return DXTRACE_ERR_MSGBOX( TEXT("GetObjectInPath"), hr );
  194.     // 注册片段通知
  195.     if( FAILED( hr = pPerformance->AddNotificationType( GUID_NOTIFICATION_SEGMENT ) ) )
  196.         return DXTRACE_ERR_MSGBOX( TEXT("AddNotificationType"), hr );
  197.     if( FAILED( hr = pPerformance->AddNotificationType( GUID_NOTIFICATION_MEASUREANDBEAT) ) )
  198.         return DXTRACE_ERR_MSGBOX( TEXT("AddNotificationType"), hr );
  199.     if( FAILED( hr = pPerformance->SetNotificationHandle( g_hDMusicMessageEvent, 0 ) ) )
  200.         return DXTRACE_ERR_MSGBOX( TEXT("SetNotificationHandle"), hr );
  201.     g_pEchoTool = new CEchoTool();
  202.     if( NULL == g_pEchoTool )
  203.         return E_OUTOFMEMORY;
  204.     g_pMeasureTool1 = new CMeasureTool(hDlg);
  205.     if( NULL == g_pMeasureTool1 )
  206.         return E_OUTOFMEMORY;
  207.     g_pMeasureTool2 = new CMeasureTool(hDlg);
  208.     if( NULL == g_pMeasureTool2 )
  209.         return E_OUTOFMEMORY;
  210.     // 初始化UI
  211.     HWND hToolCombo = GetDlgItem( hDlg, IDC_TOOL_COMBO );
  212.     lIndex = (LONG)SendMessage( hToolCombo, CB_ADDSTRING, 0, (LPARAM) TEXT("无") );
  213.     SendMessage( hToolCombo, CB_SETITEMDATA, lIndex, (LPARAM) NULL );
  214.     lIndex = (LONG)SendMessage( hToolCombo, CB_ADDSTRING, 0, (LPARAM) TEXT("Echo工具") );
  215.     SendMessage( hToolCombo, CB_SETITEMDATA, lIndex, (LPARAM) (IDirectMusicTool*) g_pEchoTool );
  216.     lIndex = (LONG)SendMessage( hToolCombo, CB_ADDSTRING, 0, (LPARAM) TEXT("Measure工具") );
  217.     SendMessage( hToolCombo, CB_SETITEMDATA, lIndex, (LPARAM) (IDirectMusicTool*) g_pMeasureTool1 );
  218.     SendMessage( hToolCombo, CB_SETCURSEL, 0, 0 );
  219.     // 装载缺省的音频片段 
  220.     TCHAR strFileName[MAX_PATH+1];
  221.     DXUtil_GetDXSDKMediaPathCb( strFileName, sizeof(strFileName) );
  222.     strcat( strFileName, "sample.sgt" );
  223.     if( S_FALSE == LoadSegmentFile( hDlg, strFileName ) )
  224.     {
  225.         // 设置UI控制
  226.         SetDlgItemText( hDlg, IDC_FILENAME, TEXT("No file loaded.") );
  227.     }
  228.     else
  229.     {
  230.         IDirectMusicSegment8*   pPrimarySegment8;
  231.         DMUS_TEMPO_PARAM        tempo;
  232.         MUSIC_TIME              mtTime = 0;
  233.         pPrimarySegment8 = g_pMusicSegment->GetSegment();
  234.         tempo.mtTime = 0;
  235.         tempo.dblTempo = 70.;
  236.         pPrimarySegment8->SetParam(GUID_TempoParam, 0xffffffff, DMUS_SEG_ALLTRACKS, mtTime, &tempo);
  237.     }
  238.     return S_OK;
  239. }
  240. //-----------------------------------------------------------------------------
  241. // 函数名: OnOpenSoundFile()
  242. // 描  述: 当用户需要打开一个声音文件时,调用
  243. //-----------------------------------------------------------------------------
  244. VOID OnOpenSoundFile( HWND hDlg ) 
  245. {
  246.     static TCHAR strFileName[MAX_PATH+1] = TEXT("");
  247.     static TCHAR strPath[MAX_PATH+1] = TEXT("");
  248.     // 得到缺省的多媒体路径(如C:MSSDKSAMPLESDMUSICMEDIA)
  249.     if( '' == strPath[0] )
  250.     {
  251.         DXUtil_GetDXSDKMediaPathCb( strPath, sizeof(strPath) );
  252.     }
  253.     // 建立OPENFILENAME结构
  254.     OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL,
  255.                          TEXT("DirectMusic Content Files*.sgt;*.mid;*.rmiAll Files*.*"), NULL,
  256.                          0, 1, strFileName, MAX_PATH, NULL, 0, strPath,
  257.                          TEXT("Open Content File"),
  258.                          OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0,
  259.                          TEXT(".sgt"), 0, NULL, NULL };
  260.     // 播放片段时,简单调用Stop()不会停止任何MIDI sustain pedals, 
  261. // 但调用StopAll()可以。
  262.     if( g_pMusicManager )
  263.         g_pMusicManager->StopAll(); 
  264.     // 为播放装载的文件更新UI控制
  265.     EnableWindow(  GetDlgItem( hDlg, IDC_PLAY ), FALSE);
  266.     EnableWindow(  GetDlgItem( hDlg, IDC_STOP ), FALSE);
  267.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Loading file...") );
  268.     // 显示OpenFileName对话框。然后尝试装载指定的文件
  269.     if( TRUE != GetOpenFileName( &ofn ) )
  270.     {
  271.         SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Load aborted.") );
  272.         return;
  273.     }
  274.     if( S_FALSE == LoadSegmentFile( hDlg, strFileName ) )
  275.     {
  276.         // 不是一个关键的错误,因此仅仅更新状态
  277.         SetDlgItemText( hDlg, IDC_FILENAME, TEXT("Could not create segment from file.") );
  278.     }
  279.     // 记忆路径
  280.     strcpy( strPath, strFileName );
  281.     char* strLastSlash = strrchr( strPath, '\' );
  282.     if( strLastSlash )
  283.         strLastSlash[0] = '';
  284. }
  285. //-----------------------------------------------------------------------------
  286. // 函数名: LoadSegmentFile()
  287. // 描  述: 装载片段文件
  288. //-----------------------------------------------------------------------------
  289. HRESULT LoadSegmentFile( HWND hDlg, TCHAR* strFileName )
  290. {
  291.     HRESULT hr;
  292.     SetDlgItemText( hDlg, IDC_FILENAME, TEXT("") );
  293.     // 释放先前的片段,建立一个新的
  294.     SAFE_DELETE( g_pMusicSegment );
  295.     // 因为老的剧本已释放,有装载器收集垃圾
  296.     g_pMusicManager->CollectGarbage();
  297.     // 为搜索与该文件相关的DirectMusic内容而设置的基于文件名的多媒体路径(如C:MEDIA)
  298.     TCHAR strMediaPath[MAX_PATH+1];
  299.     _tcsncpy( strMediaPath, strFileName, MAX_PATH );
  300.     strMediaPath[MAX_PATH-1] = 0;
  301.     TCHAR* strLastSlash = _tcsrchr(strMediaPath, TEXT('\'));
  302.     if( strLastSlash )
  303.     {
  304.         *strLastSlash = 0;
  305.         if( FAILED( hr = g_pMusicManager->SetSearchDirectory( strMediaPath ) ) )
  306.             return DXTRACE_ERR_MSGBOX( TEXT("SetSearchDirectory"), hr );
  307.     }
  308.     
  309.     // 为装载正确的乐器,DirectMusic必须知道该文件是否是一个标准的MIDI文件
  310.     BOOL bMidiFile = FALSE;
  311.     if( strstr( strFileName, ".mid" ) != NULL ||
  312.         strstr( strFileName, ".rmi" ) != NULL ) 
  313.     {
  314.         bMidiFile = TRUE;
  315.     }
  316.     // 将文件载入一个DirectMusic片段中 
  317.     if( FAILED( g_pMusicManager->CreateSegmentFromFile( &g_pMusicSegment, strFileName, 
  318.                                                         TRUE, bMidiFile ) ) )
  319.     {
  320.         // 不是一个关键的错误,因此仅仅更新状态
  321.         return S_FALSE; 
  322.     }
  323.     // 为显示片段被装载,更新UI控制
  324.     SetDlgItemText( hDlg, IDC_FILENAME, strFileName );
  325.     EnablePlayUI( hDlg, TRUE );
  326.     return S_OK;
  327. }
  328. //-----------------------------------------------------------------------------
  329. // 函数名: ProcessDirectMusicMessages()
  330. // 描  述: 处理DirectMusic音符消息
  331. //-----------------------------------------------------------------------------
  332. HRESULT ProcessDirectMusicMessages( HWND hDlg )
  333. {
  334.     HRESULT hr;
  335.     IDirectMusicPerformance8* pPerf = NULL;
  336.     DMUS_NOTIFICATION_PMSG* pPMsg;
  337.         
  338.     if( NULL == g_pMusicManager )
  339.         return S_OK;
  340.     pPerf = g_pMusicManager->GetPerformance();
  341.     // Get waiting notification message from the performance
  342.     while( S_OK == pPerf->GetNotificationPMsg( &pPMsg ) )
  343.     {
  344.         switch( pPMsg->dwNotificationOption )
  345.         {
  346.         case DMUS_NOTIFICATION_SEGEND:
  347.             if( pPMsg->punkUser )
  348.             {
  349.                 IDirectMusicSegmentState8* pSegmentState   = NULL;
  350.                 IDirectMusicSegment*       pNotifySegment   = NULL;
  351.                 IDirectMusicSegment8*      pNotifySegment8  = NULL;
  352.                 IDirectMusicSegment8*      pPrimarySegment8 = NULL;
  353.                 // pPMsg->punkUser包括一个IDirectMusicSegmentState8, 
  354.                 // 从而我们能够查询SegmentState引用的片段
  355.                 if( FAILED( hr = pPMsg->punkUser->QueryInterface( IID_IDirectMusicSegmentState8,
  356.                                                                   (VOID**) &pSegmentState ) ) )
  357.                     return DXTRACE_ERR_MSGBOX( TEXT("QueryInterface"), hr );
  358.                 if( SUCCEEDED( hr = pSegmentState->GetSegment( &pNotifySegment ) ) )
  359.                 {
  360.                     if( FAILED( hr = pNotifySegment->QueryInterface( IID_IDirectMusicSegment8,
  361.                                                                      (VOID**) &pNotifySegment8 ) ) )
  362.                         return DXTRACE_ERR_MSGBOX( TEXT("QueryInterface"), hr );
  363.                     // 为主要的片段得到IDirectMusicSegment
  364.                     pPrimarySegment8 = g_pMusicSegment->GetSegment();
  365.                     // 推断这是什么片段
  366.                     if( pNotifySegment8 == pPrimarySegment8 )
  367.                     {
  368.                         // 为显示停止音频,更新UI控制
  369.                         EnablePlayUI( hDlg, TRUE );
  370.                     }
  371.                 }
  372.                 // 清除
  373.                 SAFE_RELEASE( pSegmentState );
  374.                 SAFE_RELEASE( pNotifySegment );
  375.                 SAFE_RELEASE( pNotifySegment8 );
  376.             }
  377.             break;
  378.         }
  379.         pPerf->FreePMsg( (DMUS_PMSG*)pPMsg ); 
  380.     }
  381.     return S_OK;
  382. }
  383. //-----------------------------------------------------------------------------
  384. // 函数名: OnPlaySegment()
  385. // 描  述: 播放片段
  386. //-----------------------------------------------------------------------------
  387. HRESULT OnPlaySegment( HWND hDlg )
  388. {
  389.     HRESULT hr;
  390.     HWND hLoopButton = GetDlgItem( hDlg, IDC_LOOP_CHECK );
  391.     BOOL bLooped = ( SendMessage( hLoopButton, BM_GETSTATE, 0, 0 ) == BST_CHECKED );
  392.     if( bLooped )
  393.     {
  394.         // 设置片段的重复次数
  395.         if( FAILED( hr = g_pMusicSegment->SetRepeats( DMUS_SEG_REPEAT_INFINITE ) ) )
  396.             return DXTRACE_ERR_MSGBOX( TEXT("SetRepeats"), hr );
  397.     }
  398.     else
  399.     {
  400.         // 设置片段不重复
  401.         if( FAILED( hr = g_pMusicSegment->SetRepeats( 0 ) ) )
  402.             return DXTRACE_ERR_MSGBOX( TEXT("SetRepeats"), hr );
  403.     }
  404.     // 播放片段和等待. 当当前有一个片段在播放时,DMUS_SEGF_BEAT表示在下一次敲打时播放
  405.     if( FAILED( hr = g_pMusicSegment->Play( DMUS_SEGF_BEAT ) ) )
  406.         return DXTRACE_ERR_MSGBOX( TEXT("Play"), hr );
  407.     EnablePlayUI( hDlg, FALSE );
  408.     return S_OK;
  409. }
  410. //-----------------------------------------------------------------------------
  411. // 函数名: EnablePlayUI( )
  412. // 描  述: 是否允许UI控制的表演 
  413. //-----------------------------------------------------------------------------
  414. VOID EnablePlayUI( HWND hDlg, BOOL bEnable )
  415. {
  416.     if( bEnable )
  417.     {
  418.         EnableWindow(   GetDlgItem( hDlg, IDC_LOOP_CHECK ), TRUE );
  419.         EnableWindow(   GetDlgItem( hDlg, IDC_STOP ),       FALSE );
  420.         EnableWindow(   GetDlgItem( hDlg, IDC_PLAY ),       TRUE );
  421.         SetFocus(       GetDlgItem( hDlg, IDC_PLAY ) );
  422.     }
  423.     else
  424.     {
  425.         EnableWindow(  GetDlgItem( hDlg, IDC_LOOP_CHECK ), FALSE );
  426.         EnableWindow(  GetDlgItem( hDlg, IDC_STOP ),       TRUE );
  427.         SetFocus(      GetDlgItem( hDlg, IDC_STOP ) );
  428.         EnableWindow(  GetDlgItem( hDlg, IDC_PLAY ),       FALSE );
  429.     }
  430. }
  431. //-----------------------------------------------------------------------------
  432. // 函数名: OnChangeTool()
  433. // 描  述: 改变工具
  434. //-----------------------------------------------------------------------------
  435. HRESULT OnChangeTool( HWND hDlg )
  436. {
  437.     HRESULT hr;
  438.     IDirectMusicTool* pSelectedTool;
  439.     LONG lCurSelection;
  440.     lCurSelection = (LONG)SendDlgItemMessage( hDlg, IDC_TOOL_COMBO, CB_GETCURSEL, 0, 0 );
  441.     pSelectedTool = (IDirectMusicTool*) SendDlgItemMessage( hDlg, IDC_TOOL_COMBO, 
  442.                                                             CB_GETITEMDATA, lCurSelection, 0 );
  443.     if( pSelectedTool != g_pCurrentTool )
  444.     {
  445.         // 从当前的表中移除当前的工具
  446.         if( g_pCurrentTool != NULL )
  447.         {
  448.             if( FAILED( hr = g_pGraph->RemoveTool( g_pCurrentTool ) ) )
  449.                 return DXTRACE_ERR_MSGBOX( TEXT("RemoveTool"), hr );
  450.         }
  451.         // 对所有的通道或初始化表时,增加工具到表中 
  452.         if( pSelectedTool != NULL )
  453.         {
  454.             if( FAILED( hr = g_pGraph->InsertTool( pSelectedTool, NULL, 0, 0 ) ) )
  455.                 return DXTRACE_ERR_MSGBOX( TEXT("InsertTool"), hr );
  456.         }
  457.         g_pCurrentTool = pSelectedTool;
  458.     }
  459.     return S_OK;
  460. }