home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / template / atl / snapin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  7.5 KB  |  260 lines

  1. [!if=(FileExists, "FALSE")]
  2. #include "stdafx.h"
  3. #include "[!ProjectName].h"
  4. #include "[!HeaderName]"
  5. [!else]
  6. [!AddIncludeFile(TargetFile, "stdafx.h")]
  7. [!AddStringToSymbol(ProjectName.h, ProjectName, ".h")]
  8. [!AddIncludeFile(TargetFile, ProjectName.h)]
  9. [!AddIncludeFile(TargetFile, HeaderName)]
  10. [!endif]
  11.  
  12. [!crlf]
  13. /////////////////////////////////////////////////////////////////////////////
  14. // [!ClassName]ComponentData
  15.  
  16.  
  17. [!if=(IComponentData, "TRUE")]
  18. static const GUID [!ClassName]GUID_NODETYPE = 
  19. [!SnapInNodeType_GUIDFMT];
  20.  
  21. const GUID*  [!ClassName]Data::m_NODETYPE = &[!ClassName]GUID_NODETYPE;
  22. const OLECHAR* [!ClassName]Data::m_SZNODETYPE = OLESTR("[!SnapInNodeType]");
  23. const OLECHAR* [!ClassName]Data::m_SZDISPLAY_NAME = OLESTR("[!ShortName]");
  24. const CLSID* [!ClassName]Data::m_SNAPIN_CLASSID = &CLSID_[!CoClassName];
  25. [!crlf]
  26. [!endif]
  27. [!if=(EXTENSIONSNAPIN, "TRUE")]
  28. static const GUID [!ClassName]ExtGUID_NODETYPE = 
  29. [!EXTENDSNODE_GUIDFMT];
  30.  
  31. const GUID*  [!ClassName]ExtData::m_NODETYPE = &[!ClassName]ExtGUID_NODETYPE;
  32. const OLECHAR* [!ClassName]ExtData::m_SZNODETYPE = OLESTR("[!EXTENDSNODE]");
  33. const OLECHAR* [!ClassName]ExtData::m_SZDISPLAY_NAME = OLESTR("[!ShortName]");
  34. const CLSID* [!ClassName]ExtData::m_SNAPIN_CLASSID = &CLSID_[!CoClassName];
  35. [!endif]
  36.  
  37. [!if=(IComponentData, "TRUE")]
  38. [!if=(IExtendPropertySheet, "TRUE)]
  39. HRESULT [!ClassName]Data::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  40.     long handle, 
  41.     IUnknown* pUnk,
  42.     DATA_OBJECT_TYPES type)
  43. {
  44.     if (type == CCT_SCOPE || type == CCT_RESULT)
  45.     {
  46.         [!ClassName]Page* pPage = new [!ClassName]Page(handle, true, _T("[!ShortName]"));
  47.         lpProvider->AddPage(pPage->Create());
  48.         // The second parameter  to the property page class constructor
  49.         // should be true for only one page.
  50. [!crlf]
  51.         // TODO : Add code here to add additional pages
  52.         return S_OK;
  53.     }
  54.     return E_UNEXPECTED;
  55. }
  56. [!crlf]
  57. [!endif]
  58. HRESULT [!ClassName]Data::GetScopePaneInfo(SCOPEDATAITEM *pScopeDataItem)
  59. {
  60.     if (pScopeDataItem->mask & SDI_STR)
  61.         pScopeDataItem->displayname = m_bstrDisplayName;
  62.  
  63.     if (pScopeDataItem->mask & SDI_IMAGE)
  64.         pScopeDataItem->nImage = m_scopeDataItem.nImage;
  65.  
  66.     if (pScopeDataItem->mask & SDI_OPENIMAGE)
  67.         pScopeDataItem->nOpenImage = m_scopeDataItem.nOpenImage;
  68.  
  69.     if (pScopeDataItem->mask & SDI_PARAM)
  70.         pScopeDataItem->lParam = m_scopeDataItem.lParam;
  71.  
  72.     if (pScopeDataItem->mask & SDI_STATE )
  73.         pScopeDataItem->nState = m_scopeDataItem.nState;
  74. [!crlf]
  75.     // TODO : Add code for SDI_CHILDREN 
  76.     return S_OK;
  77. }
  78. [!crlf]
  79. HRESULT [!ClassName]Data::GetResultPaneInfo(RESULTDATAITEM *pResultDataItem)
  80. {
  81.     if (pResultDataItem->bScopeItem)
  82.     {
  83.         if (pResultDataItem->mask & RDI_STR)
  84.         {
  85.             pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  86.         }
  87.         if (pResultDataItem->mask & RDI_IMAGE)
  88.         {
  89.             pResultDataItem->nImage = m_scopeDataItem.nImage;
  90.         }
  91.         if (pResultDataItem->mask & RDI_PARAM)
  92.         {
  93.             pResultDataItem->lParam = m_scopeDataItem.lParam;
  94.         }
  95. [!crlf]
  96.         return S_OK;
  97.     }
  98. [!crlf]
  99.     if (pResultDataItem->mask & RDI_STR)
  100.     {
  101.         pResultDataItem->str = GetResultPaneColInfo(pResultDataItem->nCol);
  102.     }
  103.     if (pResultDataItem->mask & RDI_IMAGE)
  104.     {
  105.         pResultDataItem->nImage = m_resultDataItem.nImage;
  106.     }
  107.     if (pResultDataItem->mask & RDI_PARAM)
  108.     {
  109.         pResultDataItem->lParam = m_resultDataItem.lParam;
  110.     }
  111.     if (pResultDataItem->mask & RDI_INDEX)
  112.     {
  113.         pResultDataItem->nIndex = m_resultDataItem.nIndex;
  114.     }
  115. [!crlf]
  116.     return S_OK;
  117. }
  118. [!crlf]
  119. HRESULT [!ClassName]Data::Notify( MMC_NOTIFY_TYPE event,
  120.     long arg,
  121.     long param,
  122.     IComponentData* pComponentData,
  123.     IComponent* pComponent,
  124.     DATA_OBJECT_TYPES type)
  125. {
  126.     // Add code to handle the different notifications.
  127.     // Handle MMCN_SHOW and MMCN_EXPAND to enumerate children items.
  128.     // In response to MMCN_SHOW you have to enumerate both the scope
  129.     // and result pane items.
  130.     // For MMCN_EXPAND you only need to enumerate the scope items
  131.     // Use IConsoleNameSpace::InsertItem to insert scope pane items
  132.     // Use IResultData::InsertItem to insert result pane item.
  133.     HRESULT hr = E_NOTIMPL;
  134. [!crlf]    
  135.     _ASSERTE(pComponentData != NULL || pComponent != NULL);
  136. [!crlf]
  137.     CComPtr<IConsole> spConsole;
  138.     CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeader;
  139.     if (pComponentData != NULL)
  140.         spConsole = (([!ClassName]*)pComponentData)->m_spConsole;
  141.     else
  142.     {
  143.         spConsole = (([!ClassName]Component*)pComponent)->m_spConsole;
  144.         spHeader = spConsole;
  145.     }
  146. [!crlf]
  147.     switch (event)
  148.     {
  149.     case MMCN_SHOW:
  150.         {
  151.  
  152.             CComQIPtr<IResultData, &IID_IResultData> spResultData(spConsole);
  153.             // TODO : Enumerate the result pane items
  154.             hr = S_OK;
  155.             break;
  156.         }
  157.     case MMCN_EXPAND:
  158.         {
  159.             CComQIPtr<IConsoleNameSpace, &IID_IConsoleNameSpace> spConsoleNameSpace(spConsole);
  160.             // TODO : Enumerate scope pane items
  161.             hr = S_OK;
  162.             break;
  163.         }
  164.     case MMCN_ADD_IMAGES:
  165.         {
  166.             // Add Images
  167.             IImageList* pImageList = (IImageList*) arg;
  168.             hr = E_FAIL;
  169.             // Load bitmaps associated with the scope pane
  170.             // and add them to the image list
  171.             // Loads the default bitmaps generated by the wizard
  172.             // Change as required
  173.             HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE([!IDB_SNAPIN16]));
  174.             if (hBitmap16 != NULL)
  175.             {
  176.                 HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE([!IDB_SNAPIN32]));
  177.                 if (hBitmap32 != NULL)
  178.                 {
  179.                     hr = pImageList->ImageListSetStrip((long*)hBitmap16, 
  180.                     (long*)hBitmap32, 0, RGB(0, 128, 128));
  181.                     if (FAILED(hr))
  182.                         ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  183.                 }
  184.             }
  185.             break;
  186.         }
  187.     }
  188.     return hr;
  189. }
  190. [!crlf]
  191. LPOLESTR [!ClassName]Data::GetResultPaneColInfo(int nCol)
  192. {
  193.     if (nCol == 0)
  194.         return m_bstrDisplayName;
  195.  
  196.     // TODO : Return the text for other columns
  197.  
  198.     return OLESTR("Override GetResultPaneColInfo");
  199. }
  200. [!crlf]
  201. [!endif]
  202. [!if=(EXTENSIONSNAPIN, "TRUE")]
  203. [!if=(IExtendPropertySheet, "TRUE)]
  204. HRESULT [!ClassName]ExtData::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  205.     long handle, 
  206.     IUnknown* pUnk,
  207.     DATA_OBJECT_TYPES type)
  208. {
  209.     if (type == CCT_SCOPE || type == CCT_RESULT)
  210.     {
  211.         [!ClassName]Page* pPage = new [!ClassName]Page(handle, true, _T("[!ShortName]"));
  212.         lpProvider->AddPage(pPage->Create());
  213.         // The second parameter  to the property page class constructor
  214.         // should be true for only one page.
  215. [!crlf]
  216.         // TODO : Add code here to add additional pages
  217.         return S_OK;
  218.     }
  219.     return E_UNEXPECTED;
  220. }
  221. [!crlf]
  222. [!endif]
  223. [!endif]
  224. [!if=(IComponentData, "TRUE")]
  225. HRESULT [!ClassName]::Initialize(LPUNKNOWN pUnknown)
  226. {
  227.     HRESULT hr = IComponentDataImpl<[!ClassName], [!ClassName]Component >::Initialize(pUnknown);
  228.     if (FAILED(hr))
  229.         return hr;
  230. [!crlf]
  231.     CComPtr<IImageList> spImageList;
  232. [!crlf]
  233.     if (m_spConsole->QueryScopeImageList(&spImageList) != S_OK)
  234.     {
  235.         ATLTRACE(_T("IConsole::QueryScopeImageList failed\n"));
  236.         return E_UNEXPECTED;
  237.     }
  238. [!crlf]
  239.     // Load bitmaps associated with the scope pane
  240.     // and add them to the image list
  241.     // Loads the default bitmaps generated by the wizard
  242.     // Change as required
  243.     HBITMAP hBitmap16 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE([!IDB_SNAPIN16]));
  244.     if (hBitmap16 == NULL)
  245.         return S_OK;
  246. [!crlf]
  247.     HBITMAP hBitmap32 = LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE([!IDB_SNAPIN32]));
  248.     if (hBitmap32 == NULL)
  249.         return S_OK;
  250. [!crlf]
  251.     if (spImageList->ImageListSetStrip((long*)hBitmap16, 
  252.         (long*)hBitmap32, 0, RGB(0, 128, 128)) != S_OK)
  253.     {
  254.         ATLTRACE(_T("IImageList::ImageListSetStrip failed\n"));
  255.         return E_UNEXPECTED;
  256.     }
  257.     return S_OK;
  258. }
  259. [!endif]
  260.