home *** CD-ROM | disk | FTP | other *** search
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- Copyright (c) 1998 Microsoft Corporation
-
- Module Name:
-
- syssink.cpp
-
- Abstract:
-
- System Information AutoPC Sample control panel applet.
- This file implements the applet's message sink, a COM object
- with IASEventSink, IASClassMsgSink, IUnknown, and IDispatch
- interfaces.
-
- Environment:
-
- AutoPC
-
- -------------------------------------------------------------------*/
- // AutoPC includes
- #include <Windows.h>
- #include <asfc.h>
- #include <ascmnctl.h>
- #include <keypad.h>
-
- #include <apcdebug.h>
-
- // Application specific includes
- #include "resource.h"
- #include "SysInfo.h"
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::CSysInfoSink
-
- Description:
- Constructor. Just initializes COM object reference count.
-
- Returns:
- Nothing.
- -------------------------------------------------------------------*/
- CSysInfoSink::CSysInfoSink()
- {
- m_cRef = 0;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::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
- CSysInfoSink::QueryInterface(REFIID riid, PVOID *ppv)
- {
- if (!ppv) return E_INVALIDARG;
-
- // Return the requested interface
- 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;
-
- // If we gave out an interface, we have to increase our ref count
- AddRef();
- return NOERROR;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::AddRef
-
- Description:
- Standard COM IUknown method.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CSysInfoSink::AddRef()
- {
- InterlockedIncrement(&m_cRef);
- return m_cRef;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::Release
-
- Description:
- Standard COM IUknown method.
-
- Parameters:
- Nothing.
-
- Returns:
- ULONG - Reference count after increment.
- -------------------------------------------------------------------*/
- STDMETHODIMP_(ULONG)
- CSysInfoSink::Release()
- {
- if (InterlockedDecrement(&m_cRef) > 0) return m_cRef;
-
- delete this;
- return 0;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::ReceiveMsg
-
- Description:
- IASEventSink method attached to main form and forms manager.
-
- 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
- CSysInfoSink::ReceiveMsg(long uMsg, long wParam, long lParam)
- {
- return S_FALSE;
- }
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Function:
- CSysInfoSink::HandleKeyPress
-
- Description:
- IASClassMsgSink method attached to main form and forms manager.
- We only handle the VK_ESCAPE key and exit the application when we
- receive it. We have to kill the VK_ESCAPE message by returning
- S_OK so that the shell doesn't come up.
-
- Parameters:
- IDispatch* pdispControl - Control calling this method
- long lKeyDown - Key pressed
-
- Returns:
- HRESULT - S_FALSE if message should continue down message path.
- NOERROR if message should stop here
- -------------------------------------------------------------------*/
- STDMETHODIMP
- CSysInfoSink::HandleKeyPress(IDispatch *pdispControl, long lKeyDown)
- {
- switch(lKeyDown)
- {
- case VK_ESCAPE:
- // Now send the quit message to the thread we're in
- PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0, 0);
- return S_OK;
- }
-
- return S_FALSE;
- }
-