The following example shows how to enumerate and select ltmmCapture object sizes.
#include "ltmm.h"#include "resource.h"#include "tchar.h"#include "stdio.h"HINSTANCE g_hInstance; // application instance handleIltmmCapture* g_pCapture; // capture object's interface pointer//// BuildSizeList// fills a listbox to match the contents of the collection//// pSizes = size collection's interface pointer// hwndListBox = listbox window handle//void BuildSizeList(IltmmCaptureSizes* pSizes, HWND hwndListBox){long i;long count;int selected = -1;// reset the listbox contentsSendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);// get the collection's item countpSizes->get_Count(&count);for(i = 0; i < count; i++){IltmmCaptureSize* pSize;TCHAR sz[256];int index;VARIANT_BOOL f;long width;long height;// retrieve collection itempSizes->Item(i, &pSize);// get displayable namepSize->get_Width(&width);pSize->get_Height(&height);_stprintf(sz, _T("%d x %d"), width, height);// 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 collectionpSize->get_Selected(&f);if(f)selected = i;// free the collection itempSize->Release();}// 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;}}}//// SizeSelectionChanged// called to reflect changes in the listbox selection//// pSizes = size collection's interface pointer// hwndListBox = listbox window handle//void SizeSelectionChanged(IltmmCaptureSizes* pSizes, 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){// get the collection item indexitem = (long) SendMessage(hwndListBox, LB_GETITEMDATA, index, 0);// select the item#ifdef _DEBUG{IltmmCaptureSize* pSize;pSizes->Item(item, &pSize);hr = pSize->put_Selected(VARIANT_TRUE);pSize->Release();}#elsehr = pSizes->put_Selection(item);#endif// if new selection failed, we need to force the listbox to match the actual selectionif(FAILED(hr)){// get the real selectionpSizes->get_Selection(&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;}}}}}//// SizeDlgProc// selects object sizes//BOOL CALLBACK SizeDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){IltmmDevices* pDevices;IltmmCaptureSizes* pSizes;long index;switch (msg){case WM_INITDIALOG:// select the first video capture deviceg_pCapture->get_VideoDevices( &pDevices);pDevices->put_Selection( 0);pDevices->Release();g_pCapture->get_VideoCaptureSizes(&pSizes);// setup an initial size of 320 x 240pSizes->Find( 320, 240, &index);pSizes->put_Selection(index);// initialize the video size listboxBuildSizeList(pSizes, GetDlgItem(hwnd, IDC_CAPTURESIZES));pSizes->Release();return TRUE;break;case WM_COMMAND:switch(LOWORD(wParam)){case IDC_CAPTURESIZES:if(HIWORD(wParam) == LBN_SELCHANGE){// select the video sizeg_pCapture->get_VideoCaptureSizes(&pSizes);SizeSelectionChanged(pSizes, GetDlgItem(hwnd, IDC_CAPTURESIZES));pSizes->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 convert objecthr = CoCreateInstance(CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmmCapture, (void**) &g_pCapture);if(FAILED(hr))goto error;DialogBox(g_hInstance, (LPCTSTR)IDD_SIZEDLG, NULL, SizeDlgProc);error:// cleanupif(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
