#include "ltmf.h"#include "resource.h"#include "tchar.h"#include "stdio.h"HINSTANCE g_hInstance;// application instance handleIltmfCapture* g_pCapture;// convert object's interface pointer//// BuildCaptureInputList// fills a listbox to match the contents of the collection//// pCaptureInputs = input collection's interface pointer// hwndListBox = listbox window handle//void BuildCaptureInputList(IltmfCaptureInputs* pCaptureInputs, HWND hwndListBox){long i;long count;int selected = -1;// reset the listbox contentsSendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);// get the collection's item countpCaptureInputs->get_Count(&count);for(i = 0; i < count; i++){IltmfCaptureInput* pCaptureInput;BSTR bstr;TCHAR sz[256];int index;VARIANT_BOOL f;// retrieve collection itempCaptureInputs->Item(i, &pCaptureInput);// get displayable namepCaptureInput->get_Name(&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 collectionpCaptureInput->get_Selected(&f);if(f)selected = i;// free the collection itempCaptureInput->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;}}}//// CaptureInputSelectionChanged// called to reflect changes in the listbox selection//// pCaptureInputs = input collection's interface pointer// hwndListBox = listbox window handle//void CaptureInputSelectionChanged(IltmfCaptureInputs* pCaptureInputs, 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 selectionpCaptureInputs->put_Selection(-1);}else{// get the collection item indexitem = (long) SendMessage(hwndListBox, LB_GETITEMDATA, index, 0);// select the item#ifdef _DEBUG{IltmfCaptureInput* pCaptureInput;pCaptureInputs->Item(item, &pCaptureInput);hr = pCaptureInput->put_Selected(VARIANT_TRUE);pCaptureInput->Release();}#elsehr = pCaptureInputs->put_Selection(item);#endif// if new selection failed, we need to force the listbox to match the actual selectionif(FAILED(hr)){// get the real selectionpCaptureInputs->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;}}}}}//// SelectCompositeVideo// selects composite video, if available//// pCaptureInputs = input collection's interface pointer// hwndListBox = listbox window handle//void SelectCompositeVideo(IltmfCaptureInputs* pCaptureInputs, HWND hwndListBox){long item;BSTR bstr;long i;long count;// Find the composite video inputbstr = SysAllocString(L"Video Composite");pCaptureInputs->Find(bstr, &item);SysFreeString(bstr);// make it the current selectionif(item >= 0){pCaptureInputs->put_Selection(item);pCaptureInputs->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;}}}}//// CaptureInputDlgProc// selects object inputs//BOOL CALLBACK CaptureInputDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){IltmfCaptureInputs* pCaptureInputs;switch (msg){case WM_INITDIALOG:// initialize the video input listboxg_pCapture->get_VideoInputs(&pCaptureInputs);BuildCaptureInputList(pCaptureInputs, GetDlgItem(hwnd, IDC_VIDEOINPUTS));pCaptureInputs->Release();return TRUE;break;case WM_COMMAND:switch(LOWORD(wParam)){case IDC_SELECTCOMPOSITEVIDEO:// select composite videog_pCapture->get_VideoInputs(&pCaptureInputs);SelectCompositeVideo(pCaptureInputs, GetDlgItem(hwnd, IDC_VIDEOINPUTS));pCaptureInputs->Release();return TRUE;break;case IDC_VIDEOINPUTS:if(HIWORD(wParam) == LBN_SELCHANGE){// select the video inputg_pCapture->get_VideoInputs(&pCaptureInputs);CaptureInputSelectionChanged(pCaptureInputs, GetDlgItem(hwnd, IDC_VIDEOINPUTS));pCaptureInputs->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;IltmfDevices* pDevices;g_hInstance = hInstance;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// create the capture objecthr = CoCreateInstance(CLSID_ltmfCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmfCapture, (void**) &g_pCapture);if(FAILED(hr))goto error;// select the first audio device availableg_pCapture->get_AudioDevices(&pDevices);pDevices->put_Selection(0);pDevices->Release();// select the first video device availableg_pCapture->get_VideoDevices(&pDevices);pDevices->put_Selection(0);pDevices->Release();DialogBox(g_hInstance, (LPCTSTR)IDD_INPUTDLG, NULL, CaptureInputDlgProc); error:// cleanupif(g_pCapture)g_pCapture->Release();CoUninitialize();return 0;}