The following example demonstrates automatically sizing the ltmmCapture object’s video frame window to the actual size of the media.
// define helper macros for using interfaces under C
#ifndef COBJMACROS
#define COBJMACROS
#endif
// include the LEAD Multimedia TOOLKIT header
#include "ltmm.h"
#include "resource.h"
#include <tchar.h>
#include <stdio.h>
#include <assert.h>
#define SZ_WNDCLASS_CAPTURE _T("CAPTURE WNDCLASS")
#define WM_CAPTURENOTIFY (WM_USER + 1000)
HINSTANCE g_hInstance; // application instance handle
HWND g_hwndCapture; // video frame window
IltmmCapture* g_pCapture; // capture object interface pointer
//
// CaptureWndProc
// video frame window procedure
//
LRESULT CALLBACK CaptureWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
IltmmDevices* pDevices;
switch (message)
{
case WM_CREATE:
g_hwndCapture = hwnd;
// window is the video window frame
IltmmCapture_put_VideoWindowFrame(g_pCapture, (long) hwnd);
// force the frame window to be automatically resized to the video
IltmmCapture_put_AutoSize(g_pCapture, VARIANT_TRUE);
#ifdef _DEBUG
{
VARIANT_BOOL f;
IltmmCapture_get_AutoSize(g_pCapture, &f);
assert(f != 0);
}
#endif
// set preview source video only
IltmmCapture_put_PreviewSource(g_pCapture, ltmmCapture_Preview_Video);
// enable preview
IltmmCapture_put_Preview(g_pCapture, VARIANT_TRUE);
// preview is visible
IltmmCapture_put_PreviewVisible(g_pCapture, VARIANT_TRUE);
// select the first video device available
IltmmCapture_get_VideoDevices(g_pCapture, &pDevices);
IltmmDevices_put_Selection(pDevices, 0);
IUnknown_Release(pDevices);
return 0;
break;
case WM_DESTROY:
PostQuitMessage(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;
hPrevInstance = hPrevInstance ;
lpCmdLine = lpCmdLine ;
nCmdShow = nCmdShow ;
g_hInstance = hInstance;
// initialize COM library
hr = CoInitialize(NULL);
if(FAILED(hr))
goto error;
// register the video frame window class
wcex.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 = NULL;
wcex.lpszClassName = SZ_WNDCLASS_CAPTURE;
wcex.hIconSm = NULL;
if(!RegisterClassEx(&wcex))
goto error;
// create the capture object
hr = CoCreateInstance(&CLSID_ltmmCapture, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmCapture, (void**) &g_pCapture);
if(FAILED(hr))
goto error;
// create the video frame window
if(!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 done
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
error:
if(g_pCapture)
IUnknown_Release(g_pCapture);
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.