home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- tunesink.cpp
-
- Abstract:
-
- TuneIt AutoPC Sample Event Sink and Class Message Sink.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
-
- // Standard APC includes
- #include <windows.h>
- #include <olectl.h>
- #include <asfc.h> // AutoPC Forms Manager
- #include <ascmnctl.h> // AutoPC Common Controls
- #include <keypad.h>
- #include <tunerapi.h>
- #include <apcaudio.h>
-
- // Application specific includes
- #include "resource.h"
- #include "tuneit.h"
- #include "tunesink.h"
-
- // Global App Class variable
- CTuneitApp * g_pApp;
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Class:
- CAppEventSink
-
- Description:
- Application sink. A COM object that implements IUnknown, a token
- implementation of IDispatch, IASEventSink, and IASClassMsgSink.
- -------------------------------------------------------------------*/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::QueryInterface
-
- Description:
- Standard COM IUknown method.
-
- Parameters:
- REFIID - Reference to requested Interface GUID
- PVOID * - Target for interface pointer.
-
- Returns:
- HRESULT - NOERROR on success. Other error code on fail.
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppEventSink::QueryInterface(REFIID riid, PVOID *ppv)
- {
- if (!ppv) return E_INVALIDARG;
-
- if (riid == IID_ASEVENTSINK) *ppv = (PVOID) (IASEventSink *) this;
- else if (riid == IID_ASCLASSMSGSINK) *ppv = (PVOID) (IASClassMsgSink *) this;
- else if (riid == IID_IUnknown) *ppv = (PVOID) (IUnknown *) (IASEventSink *) this;
- else if (riid == IID_IDispatch) *ppv = (PVOID) (IDispatch *) (IASEventSink *) this;
- else return E_NOINTERFACE;
-
- AddRef();
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::AddRef
-
- Description:
- Standard COM IUknown method. Increases the reference count on
- this object.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CAppEventSink::AddRef()
- {
- InterlockedIncrement(&m_cRef);
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::Release
-
- Description:
- Standard COM IUknown method. Decrements reference count. Frees
- object when it is 0.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after decrement.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CAppEventSink::Release()
- {
- if (InterlockedDecrement(&m_cRef) > 0) return m_cRef;
-
- delete this;
- return 0;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::ReceiveMsg
-
- Description:
- IASEventSink method attached to Form.
-
- Parameters:
- long - Win32 Message
- long - Win32 Parameter
- long - Win32 Parameter
-
- Returns:
- HRESULT - S_FALSE if message should continue down message path.
- NOERROR if message should stop here
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppEventSink::ReceiveMsg(long uMsg, long wParam, long lParam)
- {
- switch(uMsg)
- {
- default:
- break;
-
-
- // WM_COMMAND messages always have the Control ID in wParamLOW
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- default:
- break;
-
- case IDC_EDIT_PRESET: // Message to preset edit control
- if((HIWORD(wParam) == EN_CHANGE) && // Contents changed
- (LOWORD(lParam) & ASFC_EDITNOTIFY_COMMITTED)) // And commited
- {
- g_pApp->DoneSetPreset(TRUE); // Done setting preset, save it.
- }
- break;
-
- case IDC_SETTINGS: // Message to Settings Menu
- if(HIWORD(wParam) == PLBN_SPINCHANGE)
- {
- // PLBN_SPINCHANGE messge: wParamHI - PLBN_SPINCHANGE, wParamLOW - Controls ID
- // lParamHI - Menu Item ID, lParamLOW - IntSpinner: value of item
- // StringSpinner: Index of item
- switch(HIWORD(lParam))
- {
- default:
- break;
-
- case ID_BAND:
- g_pApp->SetBand(LOWORD(lParam));
- break;
-
- case ID_BALANCE:
- g_pApp->SetBalance(LOWORD(lParam));
- break;
-
- case ID_BASS:
- g_pApp->SetBass(LOWORD(lParam));
- break;
-
- case ID_TREBLE:
- g_pApp->SetTreble(LOWORD(lParam));
- break;
-
- case ID_FADE:
- g_pApp->SetFade(LOWORD(lParam));
- break;
- }
- }
- }
- } //end switch
-
- return S_FALSE;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::HandleMessage
-
- Description:
- IASClassMsgSink method attached to Forms Manager. We use this
- to grab key presses that we want to handle. We also handle
- WM_QUERYKEYUSAGE messages since our form intercepts arrow and
- enter keystrokes.
-
- Parameters:
- IDispatch * - Control interface sending message
- long - Win32 Message
- long - Win32 Parameter
- long - Win32 Parameter
-
- Returns:
- HRESULT - S_FALSE if message should continue down message path.
- NOERROR if message should stop here
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppEventSink::HandleMessage(IDispatch* pdispControl, long uMsg, long wParam, long lParam)
- {
- IQueryKeyUsage * pKeyUsage;
-
- switch(uMsg)
- {
- default:
- break;
-
- case WM_QUERYKEYUSAGE:
- // Message asking us what keys we are using. Since we are handling WM_REMOTE_KEYDOWN
- // messages and VK_* we need to respond.
- pKeyUsage = (IQueryKeyUsage*)lParam;
-
- if(g_pApp->IsPrimary())
- {
- // FlagKeysUsed( Keys Used by App, Keys Eaten by App )
- // Basically means, Keys to add to default Nav Glyph, keys to block on default Nav Glyph
- return pKeyUsage->FlagKeysUsed( QKU_VK_UP|QKU_VK_DOWN|QKU_VK_LEFT|QKU_VK_RIGHT, NULL);
- }
- break;
-
- // Currently, all keystrokes come in under WM_REMOTE_KEYDOWN messages
- case WM_REMOTE_KEYDOWN:
- {
- switch(wParam)
- {
- default:
- break;
-
- // Always handle the volume up/down keys.
- case VK_VOLUMEUP:
- g_pApp->VolumeUp();
- return NOERROR; // Kill message here
- case VK_VOLUMEDOWN:
- g_pApp->VolumeDown();
- return NOERROR; // Kill message here
- } //endswitch wparam
-
- // If we are in Primary state (Main view), handle some of the keys
- if(g_pApp->IsPrimary())
- {
- switch(wParam)
- {
- default:
- break;
- case VK_UP:
- g_pApp->TuneUp();
- break;
- case VK_DOWN:
- g_pApp->TuneDown();
- break;
- case VK_LEFT:
- g_pApp->PreviousPreset();
- break;
- case VK_RIGHT:
- g_pApp->NextPreset();
- break;
- case VK_RETURN:
- g_pApp->PreSetPreset();
- break;
- case VK_ESCAPE:
- PostThreadMessage(g_pApp->m_idThread, WM_QUIT, 0, 0);
- break;
- case VK_MENU:
- g_pApp->OnMenu();
- break;
- } //endswitch wParam
- } //endif state=primary
- else if(g_pApp->IsSetPreset())
- {
- switch(wParam)
- {
- default:
- break;
- case VK_ESCAPE: // handle this to keep our m_State accurate
- g_pApp->DoneSetPreset(FALSE);
- break;
- }
- } //end else if
- else if(g_pApp->IsSettings())
- {
- switch(wParam)
- {
- default:
- break;
- case VK_ESCAPE:
- g_pApp->DoneSettings();
- return NOERROR;
-
- case VK_MENU:
- g_pApp->DoneSettings();
- break;
- } //end switch(wParam)
- } // end else if(g_pApp->IsSettings())
- } //endcase WM_REMOTE_KEYDOWN
- } //endswitch uMsg
-
- return S_FALSE;
- }
-