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

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2.  
  3. Copyright (c) 1998 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     syssink.cpp
  8.  
  9. Abstract:
  10.  
  11.     System Information AutoPC Sample control panel applet.
  12.     This file implements the applet's message sink, a COM object 
  13.     with IASEventSink, IASClassMsgSink, IUnknown, and IDispatch
  14.     interfaces.
  15.  
  16. Environment:
  17.  
  18.     AutoPC
  19.  
  20. -------------------------------------------------------------------*/
  21. // AutoPC includes
  22. #include <Windows.h>
  23. #include <asfc.h>           
  24. #include <ascmnctl.h>  
  25. #include <keypad.h>
  26.  
  27. #include <apcdebug.h>
  28.  
  29. // Application specific includes
  30. #include "resource.h"
  31. #include "SysInfo.h"
  32.  
  33. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  34. Function:
  35.     CSysInfoSink::CSysInfoSink
  36.  
  37. Description:
  38.     Constructor.  Just initializes COM object reference count.
  39.  
  40. Returns:
  41.     Nothing.
  42. -------------------------------------------------------------------*/
  43. CSysInfoSink::CSysInfoSink()
  44. {
  45.     m_cRef = 0;
  46. }
  47.  
  48. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  49. Function:
  50.     CSysInfoSink::QueryInterface
  51.  
  52. Description:
  53.     Standard COM IUknown method.  
  54.  
  55. Parameters:
  56.     REFIID - Reference to requested Interface GUID
  57.     PVOID * - Target for interface pointer.
  58.  
  59. Returns:
  60.     HRESULT - NOERROR on success.  Other error code on fail.
  61. -------------------------------------------------------------------*/
  62. STDMETHODIMP 
  63. CSysInfoSink::QueryInterface(REFIID riid, PVOID *ppv)
  64. {
  65.     if (!ppv) return E_INVALIDARG;
  66.  
  67.     // Return the requested interface
  68.     if (riid == IID_ASEVENTSINK) *ppv = (PVOID) (IASEventSink *) this; 
  69.     else if (riid == IID_ASCLASSMSGSINK) *ppv = (PVOID) (IASClassMsgSink *) this;
  70.     else if (riid == IID_IUnknown) *ppv = (PVOID) (IUnknown *) (IASEventSink *) this;
  71.     else if (riid == IID_IDispatch) *ppv = (PVOID) (IDispatch *) (IASEventSink *) this;
  72.     else return E_NOINTERFACE;
  73.  
  74.     // If we gave out an interface, we have to increase our ref count
  75.     AddRef();
  76.     return NOERROR;
  77. }
  78.  
  79. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  80. Function:
  81.     CSysInfoSink::AddRef
  82.  
  83. Description:
  84.     Standard COM IUknown method.  
  85.  
  86. Parameters:
  87.     Nothing.
  88.  
  89. Returns:
  90.     ULONG - Reference count after increment.
  91. -------------------------------------------------------------------*/
  92. STDMETHODIMP_(ULONG) 
  93. CSysInfoSink::AddRef()
  94. {
  95.     InterlockedIncrement(&m_cRef);
  96.     return m_cRef;         
  97. }
  98.  
  99. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  100. Function:
  101.     CSysInfoSink::Release
  102.  
  103. Description:
  104.     Standard COM IUknown method.  
  105.  
  106. Parameters:
  107.     Nothing.
  108.  
  109. Returns:
  110.     ULONG - Reference count after increment.
  111. -------------------------------------------------------------------*/
  112. STDMETHODIMP_(ULONG)
  113. CSysInfoSink::Release()
  114. {
  115.     if (InterlockedDecrement(&m_cRef) > 0) return m_cRef;
  116.  
  117.     delete this;
  118.     return 0; 
  119. }            
  120.  
  121. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  122. Function:
  123.     CSysInfoSink::ReceiveMsg
  124.  
  125. Description:
  126.     IASEventSink method attached to main form and forms manager.
  127.  
  128. Parameters:
  129.     long - Win32 Message
  130.     long - Win32 Parameter
  131.     long - Win32 Parameter
  132.  
  133. Returns:
  134.     HRESULT - S_FALSE if message should continue down message path.
  135.               NOERROR if message should stop here
  136. -------------------------------------------------------------------*/
  137. STDMETHODIMP 
  138. CSysInfoSink::ReceiveMsg(long uMsg, long wParam, long lParam)
  139. {
  140.     return S_FALSE;
  141. }
  142.  
  143. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  144. Function:
  145.     CSysInfoSink::HandleKeyPress
  146.  
  147. Description:
  148.     IASClassMsgSink method attached to main form and forms manager.
  149.     We only handle the VK_ESCAPE key and exit the application when we
  150.     receive it.  We have to kill the VK_ESCAPE message by returning 
  151.     S_OK so that the shell doesn't come up.
  152.  
  153. Parameters:
  154.     IDispatch* pdispControl    - Control calling this method
  155.     long lKeyDown            - Key pressed
  156.  
  157. Returns:
  158.     HRESULT - S_FALSE if message should continue down message path.
  159.               NOERROR if message should stop here
  160. -------------------------------------------------------------------*/
  161. STDMETHODIMP 
  162. CSysInfoSink::HandleKeyPress(IDispatch *pdispControl, long lKeyDown)
  163. {
  164.     switch(lKeyDown)
  165.     {
  166.     case VK_ESCAPE:
  167.         // Now send the quit message to the thread we're in
  168.         PostThreadMessage(GetCurrentThreadId(), WM_QUIT, 0, 0);
  169.         return S_OK;
  170.     }
  171.  
  172.     return S_FALSE;
  173. }
  174.