The following example shows how to enumerate and select ltmmCapture object compressors.
#include "ltmm.h"
#include "resource.h"
#include "tchar.h"
#include "stdio.h"
HINSTANCE g_hInstance; // application instance handle
IltmmCapture* g_pCapture; // convert 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 contents
SendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);
// get the collection's item count
pCompressors->get_Count (&count);
for(i = 0; i < count; i++)
{
IltmmCompressor* pCompressor;
BSTR bstr;
TCHAR sz[256];
int index;
VARIANT_BOOL f;
// retrieve collection item
pCompressors->Item(i, &pCompressor);
// get displayable name
pCompressor->get_FriendlyName (&bstr);
// convert from unicode
_stprintf(sz, _T("%ls"), bstr);
// free name
SysFreeString(bstr);
// add the name to the listbox
index = SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sz);
// associate the listbox item with the collection item index
SendMessage(hwndListBox, LB_SETITEMDATA, index, i);
// remember this listbox item, if it is selected in the collection
pCompressor->get_Selected (&f);
if (f)
selected = i;
// free the collection item
pCompressor->Release();
}
// select the appropriate listbox item
for(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 selection
index = (int) SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);
if (index < 0)
{
// clear selection
pCompressors->put_Selection (-1);
}
else
{
// get the collection item index
item = (long) SendMessage(hwndListBox, LB_GETITEMDATA, index, 0);
// select the item
#ifdef _DEBUG
{
IltmmCompressor* pCompressor;
pCompressors->Item (item, &pCompressor);
hr = pCompressor->put_Selected (VARIANT_TRUE);
pCompressor->Release();
}
#else
hr = pCompressors->put_Selection (item);
#endif
// if new selection failed, we need to force the listbox to match the actual selection
if (FAILED(hr))
{
// get the real selection
pCompressors->get_Selection(&item);
// find the matching listbox item
count = (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 item
pCompressors->get_Selection (&item);
if (item >= 0)
{
// get it's unique name
pCompressors->Item (item, &pCompressor);
pCompressor->get_Name (&bstr);
pCompressor->Release();
}
else
{
bstr = NULL;
}
// rebuild the collection
pCompressors->Refresh ();
if (bstr)
{
// find the previously selected item
pCompressors->Find (bstr, &item);
// make it the current selection
if (item >= 0)
pCompressors->put_Selection (item);
SysFreeString(bstr);
}
// rebuild the listbox
BuildCompressorList(pCompressors, hwndListBox);
}
//
// CompressorDlgProc
// selects object compressors
//
BOOL CALLBACK CompressorDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
IltmmCompressors* pCompressors;
switch (msg)
{
case WM_INITDIALOG:
// initialize the audio compressor listbox
g_pCapture->get_AudioCompressors (&pCompressors);
BuildCompressorList(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));
pCompressors->Release();
// initialize the video compressor listbox
g_pCapture->get_VideoCompressors (&pCompressors);
BuildCompressorList(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));
pCompressors->Release();
return TRUE;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_REFRESHAUDIOCOMPRESSORS:
// refresh the audio compressor listbox
g_pCapture->get_AudioCompressors (&pCompressors);
RefreshCompressorList(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));
pCompressors->Release();
return TRUE;
break;
case IDC_AUDIOCOMPRESSORS:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
// select the audio compressor
g_pCapture->get_AudioCompressors (&pCompressors);
CompressorSelectionChanged(pCompressors, GetDlgItem(hwnd, IDC_AUDIOCOMPRESSORS));
pCompressors->Release();
}
break;
case IDC_REFRESHVIDEOCOMPRESSORS:
// initialize the video compressor listbox
g_pCapture->get_VideoCompressors (&pCompressors);
RefreshCompressorList(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));
pCompressors->Release();
return TRUE;
break;
case IDC_VIDEOCOMPRESSORS:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
// select the video compressor
g_pCapture->get_VideoCompressors (&pCompressors);
CompressorSelectionChanged(pCompressors, GetDlgItem(hwnd, IDC_VIDEOCOMPRESSORS));
pCompressors->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 library
hr = CoInitialize(NULL);
if (FAILED(hr))
goto error;
// create the convert object
hr = CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**) &g_pCapture);
if (FAILED(hr))
goto error;
DialogBox(g_hInstance, (LPCTSTR)IDD_COMPRESSORDLG, NULL, CompressorDlgProc);
error:
// cleanup
if (g_pCapture)
g_pCapture->Release();
CoUninitialize();
return 0;
}
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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.