The following example shows how to enumerate and select ltmmPlay object processors.
#include "ltmm.h"#include "resource.h"#include "tchar.h"#include "stdio.h"HINSTANCE g_hInstance; // application instance handleIltmmPlay* g_pPlay; // play object's interface pointer//// BuildProcessorList// fills the registered processor listbox to match the contents of the collection//// pProcessors = processor collection's interface pointer// hwndListBox = listbox window handle//void BuildProcessorList(IltmmProcessors* pProcessors, HWND hwndListBox){long i;long count;// reset the listbox contentsSendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);// get the collection's item countpProcessors->get_Count(&count);for(i = 0; i < count; i++){IltmmProcessor* pProcessor;BSTR bstr;TCHAR sz[256];int index;// retrieve collection itempProcessors->Item(i, &pProcessor);// get displayable namepProcessor->get_FriendlyName(&bstr);// play from unicode_stprintf(sz, _T("%ls"), bstr);// free nameSysFreeString(bstr);// add the name to the listboxindex = SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sz);// associate the listbox item with the collection item indexSendMessage(hwndListBox, LB_SETITEMDATA, index, i);// free the collection itempProcessor->Release();}}//// BuildSelectedProcessorList// fills the selected processor listbox to match the contents of the collection//// pSelProcessors = selected processor collection's interface pointer// hwndSelListBox = selected listbox window handle//void BuildSelectedProcessorList(IltmmProcessors* pSelProcessors, HWND hwndSelListBox){long i;long count;// reset the listbox contentsSendMessage(hwndSelListBox, LB_RESETCONTENT, 0, 0);// get the collection's item countpSelProcessors->get_Count(&count);for(i = 0; i < count; i++){IltmmProcessor* pProcessor;BSTR bstr;TCHAR sz[256];// retrieve collection itempSelProcessors->Item(i, &pProcessor);// get displayable namepProcessor->get_FriendlyName(&bstr);// play from unicode_stprintf(sz, _T("%ls"), bstr);// free nameSysFreeString(bstr);// add the name to the listboxSendMessage(hwndSelListBox, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sz);// free the collection itempProcessor->Release();}// add a blank entry at the end of the list and select itSendMessage(hwndSelListBox, LB_ADDSTRING, 0, (LPARAM) (LPVOID) _T(""));SendMessage(hwndSelListBox, LB_SETCURSEL, count, 0);}//// RemoveSelectedProcessor// removes the currently selected processor//// pSelProcessors = selected processor collection's interface pointer// hwndSelListBox = selected listbox window handle//void RemoveSelectedProcessor(IltmmProcessors* pSelProcessors, HWND hwndSelListBox){int index;int count;// get the number of selected processor listbox itemscount = (int) SendMessage(hwndSelListBox, LB_GETCOUNT, 0, 0);// get the deletion point from the selected processor listboxindex = (int) SendMessage(hwndSelListBox, LB_GETCURSEL, 0, 0);// if not a valid processor, then returnif(index < 0 || index >= (count - 1))return;// remove the processor from the selected processor collectionpSelProcessors->Remove(index);// remove the name from the selected processor listboxSendMessage(hwndSelListBox, LB_DELETESTRING, index, 0);// select the next item in the listboxSendMessage(hwndSelListBox, LB_SETCURSEL, index, 0);}//// RemoveAllSelectedProcessors// removes all selected processors//// pSelProcessors = selected processor collection's interface pointer// hwndSelListBox = selected listbox window handle//void RemoveAllSelectedProcessors(IltmmProcessors* pSelProcessors, HWND hwndSelListBox){pSelProcessors->RemoveAll();BuildSelectedProcessorList(pSelProcessors, hwndSelListBox);}//// InsertSelectedProcessor// inserts the currently selected registerd processor into te selected processor collection//// pProcessors = registered processor collection's interface pointer// hwndListBox = registered listbox window handle// pSelProcessors = selected processor collection's interface pointer// hwndSelListBox = selected listbox window handle//void InsertSelectedProcessor(IltmmProcessors* pProcessors, HWND hwndListBox,IltmmProcessors* pSelProcessors, HWND hwndSelListBox){int index;int selindex;long item;IltmmProcessor* pProcessor;BSTR bstr;TCHAR sz[256];// get the selection from the registered processor listboxindex = (int) SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);if(index < 0)return;// get the collection item indexitem = (long) SendMessage(hwndListBox, LB_GETITEMDATA, index, 0);// get the actual itempProcessors->Item(item, &pProcessor);// get the insertion point from the selected processor listboxselindex = (int) SendMessage(hwndSelListBox, LB_GETCURSEL, 0, 0);// insert the processor into the selected processor collectionpSelProcessors->Add(pProcessor, selindex);// get the displayable namepProcessor->get_FriendlyName(&bstr);// release the processorpProcessor->Release();// play from unicode_stprintf(sz, _T("%ls"), bstr);// free nameSysFreeString(bstr);// insert the name into the selected processor listboxSendMessage(hwndSelListBox, LB_INSERTSTRING, selindex, (LPARAM) (LPCTSTR) sz);}//// RefreshProcessorList// called to completely rebuild the collection//// pProcessors = processor collection's interface pointer// hwndListBox = listbox window handle//void RefreshProcessorList(IltmmProcessors* pProcessors, HWND hwndListBox){IltmmProcessor* pProcessor;long item;BSTR bstr;long i;long count;// get the currently selected itemi = (int) SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);if(i >= 0){item = (long) SendMessage(hwndListBox, LB_GETITEMDATA, i, 0);// get it's unique namepProcessors->Item(item, &pProcessor);pProcessor->get_Name(&bstr);pProcessor->Release();}else{bstr = NULL;}// rebuild the collectionpProcessors->Refresh();// rebuild the listboxBuildProcessorList(pProcessors, hwndListBox);if(bstr){// find the previously selected itempProcessors->Find(bstr, &item);// make it the current selectionif(item >= 0){pProcessors->get_Count(&count);// select the appropriate listbox itemfor(i = 0; i < count; i++){if(item == (long) SendMessage(hwndListBox, LB_GETITEMDATA, i, 0)){SendMessage(hwndListBox, LB_SETCURSEL, i, 0);break;}}}SysFreeString(bstr);}}//// ProcessorSelectionChanged// called when the registered processor selection has changed//// pProcessors = processor collection's interface pointer// hwndListBox = listbox window handle// hwndAddBtn = add button window handle//void ProcessorSelectionChanged(IltmmProcessors* pProcessors, HWND hwndListBox, HWND hwndAddBtn){int index;// get the currently selected listbox itemindex = (int) SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);// enable add, if a filter is selectedEnableWindow(hwndAddBtn, index >= 0);}//// SelectedProcessorSelectionChanged// called when the selected processor selection has changed//// pSelProcessors = processor collection's interface pointer// hwndSelListBox = listbox window handle// hwndRemoveBtn = remove button window handle// hwndRemoveAllBtn = remove all button window handle// hwndPropBtn = properties button window handle//void SelectedProcessorSelectionChanged(IltmmProcessors* pSelProcessors, HWND hwndSelListBox, HWND hwndRemoveBtn, HWND hwndRemoveAllBtn, HWND hwndPropBtn){int index;int count;BOOL fFilter;VARIANT_BOOL fHasDialog = VARIANT_FALSE;HRESULT hr;// get the currently selected listbox itemindex = (int) SendMessage(hwndSelListBox, LB_GETCURSEL, 0, 0);// get the total item countcount = (int) SendMessage(hwndSelListBox, LB_GETCOUNT, 0, 0);// is this a filter?fFilter = (index >= 0 && index < (count - 1));// enable remove all button, if there is a filter in the listEnableWindow(hwndRemoveAllBtn, count > 1);// enable remove button, if it is a filterEnableWindow(hwndRemoveBtn, fFilter);if(fFilter){// check for the availablility of a filter property dialog boxIltmmProcessor* pProcessor;hr = pSelProcessors->Item(index, &pProcessor);if(SUCCEEDED(hr)){pProcessor->HasDialog(ltmmProcessor_Dlg_Properties, &fHasDialog);pProcessor->Release();}}else{fHasDialog = VARIANT_FALSE;}// enable properties button, if dialog box is availableEnableWindow(hwndPropBtn, fHasDialog != VARIANT_FALSE);}//// InvokeProcessorProperties// invokes the currently selected processor's properties dialog box//// pSelProcessors = processor collection's interface pointer// hwndSelListBox = listbox window handle// hwndParent = parent window handle//void InvokeProcessorProperties(IltmmProcessors* pSelProcessors, HWND hwndSelListBox, HWND hwndParent){int index;int count;IltmmProcessor* pProcessor;HRESULT hr;// get the currently selected listbox itemindex = (int) SendMessage(hwndSelListBox, LB_GETCURSEL, 0, 0);// get the total item countcount = (int) SendMessage(hwndSelListBox, LB_GETCOUNT, 0, 0);// is this a filter?if(index >= 0 && index < (count - 1)){// invoke the processor's dialoghr = pSelProcessors->Item(index, &pProcessor);if(SUCCEEDED(hr)){pProcessor->ShowDialog(ltmmProcessor_Dlg_Properties, (long) hwndParent);pProcessor->Release();}}}//// ProcessorDlgProc// selects object processors//BOOL CALLBACK ProcessorDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){IltmmProcessors* pProcessors;IltmmProcessors* pSelProcessors;switch (msg){case WM_INITDIALOG:// initialize the audio processor listboxg_pPlay->get_AudioProcessors(&pProcessors);BuildProcessorList(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS));ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS),GetDlgItem(hwnd, IDC_ADDAUDIOPROCESSOR));pProcessors->Release();// initialize the selected audio processor listboxg_pPlay->get_SelectedAudioProcessors(&pSelProcessors);BuildSelectedProcessorList(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEAUDIOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_AUDIOPROCESSORPROPERTIES));pSelProcessors->Release();// initialize the video processor listboxg_pPlay->get_VideoProcessors(&pProcessors);BuildProcessorList(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS));ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS),GetDlgItem(hwnd, IDC_ADDVIDEOPROCESSOR));pProcessors->Release();// initialize the selected video processor listboxg_pPlay->get_SelectedVideoProcessors(&pSelProcessors);BuildSelectedProcessorList(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEVIDEOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_VIDEOPROCESSORPROPERTIES));pSelProcessors->Release();return TRUE;break;case WM_COMMAND:switch(LOWORD(wParam)){case IDC_ADDAUDIOPROCESSOR:// insert processor into selected audio processor collectiong_pPlay->get_AudioProcessors(&pProcessors);g_pPlay->get_SelectedAudioProcessors(&pSelProcessors);InsertSelectedProcessor(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS),pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEAUDIOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_AUDIOPROCESSORPROPERTIES));pSelProcessors->Release();pProcessors->Release();return TRUE;break;case IDC_REMOVEAUDIOPROCESSOR:// remove processor from the selected audio processor collectiong_pPlay->get_SelectedAudioProcessors(&pSelProcessors);RemoveSelectedProcessor(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEAUDIOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_AUDIOPROCESSORPROPERTIES));pSelProcessors->Release();return TRUE;break;case IDC_REMOVEALLAUDIOPROCESSORS:// remove all selected audio processorsg_pPlay->get_SelectedAudioProcessors(&pSelProcessors);RemoveAllSelectedProcessors(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEAUDIOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_AUDIOPROCESSORPROPERTIES));pSelProcessors->Release();return TRUE;break;case IDC_REFRESHAUDIOPROCESSORS:// rebuild the registered audio processor collectiong_pPlay->get_AudioProcessors(&pProcessors);RefreshProcessorList(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS));ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS),GetDlgItem(hwnd, IDC_ADDAUDIOPROCESSOR));pProcessors->Release();return TRUE;break;case IDC_AUDIOPROCESSORPROPERTIES:// invoke the selected audio processor's properties dialog boxg_pPlay->get_SelectedAudioProcessors(&pSelProcessors);InvokeProcessorProperties(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS), hwnd);pSelProcessors->Release();return TRUE;break;case IDC_SELAUDIOPROCESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// selection changed, update buttonsg_pPlay->get_SelectedAudioProcessors(&pSelProcessors);SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEAUDIOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLAUDIOPROCESSORS),GetDlgItem(hwnd, IDC_AUDIOPROCESSORPROPERTIES));pSelProcessors->Release();}break;case IDC_AUDIOPROCESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// selection changed, update buttonsg_pPlay->get_AudioProcessors(&pProcessors);ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_AUDIOPROCESSORS),GetDlgItem(hwnd, IDC_ADDAUDIOPROCESSOR));pProcessors->Release();}break;case IDC_ADDVIDEOPROCESSOR:// insert processor into selected video processor collectiong_pPlay->get_VideoProcessors(&pProcessors);g_pPlay->get_SelectedVideoProcessors(&pSelProcessors);InsertSelectedProcessor(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS),pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEVIDEOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_VIDEOPROCESSORPROPERTIES));pSelProcessors->Release();pProcessors->Release();return TRUE;break;case IDC_REMOVEVIDEOPROCESSOR:// remove processor from the selected video processor collectiong_pPlay->get_SelectedVideoProcessors(&pSelProcessors);RemoveSelectedProcessor(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEVIDEOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_VIDEOPROCESSORPROPERTIES));pSelProcessors->Release();return TRUE;break;case IDC_REMOVEALLVIDEOPROCESSORS:// remove all selected video processorsg_pPlay->get_SelectedVideoProcessors(&pSelProcessors);RemoveAllSelectedProcessors(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS));SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEVIDEOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_VIDEOPROCESSORPROPERTIES));pSelProcessors->Release();return TRUE;break;case IDC_REFRESHVIDEOPROCESSORS:// rebuild the registered video processor collectiong_pPlay->get_VideoProcessors(&pProcessors);RefreshProcessorList(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS));ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS),GetDlgItem(hwnd, IDC_ADDVIDEOPROCESSOR));pProcessors->Release();return TRUE;break;case IDC_VIDEOPROCESSORPROPERTIES:// invoke the selected video processor's properties dialog boxg_pPlay->get_SelectedVideoProcessors(&pSelProcessors);InvokeProcessorProperties(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS), hwnd);pSelProcessors->Release();return TRUE;break;case IDC_SELVIDEOPROCESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// selection changed, update buttonsg_pPlay->get_SelectedVideoProcessors(&pSelProcessors);SelectedProcessorSelectionChanged(pSelProcessors, GetDlgItem(hwnd, IDC_SELVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_REMOVEVIDEOPROCESSOR),GetDlgItem(hwnd, IDC_REMOVEALLVIDEOPROCESSORS),GetDlgItem(hwnd, IDC_VIDEOPROCESSORPROPERTIES));pSelProcessors->Release();}break;case IDC_VIDEOPROCESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// selection changed, update buttonsg_pPlay->get_VideoProcessors(&pProcessors);ProcessorSelectionChanged(pProcessors, GetDlgItem(hwnd, IDC_VIDEOPROCESSORS),GetDlgItem(hwnd, IDC_ADDVIDEOPROCESSOR));pProcessors->Release();}break;case IDOK:EndDialog(hwnd, IDOK);return TRUE;break;}break;}return FALSE;}int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){HRESULT hr;g_hInstance = hInstance;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// create the play objecthr = CoCreateInstance(CLSID_ltmmPlay, NULL, CLSCTX_INPROC_SERVER, IID_IltmmPlay, (void**) &g_pPlay);if(FAILED(hr))goto error;DialogBox(g_hInstance, (LPCTSTR)IDD_PROCESSORDLG, NULL, ProcessorDlgProc);error:// cleanupif(g_pPlay)g_pPlay->Release();CoUninitialize();return 0;}