home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- appsink.cpp
-
- Abstract:
-
- SR App sample application message sinks. A CFormEventSink that will be
- attached to all the forms we create in our application, and a CAppMessageSink
- that will be attached to the forms manager.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
- // AutoPC specific includes
- #include <windows.h>
- #include <olectl.h>
- #include <asfc.h>
- #include <ascmnctl.h>
- #include <speech.h>
-
- // Application specific includes
- #include "app.h"
- #include "resource.h"
- #include "appsink.h"
-
- // Global application object
- CSRApp* g_pApp;
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Class:
- CFormEventSink
-
- Description:
- Event sink attached to each of the forms.
- -------------------------------------------------------------------*/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::CFormEventSink
-
- Description:
- Constructor. Initializes all member variables.
-
- Parameters:
- DWORD AppThreadID - Applications thread ID
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CFormEventSink::CFormEventSink(DWORD AppThreadID)
- {
- m_cRef = 0;
- m_AppThreadId = AppThreadID;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::QueryInterface
-
- Description:
- Standard COM IUknown method. We implement IUnknown, IDispatch
- (although not properly implemented), and IASEventSink interfaces.
-
- 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)
- return E_INVALIDARG;
-
- if (riid == IID_ASEVENTSINK)
- *ppv = (PVOID) (IASEventSink*) this;
- else if (riid == IID_IUnknown)
- *ppv = (PVOID) (IUnknown*) 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. Increases reference count on
- CFormEventSink object.
-
- 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. Decrements reference count. Frees
- object when it is 0.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after decrement.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)CFormEventSink::Release()
- {
- if (InterlockedDecrement(&m_cRef) == 0)
- {
- delete this;
- return(0);
- }
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CFormEventSink::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)
- {
- long lRet;
- HRESULT hr;
-
- switch (uMsg)
- {
- default:
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- default:
- break;
-
- case IDC_PLB_MENU:
- switch(HIWORD(lParam))
- {
- default:
- break;
-
- case IDMI_TRAIN_COLORS:
- g_pApp->m_pSpeech->Train(L"Black", sizeof(L"Black"), L"Black", sizeof(L"Black"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Red", sizeof(L"Red"), L"Red", sizeof(L"Red"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Green", sizeof(L"Green"), L"Green", sizeof(L"Green"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Blue", sizeof(L"Blue"), L"Blue", sizeof(L"Blue"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Yellow", sizeof(L"Yellow"), L"Yellow", sizeof(L"Yellow"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Violet", sizeof(L"Violet"), L"Violet", sizeof(L"Violet"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"Cyan", sizeof(L"Cyan"), L"Cyan", sizeof(L"Cyan"), NULL, NULL);
- g_pApp->m_pSpeech->Train(L"White", sizeof(L"White"), L"White", sizeof(L"White"), NULL, NULL);
- break;
-
- case IDMI_EXIT:
- g_pApp->Quit();
- break;
-
- case IDMI_NUMBERS:
- g_pApp->m_pActiveForms->SetFocus(g_pApp->m_pNumbersForm);
- break;
-
- case IDMI_COLORS:
- hr = g_pApp->CreateColorsVoiceMenu();
- if(FAILED(hr))
- {
- // Message box saying words not trained yet
- HRESULT hr = g_pApp->m_pManage->fmMessageBox(
- g_pApp->m_bstrNoColors,
- g_pApp->m_bstrNoColorsTitle,
- MB_OK | MB_DEFBUTTON2,
- FMMB_FLG_TTS,
- &lRet);
- }
- else
- {
- g_pApp->m_pActiveForms->SetFocus(g_pApp->m_pColorsForm);
- }
- break;
- } // endswitch HIWORD(lParam)
- break;
- } // endswitch LOWORD(wParam)
-
- } // endswitch uMsg
-
- return NOERROR;
- }
-
- //--------------------------------------------------------------------------------------------
- //
- // CAppMessageSink SINK
- //
- //--------------------------------------------------------------------------------------------
-
- CAppMessageSink::CAppMessageSink(DWORD AppThreadID)
- {
- m_cRef = 0;
- m_AppThreadId = AppThreadID;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppMessageSink::QueryInterface
-
- Description:
- Standard COM IUknown method. We implement IUnknown, IDispatch
- (although not properly implemented), IASEventSink, and
- IASClassMsgSink interfaces.
-
- 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)
- {
- if(!ppv)
- return E_INVALIDARG;
-
- 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
- return E_NOINTERFACE;
-
- AddRef();
-
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppMessageSink::AddRef
-
- Description:
- Standard COM IUknown method. Increases reference count on
- CAppMessageSink object.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CAppMessageSink::AddRef()
- {
- InterlockedIncrement(&m_cRef);
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CAppMessageSink::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)
- CAppMessageSink::Release()
- {
- if (InterlockedDecrement(&m_cRef) == 0)
- {
- delete this;
- return(0);
- }
- return m_cRef;
- }
-
- // IASClassMsgSink
- // This method is invoked whenever an event is fired
- STDMETHODIMP CAppMessageSink::HandleMessage(IDispatch* pdispControl, LONG uMsg, LONG wParam, LONG lParam)
- {
- switch (uMsg)
- {
- default:
- break;
-
- case WM_SPCH_RECOG:
- switch (lParam)
- {
- default:
- break;
-
- case IDVMI_BLACK:
- g_pApp->m_pColorsForm->put_BackColor(BLACK);
- break;
- case IDVMI_RED:
- g_pApp->m_pColorsForm->put_BackColor(RED);
- break;
- case IDVMI_GREEN:
- g_pApp->m_pColorsForm->put_BackColor(GREEN);
- break;
- case IDVMI_BLUE:
- g_pApp->m_pColorsForm->put_BackColor(BLUE);
- break;
- case IDVMI_YELLOW:
- g_pApp->m_pColorsForm->put_BackColor(YELLOW);
- break;
- case IDVMI_VIOLET:
- g_pApp->m_pColorsForm->put_BackColor(VIOLET);
- break;
- case IDVMI_CYAN:
- g_pApp->m_pColorsForm->put_BackColor(CYAN);
- break;
- case IDVMI_WHITE:
- g_pApp->m_pColorsForm->put_BackColor(WHITE);
- break;
-
- case IDVMI_ZERO:
- case IDVMI_ONE:
- case IDVMI_TWO:
- case IDVMI_THREE:
- case IDVMI_FOUR:
- case IDVMI_FIVE:
- case IDVMI_SIX:
- case IDVMI_SEVEN:
- case IDVMI_EIGHT:
- case IDVMI_NINE:
- g_pApp->AddNumber(lParam - IDVMI_NUMBERS_BASE);
- break;
-
- case IDVMI_NUMBERS_END:
- g_pApp->m_pActiveForms->SetFocus(g_pApp->m_pMainForm);
- break;
-
- case IDVMI_COLORS_END:
- g_pApp->m_pActiveForms->SetFocus(g_pApp->m_pMainForm);
- break;
-
- }
- break;
- }
-
- return S_FALSE;
- }
-
-