Using AutoSize with ltmmPlay for C

The following example demonstrates automatically sizing the ltmmPlay 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_PLAY _T("PLAY WNDCLASS") 
#define WM_PLAYNOTIFY (WM_USER + 1000) 
 
HINSTANCE g_hInstance;  // application instance handle 
HWND g_hwndPlay; // video frame window 
IltmmPlay* g_pPlay; // play object interface pointer 
 
// 
// PlayWndProc 
// video frame window procedure 
// 
LRESULT CALLBACK PlayWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
   BSTR bstr; 
 
   switch (message)  
   { 
   case WM_CREATE: 
      g_hwndPlay = hwnd; 
 
      // window is the video window frame 
      IltmmPlay_put_VideoWindowFrame(g_pPlay, (long) hwnd); 
 
 
      // force the frame to size to the video 
 
      IltmmPlay_put_AutoSize(g_pPlay, VARIANT_TRUE); 
#ifdef _DEBUG 
      { 
         VARIANT_BOOL f; 
         IltmmPlay_get_AutoSize(g_pPlay, &f); 
         assert(f != 0); 
      } 
#endif 
      // make sure we start playing immediately 
 
      IltmmPlay_put_AutoStart(g_pPlay, VARIANT_TRUE); 
 
      // set the source file 
      bstr = SysAllocString((OLECHAR*)MAKE_MEDIA_PATH("source.avi")); 
      IltmmPlay_put_SourceFile(g_pPlay, bstr); 
      SysFreeString(bstr); 
 
 
      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   = PlayWndProc; 
   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_PLAY; 
   wcex.hIconSm      = NULL; 
 
   if(!RegisterClassEx(&wcex)) 
      goto error; 
 
 
   // create the play object 
   hr = CoCreateInstance(&CLSID_ltmmPlay, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmPlay, (void**) &g_pPlay); 
   if(FAILED(hr)) 
      goto error; 
 
   // create the video frame window 
   if(!CreateWindow(SZ_WNDCLASS_PLAY, _T("Play"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, g_hInstance, NULL)) 
      goto error; 
 
   ShowWindow(g_hwndPlay, nCmdShow); 
 
   UpdateWindow(g_hwndPlay); 
 
   // process until done 
   while (GetMessage(&msg, NULL, 0, 0))  
   { 
      TranslateMessage(&msg); 
      DispatchMessage(&msg); 
   } 
 
error: 
   if(g_pPlay) 
      IUnknown_Release(g_pPlay); 
 
   CoUninitialize(); 
 
   return 0;    
} 

Help Version 20.0.2019.3.12
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help