The following code demonstrates an advanced capture application. It utilizes most of the functions available in the ltmfCapture object.
// include the LEAD Media Foundation TOOLKIT header#include "ltmf.h"#include "resource.h"#include <tchar.h>#include <stdio.h>#include <olectl.h>#include <math.h>#include <assert.h>#define SZ_WNDCLASS_CAPTURE _T("CAPTURE WNDCLASS")#define WM_CAPTURENOTIFY (WM_USER + 1000)HINSTANCE g_hInstance; // application instance handleHWND g_hwndCapture; // video frame windowIltmfCapture* g_pCapture; // capture object interface pointer//// FreeTarget// resets target and free asssociated resources//void FreeTarget(void){long type;VARIANT var;g_pCapture->get_TargetType(&type);if(type == ltmfCapture_Target_File){g_pCapture->ResetTarget();}}//// SnapFrameToVideo// resizes the frame window to match the video width and height//void SnapFrameToVideo(void){HWND hwnd;RECT rcWindow, rcClient;long cx, cy;// get the frame windowg_pCapture->get_VideoWindowFrame((long*) &hwnd);// get the video dimensionsg_pCapture->get_VideoWidth(&cx);g_pCapture->get_VideoHeight(&cy);// adjust by the border dimensionsGetWindowRect(hwnd, &rcWindow);GetClientRect(hwnd, &rcClient);cx += ((rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left));cy += ((rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top));// resize the windowSetWindowPos(hwnd, NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER);}//// CaptureWndProc// video frame window procedure//LRESULT CALLBACK CaptureWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){VARIANT_BOOL f;HRESULT hr;HGLOBAL hDIB;IPictureDisp* pPictureDisp;BSTR bstr;IltmfDevices* pDevices;long index;long l;long l2;BOOL fActive;ltmfSizeMode sm;TCHAR sz[2048];LPTSTR p;double d;VARIANT var;long x, y, cx, cy;RECT rc;POINT pt;switch (message){case WM_CREATE:g_hwndCapture = hwnd;// window is the video window frameg_pCapture->put_VideoWindowFrame((long) hwnd);// want notification messages as wellg_pCapture->SetNotifyWindow((long) hwnd, WM_CAPTURENOTIFY);// set preview source video onlyg_pCapture->put_PreviewSource(ltmfCapture_Preview_Video);// enable previewg_pCapture->put_Preview(VARIANT_TRUE);// assign initial frame delayg_pCapture->put_FrameDelay(1.0);// assign a target filebstr = SysAllocString(L"c:\\target.mp4");g_pCapture->put_TargetFile(bstr);SysFreeString(bstr);// set output format to MP4g_pCapture->put_TargetFormat(ltmfCapture_TargetFormat_MP4);#ifdef _DEBUG{long v;g_pCapture->get_TargetFormat(&v);assert(v == ltmfCapture_TargetFormat_MP4);}#endif// get target formatIltmfTargetFormats* pTargetFormats;IltmfTargetFormat* pTargetFormat;g_pCapture->get_TargetFormats(&pTargetFormats);long v;pTargetFormats->get_Selection(&v);pTargetFormats->Item(v, &pTargetFormat);pTargetFormats->Release();// get target video formatsIltmfTargetVideoFormats* pTargetVideoFormats;pTargetFormat->get_VideoFormats(&pTargetVideoFormats);// select the H264 target video formatbstr = SysAllocString(L"{34363248-0000-0010-8000-00AA00389B71}");pTargetVideoFormats->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// video target format isn't registeredpTargetFormat->Release();pTargetVideoFormats->Release();return E_FAIL;}pTargetVideoFormats->put_Selection(index);pTargetVideoFormats->Release();// get target audio formatsIltmfTargetAudioFormats* pTargetAudioFormats;pTargetFormat->get_AudioFormats(&pTargetAudioFormats);// select the AAC target audio formatbstr = SysAllocString(L"{00001610-0000-0010-8000-00AA00389B71}");pTargetAudioFormats->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// audio target format isn't registeredpTargetFormat->Release();pTargetAudioFormats->Release();return E_FAIL;}pTargetAudioFormats->put_Selection(index);pTargetAudioFormats->Release();pTargetFormat->Release();// 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();SnapFrameToVideo();return 0;break;case WM_CAPTURENOTIFY:switch(wParam){case ltmfCapture_Notify_Started:_stprintf(sz, _T("Started"));SetWindowText(hwnd, sz);break;case ltmfCapture_Notify_Complete:g_pCapture->get_Mode(&l);if(l == ltmfCapture_Mode_Still){_stprintf(sz, _T("Complete - [still]"));}else{g_pCapture->get_TargetType(&l);if(l == ltmfCapture_Target_File){g_pCapture->get_TargetFile(&bstr);_stprintf(sz, _T("Complete - [%ls]"), bstr);SysFreeString(bstr);}}SetWindowText(hwnd, sz);break;case ltmfCapture_Notify_ErrorAbort:_stprintf(sz, _T("Error 0x%.8X. Capture stopped."), lParam);MessageBox(hwnd, sz, _T("Play"), MB_ICONEXCLAMATION | MB_OK);break;case ltmfCapture_Notify_Progress:p = sz;*p = _T('\0');hr = g_pCapture->get_NumDropped(&l);if(SUCCEEDED(hr)){if(p != sz)p += _stprintf(p, _T(", "));p += _stprintf(p, _T("Dropped: %d"), l);}hr = g_pCapture->get_NumNotDropped(&l);if(SUCCEEDED(hr)){if(p != sz)p += _stprintf(p, _T(", "));p += _stprintf(p, _T("Not Dropped: %d"), l);}hr = g_pCapture->get_AverageFrameSize(&l);if(SUCCEEDED(hr)){if(p != sz)p += _stprintf(p, _T(", "));p += _stprintf(p, _T("Frame Size: %d"), l);}g_pCapture->get_Mode(&l);if(l != ltmfCapture_Mode_Still || l != ltmfCapture_Mode_ManualFrames){// only display the capture time for free running captureshr = g_pCapture->get_CaptureTime(&d);if(SUCCEEDED(hr)){if(p != sz)p += _stprintf(p, _T(", "));p += _stprintf(p, _T("Time: %f"), d);}}SetWindowText(hwnd, sz);break;}return 0;break;case WM_KEYDOWN:if(wParam == VK_ESCAPE){// if fullscreen mode then exit itg_pCapture->get_FullScreenMode(&f);if(f){g_pCapture->put_FullScreenMode(VARIANT_FALSE);return 0;}}break;case WM_DESTROY:FreeTarget();// no video frameg_pCapture->put_VideoWindowFrame((long) NULL);// no more notificationsg_pCapture->SetNotifyWindow((long) NULL, 0);PostQuitMessage(0);break;case WM_INITMENUPOPUP:if(GetSubMenu(GetMenu(hwnd), 0) == (HMENU)wParam){// determine whether the object is activeg_pCapture->get_State(&l);fActive = (l == ltmfCapture_State_Pending || l == ltmfCapture_State_Running);// enable stop if activeEnableMenuItem((HMENU) wParam, ID_CONTROL_STOPCAPTURE, fActive ? MF_ENABLED : MF_GRAYED);// enable run if pausedEnableMenuItem((HMENU) wParam, ID_CONTROL_RUN, (l == ltmfCapture_State_Paused) ? MF_ENABLED : MF_GRAYED);// enable pause if running or pendingEnableMenuItem((HMENU) wParam, ID_CONTROL_PAUSE, (l == ltmfCapture_State_Running || l == ltmfCapture_State_Pending) ? MF_ENABLED : MF_GRAYED);// can perform normal capture?g_pCapture->IsModeAvailable(ltmfCapture_Mode_VideoOrAudio, &f);EnableMenuItem((HMENU) wParam, ID_CONTROL_STARTCAPTURE, f ? MF_ENABLED : MF_GRAYED);// can perform auto frame capture?g_pCapture->IsModeAvailable(ltmfCapture_Mode_AutoFrames, &f);EnableMenuItem((HMENU) wParam, ID_CONTROL_CAPTUREAUTOFRAMES, f ? MF_ENABLED : MF_GRAYED);// can perform manual frame capture?g_pCapture->IsModeAvailable(ltmfCapture_Mode_ManualFrames, &f);EnableMenuItem((HMENU) wParam, ID_CONTROL_CAPTUREMANUALFRAMES, f ? MF_ENABLED : MF_GRAYED);// can perform still image capture?g_pCapture->IsModeAvailable(ltmfCapture_Mode_Still, &f);EnableMenuItem((HMENU) wParam, ID_CONTROL_CAPTUREDIB, f ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_CAPTUREPICTURE, f ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_GETSTILLDIB, f ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_GETSTILLPICTURE, f ? MF_ENABLED : MF_GRAYED);// check the current video size modeg_pCapture->get_VideoWindowSizeMode(&sm);CheckMenuItem((HMENU) wParam, ID_CONTROL_FITTOWINDOW, (sm == ltmfFit) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_STRETCHTOWINDOW, (sm == ltmfStretch) ? MF_CHECKED : MF_UNCHECKED);// check previewg_pCapture->get_Preview(&f);CheckMenuItem((HMENU) wParam, ID_CONTROL_PREVIEW, f ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_PREVIEW, !fActive ? MF_ENABLED : MF_GRAYED);// check preview audiog_pCapture->get_PreviewSource(&l);CheckMenuItem((HMENU) wParam, ID_CONTROL_PREVIEWVIDEOANDAUDIO, (l == ltmfCapture_Preview_VideoAndAudio) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_PREVIEWVIDEOANDAUDIO, !fActive ? MF_ENABLED : MF_GRAYED);// check frame rateg_pCapture->get_UseFrameRate(&f);g_pCapture->get_FrameRate(&d);CheckMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_DEFAULT, (!f) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_15FPS, (f && fabs(d - 15.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_30FPS, (f && fabs(d - 30.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_DEFAULT, (!fActive) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_15FPS, (!fActive) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_FRAMERATE_30FPS, (!fActive) ? MF_ENABLED : MF_GRAYED);// check time limitg_pCapture->get_UseTimeLimit(&f);g_pCapture->get_TimeLimit(&d);CheckMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_NONE, (!f) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_15SEC, (f && fabs(d - 15.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_30SEC, (f && fabs(d - 30.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_NONE, (!fActive) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_15SEC, (!fActive) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TIMELIMIT_30SEC, (!fActive) ? MF_ENABLED : MF_GRAYED);// check frame delayg_pCapture->get_FrameDelay(&d);CheckMenuItem((HMENU) wParam, ID_CONTROL_FRAMEDELAY_1SEC, (fabs(d - 1.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_FRAMEDELAY_5SEC, (fabs(d - 5.0) < 0.1) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_FRAMEDELAY_1SEC, (!fActive) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_FRAMEDELAY_5SEC, (!fActive) ? MF_ENABLED : MF_GRAYED);// check targetg_pCapture->get_TargetType(&l);CheckMenuItem((HMENU) wParam, ID_CONTROL_TARGET_FILE, (l == ltmfCapture_Target_File) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TARGET_FILE, (!fActive) ? MF_ENABLED : MF_GRAYED);// check target formatg_pCapture->get_TargetFormat(&l);g_pCapture->get_TargetType(&l2);CheckMenuItem((HMENU) wParam, ID_CONTROL_TARGETFORMAT_MP4, (l == ltmfCapture_TargetFormat_MP4) ? MF_CHECKED : MF_UNCHECKED);CheckMenuItem((HMENU) wParam, ID_CONTROL_TARGETFORMAT_WMV, (l == ltmfCapture_TargetFormat_WMV) ? MF_CHECKED : MF_UNCHECKED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TARGETFORMAT_MP4, (!fActive && l2 == ltmfCapture_Target_File) ? MF_ENABLED : MF_GRAYED);EnableMenuItem((HMENU) wParam, ID_CONTROL_TARGETFORMAT_WMV, (!fActive && l2 == ltmfCapture_Target_File) ? MF_ENABLED : MF_GRAYED);// check properties previewg_pCapture->get_ShowDialogPreview(&f);CheckMenuItem((HMENU) wParam, ID_CONTROL_PROPERTIESPREVIEW, (f) ? MF_CHECKED : MF_UNCHECKED);}break;case WM_COMMAND:switch(LOWORD(wParam)){case ID_CONTROL_FITTOWINDOW:// fit the video to the windowg_pCapture->put_VideoWindowSizeMode(ltmfFit);return 0;break;case ID_CONTROL_STRETCHTOWINDOW:// stretch the video to the windowg_pCapture->put_VideoWindowSizeMode(ltmfStretch);return 0;break;case ID_CONTROL_FULLSCREEN:// toggle fullscreen modeg_pCapture->ToggleFullScreenMode();return 0;break;case ID_CONTROL_PREVIEW:// toggle previewg_pCapture->TogglePreview();return 0;break;case ID_CONTROL_PREVIEWVIDEOANDAUDIO:// toggle audio previewg_pCapture->get_PreviewSource(&l);if(l == ltmfCapture_Preview_VideoAndAudio)g_pCapture->put_PreviewSource(ltmfCapture_Preview_Video);elseg_pCapture->put_PreviewSource(ltmfCapture_Preview_VideoAndAudio);return 0;break;case ID_CONTROL_STOPCAPTURE:// stop capturingg_pCapture->StopCapture();return 0;break;case ID_CONTROL_STARTCAPTURE:// ready capture to eliminate start delayshr = g_pCapture->ReadyCapture(ltmfCapture_Mode_VideoOrAudio);if(SUCCEEDED(hr)){if(MessageBox(hwnd, _T("Ready to capture. Click 'ok' to start."), _T("Capture"), MB_OKCANCEL) == IDOK){// start capturingg_pCapture->StartCapture(ltmfCapture_Mode_VideoOrAudio);}else{// cancel captureg_pCapture->StopCapture();}}return 0;break;case ID_CONTROL_RUN:// run the capture graphg_pCapture->RunCapture();return 0;break;case ID_CONTROL_PAUSE:// pause the capture graphg_pCapture->PauseCapture();return 0;break;case ID_CONTROL_CAPTUREAUTOFRAMES:hr = g_pCapture->ReadyCapture(ltmfCapture_Mode_AutoFrames);if(SUCCEEDED(hr)){// start capturing automatic frame sequenceg_pCapture->StartCapture(ltmfCapture_Mode_AutoFrames);}return 0;break;case ID_CONTROL_CAPTUREMANUALFRAMES:hr = g_pCapture->ReadyCapture(ltmfCapture_Mode_ManualFrames);if(SUCCEEDED(hr)){// start capturing automatic frame sequencehr = g_pCapture->StartCapture(ltmfCapture_Mode_ManualFrames);if(SUCCEEDED(hr)){while(MessageBox(hwnd, _T("Press 'ok' to capture frame."), _T("Capture Manual Frames"), MB_OKCANCEL) == IDOK)g_pCapture->CaptureFrame();g_pCapture->StopCapture();}}return 0;break;case ID_CONTROL_CAPTUREDIB:// capture device independent bitmaphr = g_pCapture->CaptureDIB((long*) &hDIB);if(SUCCEEDED(hr)){// copy to the clipboardOpenClipboard(hwnd);EmptyClipboard();SetClipboardData(CF_DIB, hDIB);CloseClipboard();}return 0;break;case ID_CONTROL_CAPTUREPICTURE:// capture ole picture objecthr = g_pCapture->CapturePicture(&pPictureDisp);if(SUCCEEDED(hr)){// save the picturebstr = SysAllocString(L"c:\\still.bmp");OleSavePictureFile(pPictureDisp, bstr);SysFreeString(bstr);pPictureDisp->Release();}return 0;break;case ID_CONTROL_GETSTILLDIB:// alternate method of capturing a device independent bitmaphr = g_pCapture->StartCapture(ltmfCapture_Mode_Still);if(SUCCEEDED(hr)){hr = g_pCapture->GetStillDIB(INFINITE, (long*) &hDIB);g_pCapture->StopCapture();if(SUCCEEDED(hr)){// copy to the clipboardOpenClipboard(hwnd);EmptyClipboard();SetClipboardData(CF_DIB, hDIB);CloseClipboard();}}return 0;break;case ID_CONTROL_GETSTILLPICTURE:// alternate method of capturing an ole picture objecthr = g_pCapture->StartCapture(ltmfCapture_Mode_Still);if(SUCCEEDED(hr)){hr = g_pCapture->GetStillPicture(INFINITE, &pPictureDisp);g_pCapture->StopCapture();if(SUCCEEDED(hr)){// save the picturebstr = SysAllocString(L"c:\\still.bmp");OleSavePictureFile(pPictureDisp, bstr);SysFreeString(bstr);pPictureDisp->Release();}}return 0;break;case ID_CONTROL_FRAMERATE_DEFAULT:// set rate to defaultg_pCapture->put_UseFrameRate(VARIANT_FALSE);return 0;break;case ID_CONTROL_FRAMERATE_15FPS:// set rate to 15 fpsg_pCapture->put_FrameRate(15.0);g_pCapture->put_UseFrameRate(VARIANT_TRUE);return 0;break;case ID_CONTROL_FRAMERATE_30FPS:// set rate to 30 fpsg_pCapture->put_FrameRate(30.0);g_pCapture->put_UseFrameRate(VARIANT_TRUE);return 0;break;case ID_CONTROL_TIMELIMIT_NONE:// no time limitg_pCapture->put_UseTimeLimit(VARIANT_FALSE);return 0;break;case ID_CONTROL_TIMELIMIT_15SEC:// 15 sec time limitg_pCapture->put_TimeLimit(15.0);g_pCapture->put_UseTimeLimit(VARIANT_TRUE);return 0;break;case ID_CONTROL_TIMELIMIT_30SEC:// 30 sec time limitg_pCapture->put_TimeLimit(30.0);g_pCapture->put_UseTimeLimit(VARIANT_TRUE);return 0;break;case ID_CONTROL_FRAMEDELAY_1SEC:// 1 sec frame delayg_pCapture->put_FrameDelay(1.0);return 0;break;case ID_CONTROL_FRAMEDELAY_5SEC:// 5 sec frame delayg_pCapture->put_FrameDelay(5.0);return 0;break;case ID_CONTROL_TARGET_FILE:// assign a target fileFreeTarget();// set output format to MP4g_pCapture->put_TargetFormat(ltmfCapture_TargetFormat_MP4);#ifdef _DEBUG{long v;g_pCapture->get_TargetFormat(&v);assert(v == ltmfCapture_TargetFormat_MP4);}#endif// get target formatIltmfTargetFormats* pTargetFormats;IltmfTargetFormat* pTargetFormat;g_pCapture->get_TargetFormats(&pTargetFormats);long v;pTargetFormats->get_Selection(&v);pTargetFormats->Item(v, &pTargetFormat);pTargetFormats->Release();// get target video formatsIltmfTargetVideoFormats* pTargetVideoFormats;pTargetFormat->get_VideoFormats(&pTargetVideoFormats);// select the H264 video target video formatbstr = SysAllocString(L"{34363248-0000-0010-8000-00AA00389B71}");pTargetVideoFormats->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// video target format isn't registeredpTargetFormat->Release();pTargetVideoFormats->Release();return E_FAIL;}pTargetVideoFormats->put_Selection(index);pTargetVideoFormats->Release();// get target audio formatsIltmfTargetAudioFormats* pTargetAudioFormats;pTargetFormat->get_AudioFormats(&pTargetAudioFormats);// select the AAC target audio formatbstr = SysAllocString(L"{00001610-0000-0010-8000-00AA00389B71}");pTargetAudioFormats->Find(bstr, &index);SysFreeString(bstr);if(index < 0){// audio target format isn't registeredpTargetFormat->Release();pTargetAudioFormats->Release();return E_FAIL;}pTargetAudioFormats->put_Selection(index);pTargetAudioFormats->Release();pTargetFormat->Release();return 0;break;case ID_CONTROL_TARGETFORMAT_MP4:// is target a file?g_pCapture->get_TargetType(&l);if(l == ltmfCapture_Target_File){// rename itbstr = SysAllocString(L"c:\\target.mp4");g_pCapture->put_TargetFile(bstr);SysFreeString(bstr);}g_pCapture->put_TargetFormat(ltmfCapture_TargetFormat_MP4);return 0;break;case ID_CONTROL_TARGETFORMAT_WMV:// is target a file?g_pCapture->get_TargetType(&l);if(l == ltmfCapture_Target_File){// rename itbstr = SysAllocString(L"c:\\target.wmv");g_pCapture->put_TargetFile(bstr);SysFreeString(bstr);}g_pCapture->put_TargetFormat(ltmfCapture_TargetFormat_WMV);return 0;break;case ID_CONTROL_AUDIOPROCESSORS:// edit audio processorsg_pCapture->ShowDialog(ltmfCapture_Dlg_AudioProcessors, (long) hwnd);return 0;break;case ID_CONTROL_VIDEOPROCESSORS:// edit video processorsg_pCapture->ShowDialog(ltmfCapture_Dlg_VideoProcessors, (long) hwnd);return 0;break;case ID_CONTROL_PROPERTIESPREVIEW:// toggle preview while editing propertiesg_pCapture->get_ShowDialogPreview(&f);g_pCapture->put_ShowDialogPreview(f ? VARIANT_FALSE : VARIANT_TRUE);return 0;break;}break;case WM_LBUTTONDOWN:g_pCapture->get_State(&l);if(l != ltmfCapture_State_Pending || l != ltmfCapture_State_Running){g_pCapture->get_VideoWindowLeft(&x);g_pCapture->get_VideoWindowTop(&y);g_pCapture->get_VideoWindowWidth(&cx);g_pCapture->get_VideoWindowHeight(&cy);SetRect(&rc, x, y, x + cx, y + cy);pt.x = (short) LOWORD(lParam);pt.y = (short) HIWORD(lParam);if(PtInRect(&rc, pt)){// set target format propertiesg_pCapture->ShowDialog(ltmfCapture_Dlg_TargetFormat, (long) hwnd);}}return 0;break;}return DefWindowProc(hwnd, message, wParam, lParam);}int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){MSG msg;HRESULT hr;WNDCLASSEX wcex;g_hInstance = hInstance;// initialize COM libraryhr = CoInitialize(NULL);if(FAILED(hr))goto error;// register the video frame window classwcex.cbSize = sizeof(WNDCLASSEX);wcex.style = CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc = CaptureWndProc;wcex.cbClsExtra = 0;wcex.cbWndExtra = 0;wcex.hInstance = g_hInstance;wcex.hIcon = NULL;wcex.hCursor = LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1);wcex.lpszMenuName = (LPCWSTR)IDR_MENU;wcex.lpszClassName = SZ_WNDCLASS_CAPTURE;wcex.hIconSm = NULL;if(!RegisterClassEx(&wcex))goto error;// create the capture objecthr = CoCreateInstance(CLSID_ltmfCapture, NULL, CLSCTX_INPROC_SERVER, IID_IltmfCapture, (void**) &g_pCapture);if(FAILED(hr))goto error;// create the video frame windowif(!CreateWindow(SZ_WNDCLASS_CAPTURE, _T("Capture"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInstance, NULL))goto error;ShowWindow(g_hwndCapture, nCmdShow);UpdateWindow(g_hwndCapture);// process until donewhile (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}error:if(g_pCapture)g_pCapture->Release();CoUninitialize();return 0;}