home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- appsink.cpp
-
- Abstract:
-
- Keyboard Sample application sinks. Implements two classes,
- CFormEventSink and CAppMessageSink.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
- // System specific includes
- #include <windows.h>
- #include <olectl.h>
- #include <asfc.h>
- #include <ascmnctl.h>
- #include <speech.h>
- #include <keypad.h>
-
- // Application specific includes
- #include "app.h"
- #include "resource.h"
- #include "appsink.h"
-
- // Global Application class object
- extern CKeyboardApp* g_pApp;
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Class:
- CFormEventSink
-
- Description:
- Implements IASEventSink interface. Doesn't handle any messages
- (All of them are handled in the ClassMsgSink attached to the form
- manager)
- -------------------------------------------------------------------*/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::CFormEventSink
-
- Description:
- Constructor. Initializes all member variables.
-
- Parameters:
- DWORD - Applications main thread ID
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CFormEventSink::CFormEventSink(DWORD AppThreadID)
- {
- m_cRef = 0;
- m_AppThreadId = AppThreadID;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::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
- CFormEventSink::QueryInterface( REFIID riid,
- PVOID *ppv)
- {
-
- HRESULT hr = NOERROR;
-
- if (!ppv)
- hr = E_INVALIDARG;
-
- // Return the requested interface
- if( SUCCEEDED( hr ) ) {
- if (riid == IID_ASEVENTSINK)
- *ppv = (PVOID) (IASEventSink*) this;
- else if (riid == IID_IUnknown)
- *ppv = (PVOID) (IUnknown*) (IVCmdNotifySinkW*) this;
- else if (riid == IID_IDispatch)
- *ppv = (PVOID) (IDispatch*) this;
- else
- hr = E_NOINTERFACE;
- }
-
- if( SUCCEEDED( hr ) )
- AddRef();
-
- return hr;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::AddRef
-
- Description:
- Standard COM IUknown method.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CFormEventSink::AddRef()
- {
- InterlockedIncrement(&m_cRef);
-
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::Release
-
- Description:
- Standard COM IUknown method.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CFormEventSink::Release()
- {
-
- if (InterlockedDecrement(&m_cRef) == 0)
- {
- delete this;
- return(0);
- }
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 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
- CFormEventSink::ReceiveMsg(LONG uMsg, LONG wParam, LONG lParam)
- {
- return S_FALSE;
- }
-
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Class:
- CAppMessageSink
-
- Description:
- ClassMsgSink and EventSink attached to the form Manager.
- -------------------------------------------------------------------*/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppMessageSink::CAppMessageSink
-
- Description:
- Constructor. Initializes all member variables.
-
- Parameters:
- DWORD - Applications main thread ID
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CAppMessageSink::CAppMessageSink(DWORD AppThreadID)
- {
- m_cRef = 0;
- m_AppThreadId = AppThreadID;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppMessageSink::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
- CAppMessageSink::QueryInterface(REFIID riid, PVOID *ppv)
- {
- HRESULT hr = NOERROR;
-
- if (!ppv)
- hr = E_INVALIDARG;
-
- // Return the requested interface.
- if( SUCCEEDED( hr ) ) {
- if (riid == IID_ASCLASSMSGSINK)
- *ppv = (PVOID) (IASClassMsgSink *) this;
- else if (riid == IID_ASEVENTSINK)
- *ppv = (PVOID) (IASEventSink*) this;
- else if (riid == IID_IUnknown)
- *ppv = (PVOID) (IUnknown *) (IASClassMsgSink *)this;
- else if (riid == IID_IDispatch)
- *ppv = (PVOID) (IDispatch *) (IASClassMsgSink *)this;
- else
- hr = E_NOINTERFACE;
- }
-
- if( SUCCEEDED( hr ) )
- AddRef();
-
- return hr;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::AddRef
-
- Description:
- Standard COM IUknown method. Increases the objects reference count.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CAppMessageSink::AddRef( VOID)
- {
- InterlockedIncrement(&m_cRef);
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::Release
-
- Description:
- Standard COM IUknown method. Decreases the objects reference
- count and deletes it when no longer needed.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after decrement.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CAppMessageSink::Release( VOID)
- {
- if (InterlockedDecrement(&m_cRef) == 0)
- {
- delete this;
- return(0);
- }
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::HandleKeyPress
-
- Description:
- IASClassMsgSink method. Called when a keypad key (lKeyPress = 'x'),
- enter (VK_RETURN), and escape (VK_ESCAPE).
-
- Parameters:
- IDispatch * pdispControl - Control receiving keypress.
- LONG lKeyPress - Key being pressed.
-
- Returns:
- S_FALSE - To keep message going down the message path.
- NOERROR - To eat the message.
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppMessageSink::HandleKeyPress(IDispatch* pdispControl, LONG lKeyPress)
- {
- WCHAR wsztext[80] = { 0 };
-
- switch (lKeyPress)
- {
- // Case of any numeric keypad presses
- case '0': case '1': case '2': case '3': case '4': case '5': case '6':
- case '7': case '8': case '9': case '*': case '#':
- wsprintf(wsztext, TEXT("HandleKeyPress %c "), (char)lKeyPress);
- break;
-
- // Enter (return) pressed
- case VK_RETURN:
- lstrcpy(wsztext, TEXT("HandleKeyPress enter"));
- break;
-
- // Any keypress not handled above. On v1.0 devices, there shouldn't
- // be any, but on future devices, they may include a keyboard or
- // key input device.
- default:
- wsprintf(wsztext, TEXT("HandleKeyPress missed %d "), lKeyPress);
- break;
- }
- g_pApp->UpdateSystemLabel(wsztext);
- return S_FALSE;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::HandleMessage
-
- Description:
- IASClassMsgSink method. Called when a message is fired towards
- our forms manager.
-
- Parameters:
- IDispatch * pdispControl - Control to receive message.
- LONG uMsg - Win32 Message.
- LONG wParam - Message Parameter.
- LONG lParam - Message Parameter.
-
- Returns:
- S_FALSE - To keep message going down the message path.
- NOERROR - To eat the message.
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppMessageSink::HandleMessage(IDispatch* pdispControl, long uMsg, long wParam, long lParam)
- {
- // If someone presses the escape key (which would bring them back
- // to the shell), we kill the process by sending a WM_QUIT
- // message to our app.
- if(uMsg == WM_REMOTE_KEYDOWN && wParam == VK_ESCAPE)
- {
- PostThreadMessage(m_AppThreadId, WM_QUIT, 0, 0);
- return NOERROR;
- }
-
- // We let a main application method handle these messages.
- g_pApp->ProcessMessage(uMsg, wParam, lParam);
-
- return S_FALSE;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppEventSink::ReceiveMsg
-
- Description:
- IASEventSink method. Attached to the forms manager. Called first
- when a message is fired towards our forms manager. In this case we
- do nothing and let the ClassMsgSink methods handle all messages.
-
- Parameters:
- LONG uMsg - Win32 Message.
- LONG wParam - Message Parameter.
- LONG lParam - Message Parameter.
-
- Returns:
- S_FALSE - To keep message going down the message path.
- NOERROR - To eat the message.
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CAppMessageSink::ReceiveMsg(long uMsg, long wParam, long lParam)
- {
- return S_FALSE;
- }
-
-
-
-
-