Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.5 KiB

  1. #include "stdafx.h"
  2. #include "dsplex.h"
  3. #include "DisplEx.h"
  4. extern HINSTANCE g_hinst; // in dsplex.cpp
  5. // local function
  6. LPOLESTR CoTaskDupString (LPOLESTR szString)
  7. {
  8. OLECHAR * lpString = (OLECHAR *)CoTaskMemAlloc (sizeof(OLECHAR)*(lstrlen(szString)+1));
  9. if (lpString)
  10. lstrcpy (lpString, szString);
  11. return lpString;
  12. }
  13. CEnumTasks::CEnumTasks()
  14. {
  15. m_refs = 0;
  16. m_index = 0;
  17. }
  18. CEnumTasks::~CEnumTasks()
  19. {
  20. }
  21. HRESULT CEnumTasks::QueryInterface (REFIID riid, LPVOID FAR* ppv)
  22. {
  23. if ( (riid == IID_IUnknown) ||
  24. (riid == IID_IEnumTASK) ){
  25. *ppv = this;
  26. ((LPUNKNOWN)(*ppv))->AddRef();
  27. return NOERROR;
  28. }
  29. *ppv = NULL;
  30. return E_NOINTERFACE;
  31. }
  32. ULONG CEnumTasks::AddRef ()
  33. {
  34. return ++m_refs;
  35. }
  36. ULONG CEnumTasks::Release ()
  37. {
  38. if (--m_refs == 0) {
  39. delete this;
  40. return 0;
  41. }
  42. return m_refs;
  43. }
  44. #define NUMBER_OF_TASKS 1
  45. LPOLESTR g_bitmaps[NUMBER_OF_TASKS] = {L"/img\\ntmonitor.gif"};
  46. LPOLESTR g_text [NUMBER_OF_TASKS] = {L"Wallpaper Extension Task"};
  47. LPOLESTR g_help [NUMBER_OF_TASKS] = {L"Use Clipboard Image as Wallpaper (but just for testing purposes I'm going to make this a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long line\
  48. really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long line)"};
  49. long g_action [NUMBER_OF_TASKS] = {1};
  50. HRESULT CEnumTasks::Next (ULONG celt, MMC_TASK *rgelt, ULONG *pceltFetched)
  51. {//will be called with celt == 1
  52. _ASSERT (celt == 1);
  53. _ASSERT (!IsBadWritePtr (rgelt, celt*sizeof(MMC_TASK)));
  54. // wrong type.
  55. if (m_type != 1) {
  56. if (pceltFetched)
  57. *pceltFetched = 0;
  58. return S_FALSE; // failure
  59. }
  60. // setup path for reuse
  61. OLECHAR szBuffer[MAX_PATH*2]; // that should be enough
  62. lstrcpy (szBuffer, L"res://");
  63. ::GetModuleFileName (g_hinst, szBuffer + lstrlen(szBuffer), MAX_PATH);
  64. OLECHAR * temp = szBuffer + lstrlen(szBuffer);
  65. if (m_index >= NUMBER_OF_TASKS) {
  66. if (pceltFetched)
  67. *pceltFetched = 0;
  68. return S_FALSE; // failure
  69. }
  70. MMC_TASK * task = &rgelt[0];
  71. MMC_TASK_DISPLAY_OBJECT* pdo = &task->sDisplayObject;
  72. MMC_TASK_DISPLAY_BITMAP* pdb = &pdo->uBitmap;
  73. // fill out bitmap URL
  74. pdo->eDisplayType = MMC_TASK_DISPLAY_TYPE_BITMAP;
  75. lstrcpy (temp, g_bitmaps[m_index]);
  76. pdb->szMouseOverBitmap = CoTaskDupString (szBuffer);
  77. if (pdb->szMouseOverBitmap) {
  78. pdb->szMouseOffBitmap = CoTaskDupString (szBuffer);
  79. if (pdb->szMouseOffBitmap) {
  80. // add button text
  81. task->szText = CoTaskDupString (g_text[m_index]);
  82. if (task->szText) {
  83. // add help string
  84. task->szHelpString = CoTaskDupString (g_help[m_index]);
  85. if (task->szHelpString) {
  86. // add action URL (link or script)
  87. task->eActionType = MMC_ACTION_ID;
  88. task->nCommandID = g_action[m_index];
  89. m_index++;
  90. if (pceltFetched)
  91. *pceltFetched = 1;
  92. return S_OK;
  93. }
  94. CoTaskMemFree (task->szText);
  95. }
  96. CoTaskMemFree (pdb->szMouseOffBitmap);
  97. }
  98. CoTaskMemFree (pdb->szMouseOverBitmap);
  99. }
  100. // if we get here, we didn't "continue" and therefore fail
  101. if (pceltFetched)
  102. *pceltFetched = 0;
  103. return S_FALSE; // failure
  104. }
  105. HRESULT CEnumTasks::Skip (ULONG celt)
  106. {
  107. m_index += celt;
  108. return S_OK;
  109. }
  110. HRESULT CEnumTasks::Reset()
  111. {
  112. m_index = 0;
  113. return S_OK;
  114. }
  115. HRESULT CEnumTasks::Clone(IEnumTASK **ppenum)
  116. {//clone maintaining state info
  117. return E_NOTIMPL;
  118. }
  119. HRESULT CEnumTasks::Init (IDataObject * pdo, LPOLESTR szTaskGroup)
  120. { // return ok, if we can handle data object and group
  121. if (!lstrcmp (szTaskGroup, L""))
  122. m_type = 1; // default tasks
  123. return S_OK;
  124. }