home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winui / shell / regview / infotip.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-27  |  4.4 KB  |  195 lines

  1. /**************************************************************************
  2.    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3.    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4.    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5.    PARTICULAR PURPOSE.
  6.  
  7.    Copyright 1997 Microsoft Corporation.  All Rights Reserved.
  8. **************************************************************************/
  9.  
  10. /**************************************************************************
  11.  
  12.    File:          InfoTip.cpp
  13.    
  14.    Description:   Implements CQueryInfo.
  15.  
  16. **************************************************************************/
  17.  
  18. #include "InfoTip.h"
  19.  
  20. #if (_WIN32_IE >= 0x0400)
  21.  
  22. /**************************************************************************
  23.    #include statements
  24. **************************************************************************/
  25.  
  26. #include "Guid.h"
  27. #include "Utility.h"
  28.  
  29. /**************************************************************************
  30.  
  31.    CQueryInfo::CQueryInfo()
  32.  
  33. **************************************************************************/
  34.  
  35. CQueryInfo::CQueryInfo(LPCITEMIDLIST pidl)
  36. {
  37. m_pPidlMgr = new CPidlMgr();
  38. if(!m_pPidlMgr)
  39.    {
  40.    delete this;
  41.    return;
  42.    }
  43.  
  44. //get the shell's IMalloc pointer
  45. //we'll keep this until we get destroyed
  46. if(FAILED(SHGetMalloc(&m_pMalloc)))
  47.    {
  48.    delete this;
  49.    return;
  50.    }
  51.  
  52. m_pidl = m_pPidlMgr->Copy(pidl);
  53.  
  54. m_ObjRefCount = 1;
  55.  
  56. g_DllRefCount++;
  57. }
  58.  
  59. /**************************************************************************
  60.  
  61.    CQueryInfo::~CQueryInfo()
  62.  
  63. **************************************************************************/
  64.  
  65. CQueryInfo::~CQueryInfo()
  66. {
  67. if(m_pidl)
  68.    {
  69.    m_pPidlMgr->Delete(m_pidl);
  70.    m_pidl = NULL;
  71.    }
  72.  
  73. if(m_pMalloc)
  74.    {
  75.    m_pMalloc->Release();
  76.    }
  77.  
  78. if(m_pPidlMgr)
  79.    {
  80.    delete m_pPidlMgr;
  81.    }
  82.  
  83. g_DllRefCount--;
  84. }
  85.  
  86. ///////////////////////////////////////////////////////////////////////////
  87. //
  88. // IUnknown Implementation
  89. //
  90.  
  91. /**************************************************************************
  92.  
  93.    CQueryInfo::QueryInterface
  94.  
  95. **************************************************************************/
  96.  
  97. STDMETHODIMP CQueryInfo::QueryInterface(REFIID riid, LPVOID *ppReturn)
  98. {
  99. *ppReturn = NULL;
  100.  
  101. //IUnknown
  102. if(IsEqualIID(riid, IID_IUnknown))
  103.    {
  104.    *ppReturn = this;
  105.    }
  106.  
  107. //IQueryInfo
  108. else if(IsEqualIID(riid, IID_IQueryInfo))
  109.    {
  110.    *ppReturn = (IQueryInfo*)this;
  111.    }
  112.  
  113. if(*ppReturn)
  114.    {
  115.    (*(LPUNKNOWN*)ppReturn)->AddRef();
  116.    return S_OK;
  117.    }
  118.  
  119. return E_NOINTERFACE;
  120. }                                             
  121.  
  122. /**************************************************************************
  123.  
  124.    CQueryInfo::AddRef
  125.  
  126. **************************************************************************/
  127.  
  128. STDMETHODIMP_(DWORD) CQueryInfo::AddRef()
  129. {
  130. return ++m_ObjRefCount;
  131. }
  132.  
  133. /**************************************************************************
  134.  
  135.    CQueryInfo::Release
  136.  
  137. **************************************************************************/
  138.  
  139. STDMETHODIMP_(DWORD) CQueryInfo::Release()
  140. {
  141. if(--m_ObjRefCount == 0)
  142.    {
  143.    delete this;
  144.    return 0;
  145.    }
  146.    
  147. return m_ObjRefCount;
  148. }
  149.  
  150. ///////////////////////////////////////////////////////////////////////////
  151. //
  152. // IQueryInfo Implementation
  153. //
  154.  
  155. /**************************************************************************
  156.  
  157.    CQueryInfo::GetInfoTip()
  158.    
  159. **************************************************************************/
  160.  
  161. STDMETHODIMP CQueryInfo::GetInfoTip(DWORD dwFlags, WCHAR **ppwszTip)
  162. {
  163. TCHAR szTipText[MAX_PATH];
  164. int   cchOleStr;
  165.  
  166. *ppwszTip = NULL;
  167.  
  168. //get the entire text for the item
  169. m_pPidlMgr->GetPidlPath(m_pidl, szTipText, sizeof(szTipText));
  170.  
  171. //get the number of characters required
  172. cchOleStr = lstrlen(szTipText) + 1;
  173.  
  174. //allocate the wide character string
  175. *ppwszTip = (LPWSTR)m_pMalloc->Alloc(cchOleStr * sizeof(WCHAR));
  176. if(!*ppwszTip)
  177.    return E_OUTOFMEMORY;
  178.  
  179. LocalToWideChar(*ppwszTip, szTipText, cchOleStr);
  180.  
  181. return S_OK;
  182. }
  183.  
  184. /**************************************************************************
  185.  
  186.    CQueryInfo::GetInfoFlags()
  187.    
  188. **************************************************************************/
  189.  
  190. STDMETHODIMP CQueryInfo::GetInfoFlags(LPDWORD pdwFlags)
  191. {
  192. return E_NOTIMPL;
  193. }
  194.  
  195. #endif   //(_WIN32_IE >= 0x0400)