home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / effprop.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  5.6 KB  |  256 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. //effprop.cpp
  13. //
  14.  
  15. #include <streams.h>
  16.  
  17. #include <windows.h>
  18. #include <windowsx.h>
  19. #include <commctrl.h>
  20. #include <olectl.h>
  21. #include <memory.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <tchar.h>
  25.  
  26. #include "resource.h"
  27. #include "ieffect.h"
  28. #include "effect.h"
  29. #include "effprop.h"
  30.  
  31. // *
  32. // * CEffectProperties
  33. // *
  34.  
  35.  
  36. //
  37. // CreateInstance
  38. //
  39. CUnknown *CEffectProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) {
  40.  
  41.     CUnknown *punk = new CEffectProperties(lpunk, phr);
  42.     if (punk == NULL) {
  43.     *phr = E_OUTOFMEMORY;
  44.     }
  45.  
  46.     return punk;
  47. }
  48.  
  49.  
  50. //
  51. // CEffectProperties::Constructor
  52. //
  53. CEffectProperties::CEffectProperties(LPUNKNOWN pUnk, HRESULT *phr)
  54.     : CBasePropertyPage(NAME("Effect Property Page"),pUnk,phr,
  55.         IDD_EFFECTPROP, IDS_TITLE)
  56.  
  57.     , m_pEffect(NULL)
  58.     , m_bIsInitialized(FALSE)
  59. {
  60.     InitCommonControls();
  61. }
  62.  
  63.  
  64.  
  65. //
  66. // SetDirty
  67. //
  68. // Sets m_hrDirtyFlag and notifies the property page site of the change
  69. //
  70. void CEffectProperties::SetDirty()
  71. {
  72.     m_bDirty = TRUE;
  73.     if (m_pPageSite)
  74.     {
  75.         m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  76.     }
  77. }
  78.  
  79.  
  80. BOOL CEffectProperties::OnReceiveMessage(HWND hwnd,
  81.                                         UINT uMsg,
  82.                                         WPARAM wParam,
  83.                                         LPARAM lParam)
  84. {
  85.     switch (uMsg)
  86.     {
  87.         case WM_INITDIALOG:
  88.         {
  89.             TCHAR   sz[60];
  90.  
  91.             SetSlider(GetDlgItem(hwnd, IDC_SLIDER), m_startLevel);
  92.             SetSlider(GetDlgItem(hwnd, IDC_SLIDER2), m_endLevel);
  93.  
  94.             _stprintf(sz, TEXT("%.2f"), m_length);
  95.             Edit_SetText(GetDlgItem(hwnd, IDC_LENGTH), sz);
  96.             _stprintf(sz, TEXT("%.2f"), m_start);
  97.             Edit_SetText(GetDlgItem(hwnd, IDC_START), sz);
  98.  
  99.             CheckRadioButton(hwnd, IDC_WIPEUP, IDC_BAND,
  100.                      m_effect + IDC_WIPEUP);
  101.  
  102.             return (LRESULT) 1;
  103.         }
  104.  
  105.         case WM_VSCROLL:
  106.         {
  107.             SetDirty();
  108.             return (LRESULT) 1;
  109.         }
  110.  
  111.         case WM_COMMAND:
  112.         {
  113.             if (m_bIsInitialized)
  114.             {
  115.                 switch (LOWORD(wParam))
  116.                 {
  117.                  case IDC_EFFECT:
  118.                  case IDC_START:
  119.                  case IDC_LENGTH:
  120.                  case IDC_WIPEUP:
  121.                  case IDC_WIPELEFT:    
  122.                  case IDC_IRIS:
  123.                  case IDC_BAND:
  124.                     SetDirty();
  125.                     break;
  126.                 }
  127.             }
  128.             return (LRESULT) 1;
  129.         }
  130.  
  131.         case WM_DESTROY:
  132.         {
  133.             return (LRESULT) 1;
  134.         }
  135.  
  136.     }
  137.     return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
  138. }
  139.  
  140. HRESULT CEffectProperties::OnConnect(IUnknown *pUnknown)
  141. {
  142.  
  143.     // Get IEffect interface
  144.  
  145.     ASSERT(m_pEffect == NULL);
  146.  
  147.     HRESULT hr = pUnknown->QueryInterface(IID_IEffect, (void **) &m_pEffect);
  148.     if (FAILED(hr))
  149.     {
  150.     return E_NOINTERFACE;
  151.     }
  152.  
  153.     ASSERT(m_pEffect);
  154.     pIEffect()->GetEffectParameters(&m_effect, &m_start, &m_length,
  155.                     &m_startLevel, &m_endLevel);
  156.  
  157.     m_bIsInitialized = FALSE ;
  158.  
  159.     return NOERROR;
  160. }
  161.  
  162. HRESULT CEffectProperties::OnDisconnect()
  163. {
  164.     // Release the interface
  165.  
  166.     if (m_pEffect == NULL)
  167.     {
  168.         return(E_UNEXPECTED);
  169.     }
  170.     m_pEffect->Release();
  171.     m_pEffect = NULL;
  172.     return NOERROR;
  173. }
  174.  
  175.  
  176. // We are being activated
  177.  
  178. HRESULT CEffectProperties::OnActivate()
  179. {
  180.     m_bIsInitialized = TRUE;
  181.     return NOERROR;
  182. }
  183.  
  184.  
  185. // We are being deactivated
  186.  
  187. HRESULT CEffectProperties::OnDeactivate(void)
  188. {
  189.     // remember present effect level for next Activate() call
  190.  
  191.     GetFromDialog();
  192.     return NOERROR;
  193. }
  194.  
  195.  
  196. //
  197. // SetSlider
  198. //
  199. // Set up the slider (common control) to allow the user to
  200. // adjust the effect
  201. HWND CEffectProperties::SetSlider(HWND hwndSlider, int iValue) {
  202.  
  203.     // Set the Range
  204.     SendMessage(hwndSlider, TBM_SETRANGE, TRUE, MAKELONG(0, 1000));
  205.  
  206.     // Set a tick at zero
  207.     SendMessage(hwndSlider, TBM_SETTIC, 0, 0);
  208.     SendMessage(hwndSlider, TBM_SETTIC, 0, 1000);
  209.  
  210.     //
  211.     // Set the slider position according to the value we obtain
  212.     // from initialisation or from the last Deactivate call.
  213.     //
  214.     SendMessage(hwndSlider, TBM_SETPOS, TRUE, iValue);
  215.  
  216.     return hwndSlider;
  217. }
  218.  
  219.  
  220. STDMETHODIMP CEffectProperties::GetFromDialog(void)
  221. {
  222.     TCHAR sz[60];
  223.  
  224.     Edit_GetText(GetDlgItem(m_hwnd, IDC_LENGTH), sz, 60);
  225.     m_length = COARefTime(atof(sz));
  226.  
  227.     Edit_GetText(GetDlgItem(m_hwnd, IDC_START), sz, 60);
  228.     m_start = COARefTime(atof(sz));
  229.  
  230.     m_startLevel = (int) SendMessage(GetDlgItem(m_hwnd, IDC_SLIDER),
  231.                        TBM_GETPOS, 0, 0L);
  232.     m_endLevel = (int) SendMessage(GetDlgItem(m_hwnd, IDC_SLIDER2),
  233.                        TBM_GETPOS, 0, 0L);
  234.  
  235.     for (int i = IDC_WIPEUP; i <= IDC_BAND; i++)
  236.         if (IsDlgButtonChecked(m_hwnd, i))
  237.             m_effect = i - IDC_WIPEUP;
  238.  
  239.     return NOERROR;
  240. }
  241.  
  242.  
  243. HRESULT CEffectProperties::OnApplyChanges()
  244. {
  245.     GetFromDialog();
  246.  
  247.     m_bDirty  = FALSE; // the page is now clean
  248.  
  249.     pIEffect()->SetEffectParameters(m_effect, m_start, m_length,
  250.                     m_startLevel, m_endLevel);
  251.  
  252.     return(NOERROR);
  253.  
  254. }
  255.  
  256.