avi_dialogs.cpp

Go to the documentation of this file.
00001 #define _WIN32_DCOM 
00002 
00003 #include <windows.h>
00004 #include <atlbase.h>
00005 #include <stdio.h>
00006 #include <dshow.h>
00007 
00008 #include "avi_write.h"
00009 #include "avi_resource.h"
00010 
00011 extern void CreateCompressionFilter(IMoniker *pMoniker, BOOL dvPal);
00012 extern int bCompressed;
00013 
00014 void CentreDialogOnScreen(HWND hWnd){
00015  RECT rc;
00016  GetWindowRect(hWnd, &rc);
00017  SetWindowPos(hWnd, NULL,
00018     (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
00019     (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2,
00020     0, 0, SWP_NOSIZE | SWP_NOZORDER);
00021 }
00022 
00023 
00024 void OnInitDialog(HWND hDlg){
00025     HRESULT hr;
00026     ICreateDevEnum *pSysDevEnum = NULL;
00027     IEnumMoniker *pEnum = NULL;
00028     IMoniker *pMoniker = NULL;
00029     hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, 
00030         CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, 
00031         (void**)&pSysDevEnum);
00032     if (FAILED(hr))return;
00033     hr = pSysDevEnum->CreateClassEnumerator(
00034              CLSID_VideoCompressorCategory, &pEnum, 0);
00035     if (hr == S_OK) { // S_FALSE means nothing in this category.    
00036         while (S_OK == pEnum->Next(1, &pMoniker, NULL))    {
00037             IPropertyBag *pPropBag = NULL;
00038             pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
00039                 (void **)&pPropBag);
00040             VARIANT var;
00041             VariantInit(&var);
00042             hr = pPropBag->Read(L"FriendlyName", &var, 0);
00043             if (SUCCEEDED(hr)){
00044                USES_CONVERSION;
00045                 LRESULT iSel=SendDlgItemMessage(hDlg,IDC_LIST1,LB_ADDSTRING,0,
00046                 (LPARAM)OLE2T(var.bstrVal));
00047             }   
00048             VariantClear(&var); 
00049             pPropBag->Release();
00050             pMoniker->Release();
00051         }
00052     }
00053     SendDlgItemMessage(hDlg, IDC_LIST1, 
00054                        LB_SETCURSEL, 0, 0);
00055     pSysDevEnum->Release();
00056     pEnum->Release();
00057 }
00058 
00059 void OnSelectFilter(HWND hDlg){
00060     HRESULT hr;
00061     ICreateDevEnum *pSysDevEnum = NULL;
00062     IEnumMoniker *pEnum = NULL;
00063     IMoniker *pMoniker = NULL;
00064     int id;
00065     char item_list[256];
00066     BOOL bPal=FALSE;
00067     id=(int)SendDlgItemMessage(hDlg, IDC_LIST1, 
00068                        LB_GETCURSEL, 0, 0);
00069     SendDlgItemMessage(hDlg, IDC_LIST1,LB_GETTEXT,  
00070                        (WPARAM)id,(LPARAM)(LPCTSTR)item_list);
00071     hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, 
00072         CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, 
00073         (void**)&pSysDevEnum);
00074     if (FAILED(hr))return;
00075     hr = pSysDevEnum->CreateClassEnumerator(
00076              CLSID_VideoCompressorCategory, &pEnum, 0);
00077     if (hr == S_OK){  // S_FALSE means nothing in this category.
00078         while (S_OK == pEnum->Next(1, &pMoniker, NULL))        {
00079             IPropertyBag *pPropBag = NULL;
00080             pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
00081                 (void **)&pPropBag);
00082             VARIANT var;
00083             VariantInit(&var);
00084             hr = pPropBag->Read(L"FriendlyName", &var, 0);
00085             if (SUCCEEDED(hr)){
00086                USES_CONVERSION;
00087                if(strcmp(OLE2T(var.bstrVal),item_list) == 0){
00088                   if(strcmp(item_list,"DV Video Encoder") == 0)bPal=TRUE;
00089                   //if(bPal)MessageBox(NULL,item_list,OLE2T(var.bstrVal),MB_OK);
00090                   CreateCompressionFilter(pMoniker,bPal);
00091                   VariantClear(&var); 
00092                   pPropBag->Release();
00093                   pMoniker->Release();
00094                   break;
00095                }
00096             }   
00097             VariantClear(&var); 
00098             pPropBag->Release();
00099             pMoniker->Release();
00100         }
00101     }
00102     SendDlgItemMessage(hDlg, IDC_LIST1, 
00103                        LB_SETCURSEL, 0, 0);
00104     pSysDevEnum->Release();
00105     pEnum->Release();
00106 }
00107 
00108 
00109  
00110 static BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,
00111                                    WPARAM wparam,LPARAM lparam){
00112  switch( msg ) {
00113    case WM_INITDIALOG:
00114      OnInitDialog(hwnd);
00115      CentreDialogOnScreen(hwnd);
00116      if(bCompressed)SendDlgItemMessage(hwnd,IDC_CHECK1,BM_SETCHECK,TRUE,0);
00117      return (TRUE);
00118    case WM_DESTROY:
00119      break;
00120    case WM_DRAWITEM:
00121      return TRUE;
00122    case WM_PAINT:
00123      break;
00124    case WM_COMMAND:
00125       switch(LOWORD(wparam)){
00126         case IDCANCEL:
00127           EndDialog(hwnd,FALSE);
00128           return(TRUE);
00129         case IDOK:
00130           if(IsDlgButtonChecked(hwnd,IDC_CHECK1) == BST_CHECKED) bCompressed=TRUE;
00131           else bCompressed=FALSE; 
00132           OnSelectFilter(hwnd);
00133           EndDialog(hwnd,TRUE);
00134           return(TRUE);
00135         default:
00136           break;
00137       }
00138       break;
00139     default: break;
00140  }
00141  return(FALSE);
00142 }
00143 
00144 BOOL DoDialog(HINSTANCE hInstance, HWND hWnd){
00145  return (BOOL)DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),hWnd,
00146             (DLGPROC)DlgProc,(LPARAM)1);
00147 }

Generated on Sun Apr 27 14:20:13 2014 for OpenFX by  doxygen 1.5.6