The following example shows how to enumerate and select ltmmConvert object compressors.
// define helper macros for using interfaces under C#ifndef COBJMACROS#define COBJMACROS#endif#include "ltmm.h"#include "resource.h"#include "tchar.h"#include "stdio.h"HINSTANCE g_hInstance; // application instance handleIltmmConvert* g_pConvert; // capture object's interface pointer//// BuildCompressorList// fills a listbox to match the contents of the collection//// pCompressors = compressor collection's interface pointer// hwndListBox = listbox window handle//void BuildCompressorList(IltmmCompressors* pCompressors, HWND hwndListBox){long i;long count;int selected = -1;// reset the listbox contentsSendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);// get the collection's item countIltmmCompressors_get_Count(pCompressors, &count);for(i = 0; i < count; i++){IltmmCompressor* pCompressor;BSTR bstr;TCHAR sz[256];int index;VARIANT_BOOL f;// retrieve collection itemIltmmCompressors_Item (pCompressors, i, &pCompressor);// get displayable nameIltmmCompressor_get_FriendlyName (pCompressor, &bstr);// convert 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);// remember this listbox item, if it is selected in the collectionIltmmCompressor_get_Selected (pCompressor, &f);if(f)selected = i;// free the collection itemIUnknown_Release(pCompressor);}// select the appropriate listbox itemfor(i = 0; i < count; i++){if(selected == (long) SendMessage(hwndListBox, LB_GETITEMDATA, i, 0)){SendMessage(hwndListBox, LB_SETCURSEL, i, 0);break;}}}//// CompressorSelectionChanged// called to reflect changes in the listbox selection//// pCompressors = compressor collection's interface pointer// hwndListBox = listbox window handle//void CompressorSelectionChanged(IltmmCompressors* pCompressors, HWND hwndListBox){int index;long item;int i;int count;HRESULT hr;// get the index of current listbox selectionindex = (int) SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);if(index < 0){// clear selectionIltmmCompressors_put_Selection (pCompressors, -1);}else{// get the collection item indexitem = (long) SendMessage(hwndListBox, LB_GETITEMDATA, index, 0);// select the item#ifdef _DEBUG{IltmmCompressor* pCompressor;IltmmCompressors_Item (pCompressors, item, &pCompressor);hr = IltmmCompressor_put_Selected (pCompressor, VARIANT_TRUE);IUnknown_Release(pCompressor);}#elsehr = IltmmCompressors_put_Selection (pCompressors, item);#endif// if new selection failed, we need to force the listbox to match the actual selectionif(FAILED(hr)){// get the real selectionIltmmCompressors_get_Selection (pCompressors, &item);// find the matching listbox itemcount = (int) SendMessage(hwndListBox, LB_GETCOUNT, 0, 0);for(i = 0; i < count; i++){if(item == (long) SendMessage(hwndListBox, LB_GETITEMDATA, i, 0)){SendMessage(hwndListBox, LB_SETCURSEL, i, 0);break;}}}}}//// RefreshCompressorList// called when to completely rebuild the collection//// pCompressors = compressor collection's interface pointer// hwndListBox = listbox window handle//void RefreshCompressorList(IltmmCompressors* pCompressors, HWND hwndListBox){IltmmCompressor* pCompressor;long item;BSTR bstr;// get the currently selected itemIltmmCompressors_get_Selection (pCompressors, &item);if(item >= 0){// get it's unique nameIltmmCompressors_Item (pCompressors, item, &pCompressor);IltmmCompressor_get_Name (pCompressor, &bstr);IUnknown_Release(pCompressor);}else{bstr = NULL;}// rebuild the collectionIltmmCompressors_Refresh (pCompressors);if(bstr){// find the previously selected itemIltmmCompressors_Find(pCompressors, bstr, &item);// make it the current selectionif(item >= 0)IltmmCompressors_put_Selection (pCompressors, item);SysFreeString(bstr);}// rebuild the listboxBuildCompressorList(pCompressors, hwndListBox);}//// CompressorDlgProc// selects object compressors//BOOL CALLBACK CompressorDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){IltmmCompressors* pCompressors;lParam = lParam ;switch (msg){case WM_INITDIALOG:// initialize the audio compressor listboxIltmmConvert_get_AudioCompressors (g_pConvert, &pCompressors);BuildCompressorList(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));IUnknown_Release(pCompressors);// initialize the video compressor listboxIltmmConvert_get_VideoCompressors (g_pConvert, &pCompressors);BuildCompressorList(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));IUnknown_Release(pCompressors);return TRUE;break;case WM_COMMAND:switch(LOWORD(wParam)){case IDC_REFRESHAUDIOCOMPRESSORS:// refresh the audio compressor listboxIltmmConvert_get_AudioCompressors (g_pConvert, &pCompressors);RefreshCompressorList(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));IUnknown_Release(pCompressors);return TRUE;break;case IDC_AUDIOCOMPRESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// select the audio compressorIltmmConvert_get_AudioCompressors (g_pConvert, &pCompressors);CompressorSelectionChanged(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));IUnknown_Release(pCompressors);}break;case IDC_REFRESHVIDEOCOMPRESSORS:// initialize the video compressor listboxIltmmConvert_get_VideoCompressors (g_pConvert, &pCompressors);RefreshCompressorList(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));IUnknown_Release(pCompressors);return TRUE;break;case IDC_VIDEOCOMPRESSORS:if(HIWORD(wParam) == LBN_SELCHANGE){// select the video compressorIltmmConvert_get_VideoCompressors (g_pConvert, &pCompressors);CompressorSelectionChanged(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));IUnknown_Release(pCompressors);}break;case IDOK:EndDialog(hwnd, IDOK);return TRUE;break;}break;}return FALSE;}void SelectingltmmConvertObjectCompressors_Example ( HINSTANCE hInstance /*application instance handle*/ ){HRESULT hr;g_hInstance = hInstance;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// create the convert objecthr = CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &g_pConvert);if(FAILED(hr))goto error;DialogBox(g_hInstance, (LPCTSTR)IDD_COMPRESSORDLG, NULL, CompressorDlgProc);error:// cleanupif(g_pConvert)IUnknown_Release(g_pConvert);CoUninitialize();}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
