home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / AutoPC / apcsdk10.exe / data1.cab / Win32_Samples / win32 / tuneit / tunesink.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-13  |  7.6 KB  |  317 lines

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     tunesink.cpp
  8.  
  9. Abstract:
  10.  
  11.     TuneIt AutoPC Sample Event Sink and Class Message Sink.
  12.  
  13. Environment:
  14.  
  15.     AutoPC
  16.  
  17. -------------------------------------------------------------------*/
  18.  
  19. // Standard APC includes
  20. #include <windows.h>
  21. #include <olectl.h>
  22. #include <asfc.h>           // AutoPC Forms Manager
  23. #include <ascmnctl.h>       // AutoPC Common Controls
  24. #include <keypad.h>
  25. #include <tunerapi.h>
  26. #include <apcaudio.h>
  27.  
  28. // Application specific includes
  29. #include "resource.h"
  30. #include "tuneit.h"
  31. #include "tunesink.h"
  32.  
  33. // Global App Class variable
  34. CTuneitApp * g_pApp;
  35.  
  36. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  37. Class:
  38.     CAppEventSink
  39.  
  40. Description:
  41.     Application sink.  A COM object that implements IUnknown, a token 
  42.     implementation of IDispatch, IASEventSink, and IASClassMsgSink.
  43. -------------------------------------------------------------------*/
  44.  
  45. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. Function:
  47.     CAppEventSink::QueryInterface
  48.  
  49. Description:
  50.     Standard COM IUknown method.  
  51.  
  52. Parameters:
  53.     REFIID - Reference to requested Interface GUID
  54.     PVOID * - Target for interface pointer.
  55.  
  56. Returns:
  57.     HRESULT - NOERROR on success.  Other error code on fail.
  58. -------------------------------------------------------------------*/
  59. STDMETHODIMP 
  60. CAppEventSink::QueryInterface(REFIID riid, PVOID *ppv)
  61. {
  62.     if (!ppv) return E_INVALIDARG;
  63.  
  64.     if (riid == IID_ASEVENTSINK) *ppv = (PVOID) (IASEventSink *) this; 
  65.     else if (riid == IID_ASCLASSMSGSINK) *ppv = (PVOID) (IASClassMsgSink *) this;
  66.     else if (riid == IID_IUnknown) *ppv = (PVOID) (IUnknown *) (IASEventSink *) this;
  67.     else if (riid == IID_IDispatch) *ppv = (PVOID) (IDispatch *) (IASEventSink *) this;
  68.     else return E_NOINTERFACE;
  69.  
  70.     AddRef();
  71.     return NOERROR;
  72. }
  73.  
  74. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  75. Function:
  76.     CAppEventSink::AddRef
  77.  
  78. Description:
  79.     Standard COM IUknown method.  Increases the reference count on
  80.     this object.
  81.  
  82. Parameters:
  83.     Nothing.
  84.  
  85. Returns:
  86.     ULONG - Reference count after increment.
  87. -------------------------------------------------------------------*/
  88. STDMETHODIMP_(ULONG) 
  89. CAppEventSink::AddRef()
  90. {
  91.     InterlockedIncrement(&m_cRef);
  92.     return m_cRef;         
  93. }
  94.  
  95. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  96. Function:
  97.     CAppEventSink::Release
  98.  
  99. Description:
  100.     Standard COM IUknown method.  Decrements reference count.  Frees
  101.     object when it is 0.
  102.  
  103. Parameters:
  104.     Nothing.
  105.  
  106. Returns:
  107.     ULONG - Reference count after decrement.
  108. -------------------------------------------------------------------*/
  109. STDMETHODIMP_(ULONG)
  110. CAppEventSink::Release()
  111. {
  112.     if (InterlockedDecrement(&m_cRef) > 0) return m_cRef;
  113.  
  114.     delete this;
  115.     return 0; 
  116. }            
  117.  
  118. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  119. Function:
  120.     CAppEventSink::ReceiveMsg
  121.  
  122. Description:
  123.     IASEventSink method attached to Form.
  124.  
  125. Parameters:
  126.     long - Win32 Message
  127.     long - Win32 Parameter
  128.     long - Win32 Parameter
  129.  
  130. Returns:
  131.     HRESULT - S_FALSE if message should continue down message path.
  132.               NOERROR if message should stop here
  133. -------------------------------------------------------------------*/
  134. STDMETHODIMP 
  135. CAppEventSink::ReceiveMsg(long uMsg, long wParam, long lParam)
  136. {
  137.     switch(uMsg)
  138.     {
  139.     default:
  140.         break;
  141.  
  142.  
  143.     // WM_COMMAND messages always have the Control ID in wParamLOW
  144.     case WM_COMMAND:
  145.         switch(LOWORD(wParam))
  146.         {
  147.         default:
  148.             break;
  149.     
  150.         case IDC_EDIT_PRESET:    // Message to preset edit control
  151.             if((HIWORD(wParam) == EN_CHANGE) &&                    // Contents changed
  152.                 (LOWORD(lParam) & ASFC_EDITNOTIFY_COMMITTED))    // And commited
  153.                 {
  154.                     g_pApp->DoneSetPreset(TRUE);    // Done setting preset, save it.
  155.                 }
  156.             break;
  157.  
  158.         case IDC_SETTINGS:        // Message to Settings Menu
  159.             if(HIWORD(wParam) == PLBN_SPINCHANGE)
  160.             {
  161.                 // PLBN_SPINCHANGE messge:    wParamHI - PLBN_SPINCHANGE,        wParamLOW - Controls ID
  162.                 //                            lParamHI - Menu Item ID,        lParamLOW - IntSpinner: value of item
  163.                 //                                                                        StringSpinner: Index of item
  164.                 switch(HIWORD(lParam))
  165.                 {
  166.                 default:
  167.                     break;
  168.  
  169.                 case ID_BAND:
  170.                     g_pApp->SetBand(LOWORD(lParam));
  171.                     break;
  172.                 
  173.                 case ID_BALANCE:
  174.                     g_pApp->SetBalance(LOWORD(lParam));
  175.                     break;
  176.  
  177.                 case ID_BASS:
  178.                     g_pApp->SetBass(LOWORD(lParam));
  179.                     break;
  180.  
  181.                 case ID_TREBLE:
  182.                     g_pApp->SetTreble(LOWORD(lParam));
  183.                     break;
  184.  
  185.                 case ID_FADE:
  186.                     g_pApp->SetFade(LOWORD(lParam));
  187.                     break;
  188.                 }
  189.             }
  190.         }        
  191.     } //end switch
  192.  
  193.     return S_FALSE;
  194. }
  195.  
  196. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  197. Function:
  198.     CAppEventSink::HandleMessage
  199.  
  200. Description:
  201.     IASClassMsgSink method attached to Forms Manager.  We use this
  202.     to grab key presses that we want to handle.  We also handle
  203.     WM_QUERYKEYUSAGE messages since our form intercepts arrow and 
  204.     enter keystrokes.
  205.  
  206. Parameters:
  207.     IDispatch * - Control interface sending message
  208.     long - Win32 Message
  209.     long - Win32 Parameter
  210.     long - Win32 Parameter
  211.  
  212. Returns:
  213.     HRESULT - S_FALSE if message should continue down message path.
  214.               NOERROR if message should stop here
  215. -------------------------------------------------------------------*/
  216. STDMETHODIMP
  217. CAppEventSink::HandleMessage(IDispatch* pdispControl, long uMsg, long wParam, long lParam)
  218. {
  219.     IQueryKeyUsage * pKeyUsage;
  220.  
  221.     switch(uMsg)
  222.     {
  223.     default:
  224.         break;
  225.  
  226.     case WM_QUERYKEYUSAGE:
  227.         // Message asking us what keys we are using.  Since we are handling WM_REMOTE_KEYDOWN 
  228.         // messages and VK_* we need to respond.
  229.         pKeyUsage = (IQueryKeyUsage*)lParam;
  230.  
  231.         if(g_pApp->IsPrimary())
  232.         {
  233.             // FlagKeysUsed( Keys Used by App, Keys Eaten by App )
  234.             // Basically means, Keys to add to default Nav Glyph, keys to block on default Nav Glyph
  235.             return pKeyUsage->FlagKeysUsed( QKU_VK_UP|QKU_VK_DOWN|QKU_VK_LEFT|QKU_VK_RIGHT, NULL);
  236.         }
  237.         break;
  238.  
  239.     // Currently, all keystrokes come in under WM_REMOTE_KEYDOWN messages
  240.     case WM_REMOTE_KEYDOWN:
  241.         {
  242.         switch(wParam)
  243.             {
  244.             default:
  245.                 break;
  246.  
  247.             // Always handle the volume up/down keys.
  248.             case VK_VOLUMEUP:
  249.                 g_pApp->VolumeUp();
  250.                 return NOERROR;        // Kill message here
  251.             case VK_VOLUMEDOWN:
  252.                 g_pApp->VolumeDown();
  253.                 return NOERROR;        // Kill message here
  254.             } //endswitch wparam
  255.  
  256.             // If we are in Primary state (Main view), handle some of the keys
  257.             if(g_pApp->IsPrimary())
  258.             {
  259.                 switch(wParam)
  260.                 {
  261.                 default:
  262.                     break;
  263.                 case VK_UP:
  264.                     g_pApp->TuneUp();
  265.                     break;
  266.                 case VK_DOWN:
  267.                     g_pApp->TuneDown();
  268.                     break;
  269.                 case VK_LEFT:
  270.                     g_pApp->PreviousPreset();
  271.                     break;
  272.                 case VK_RIGHT:
  273.                     g_pApp->NextPreset();
  274.                     break;
  275.                 case VK_RETURN:
  276.                     g_pApp->PreSetPreset();
  277.                     break;
  278.                 case VK_ESCAPE:
  279.                     PostThreadMessage(g_pApp->m_idThread, WM_QUIT, 0, 0);
  280.                     break;
  281.                 case VK_MENU:
  282.                     g_pApp->OnMenu();
  283.                     break;
  284.                 } //endswitch wParam
  285.             } //endif state=primary
  286.             else if(g_pApp->IsSetPreset())
  287.             {
  288.                 switch(wParam)
  289.                 {
  290.                 default:
  291.                     break;
  292.                 case VK_ESCAPE:    // handle this to keep our m_State accurate
  293.                     g_pApp->DoneSetPreset(FALSE);
  294.                     break;
  295.                 }
  296.             } //end else if
  297.             else if(g_pApp->IsSettings())
  298.             {    
  299.                 switch(wParam)
  300.                 {
  301.                 default:
  302.                     break;
  303.                 case VK_ESCAPE:
  304.                     g_pApp->DoneSettings();
  305.                     return NOERROR;
  306.                     
  307.                 case VK_MENU:
  308.                     g_pApp->DoneSettings();
  309.                     break;
  310.                 } //end switch(wParam)
  311.             } // end else if(g_pApp->IsSettings())
  312.         } //endcase WM_REMOTE_KEYDOWN
  313.     }  //endswitch uMsg
  314.  
  315.     return S_FALSE;
  316. }
  317.