Leaked source code of windows server 2003
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.

247 lines
6.1 KiB

  1. #include "shole.h"
  2. #include "ids.h"
  3. //===========================================================================
  4. // CScrapExt : Class definition
  5. //===========================================================================
  6. class CScrapExt : public IShellExtInit, public IShellPropSheetExt
  7. {
  8. public:
  9. CScrapExt();
  10. ~CScrapExt();
  11. HRESULT GetFileName(LPTSTR pszPath);
  12. // IUnKnown
  13. virtual HRESULT __stdcall QueryInterface(REFIID,void **);
  14. virtual ULONG __stdcall AddRef(void);
  15. virtual ULONG __stdcall Release(void);
  16. // IShellExtInit
  17. virtual HRESULT __stdcall Initialize(LPCITEMIDLIST pidlFolder,
  18. LPDATAOBJECT lpdobj, HKEY hkeyProgID);
  19. // IShellPropSheetExt
  20. virtual HRESULT __stdcall AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
  21. virtual HRESULT __stdcall ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam);
  22. protected:
  23. UINT _cRef;
  24. IDataObject* _pdtobj;
  25. };
  26. HRESULT CScrapExt::GetFileName(LPTSTR pszPath)
  27. {
  28. STGMEDIUM medium;
  29. FORMATETC fmte = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  30. HRESULT hres = E_FAIL;
  31. if (_pdtobj)
  32. {
  33. hres = _pdtobj->GetData(&fmte, &medium);
  34. if (hres == S_OK)
  35. {
  36. if (!DragQueryFile((HDROP)medium.hGlobal,0,pszPath,MAX_PATH))
  37. hres = E_FAIL;
  38. ReleaseStgMedium(&medium);
  39. }
  40. }
  41. return hres;
  42. }
  43. HRESULT CScrapExt::QueryInterface(REFIID riid, LPVOID * ppvObj)
  44. {
  45. if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
  46. {
  47. *ppvObj = (IShellExtInit*)this;
  48. _cRef++;
  49. return S_OK;
  50. }
  51. else if (IsEqualIID(riid, IID_IShellPropSheetExt))
  52. {
  53. *ppvObj = (IShellPropSheetExt *)this;
  54. _cRef++;
  55. return S_OK;
  56. }
  57. *ppvObj = NULL;
  58. return E_NOINTERFACE;
  59. }
  60. ULONG CScrapExt::AddRef()
  61. {
  62. _cRef++;
  63. return _cRef;
  64. }
  65. ULONG CScrapExt::Release()
  66. {
  67. _cRef--;
  68. if (_cRef > 0)
  69. return _cRef;
  70. delete this;
  71. return 0;
  72. }
  73. CScrapExt::CScrapExt() : _cRef(1), _pdtobj(NULL)
  74. {
  75. g_cRefThisDll++;
  76. OleInitialize(NULL);
  77. }
  78. CScrapExt::~CScrapExt()
  79. {
  80. if (_pdtobj) {
  81. _pdtobj->Release();
  82. }
  83. OleUninitialize();
  84. g_cRefThisDll--;
  85. }
  86. HRESULT CScrapExt::Initialize(LPCITEMIDLIST pidlFolder,
  87. LPDATAOBJECT pdtobj, HKEY hkeyProgID)
  88. {
  89. DebugMsg(DM_TRACE, TEXT("sc TR - CScrapExt::Initialize called"));
  90. if (pdtobj) {
  91. _pdtobj = pdtobj;
  92. pdtobj->AddRef();
  93. return S_OK;
  94. }
  95. return E_FAIL;
  96. }
  97. //===========================================================================
  98. // CScrapPropSheetPage: Class definition
  99. //
  100. // Notes: Notice that this class has no destructor. It has no destructor
  101. // because the lifetime of the object itself does not mean anything
  102. // -- full contents will be copied by the property sheet code.
  103. // Instead, it has a _Release function which is explicitly called
  104. // when the property sheet handle is destroyed.
  105. //===========================================================================
  106. class CScrapPropSheetPage : public PROPSHEETPAGE // spsp
  107. {
  108. public:
  109. CScrapPropSheetPage(CScrapExt* psext);
  110. protected:
  111. static INT_PTR CALLBACK _DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  112. static UINT CALLBACK _CallBack(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp);
  113. void _Release();
  114. CScrapExt* _psext;
  115. HWND _hdlg;
  116. IOleClientSite* _pcli;
  117. };
  118. CScrapPropSheetPage::CScrapPropSheetPage(CScrapExt* psext)
  119. : _psext(psext), _hdlg(NULL), _pcli(NULL)
  120. {
  121. dwSize = sizeof(CScrapPropSheetPage);
  122. dwFlags = PSP_DEFAULT|PSP_USECALLBACK;
  123. hInstance = HINST_THISDLL;
  124. pszTemplate = MAKEINTRESOURCE(IDD_VIEW);
  125. // hIcon = NULL; // unused (PSP_USEICON is not set)
  126. // pszTitle = NULL; // unused (PSP_USETITLE is not set)
  127. pfnDlgProc = _DlgProc;
  128. // lParam = 0; // unused
  129. pfnCallback = _CallBack;
  130. // pcRefParent = NULL;
  131. _psext->AddRef();
  132. CShClientSite_RegisterClass();
  133. }
  134. void CScrapPropSheetPage::_Release()
  135. {
  136. if (_psext) {
  137. _psext->Release();
  138. }
  139. if (_pcli) {
  140. CShClientSite_Release(_pcli);
  141. }
  142. };
  143. INT_PTR CALLBACK CScrapPropSheetPage::_DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  144. {
  145. HWND hwndView;
  146. CScrapPropSheetPage* pspsp;
  147. switch(uMsg)
  148. {
  149. case WM_INITDIALOG:
  150. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  151. pspsp = (CScrapPropSheetPage *)lParam;
  152. pspsp->_hdlg = hdlg;
  153. hwndView = GetDlgItem(hdlg, IDI_SCRAPVIEW);
  154. if (hwndView) {
  155. SetWindowText(hwndView, TEXT("Not Implemented Yet"));
  156. // SetWindowLongPtr(hwndView, sizeof(LPVOID), (LPARAM)pspsp);
  157. TCHAR szPath[MAX_PATH];
  158. if (SUCCEEDED(pspsp->_psext->GetFileName(szPath)))
  159. {
  160. pspsp->_pcli = CShClientSite_Create(hwndView, szPath);
  161. }
  162. }
  163. break;
  164. }
  165. return FALSE;
  166. }
  167. UINT CALLBACK CScrapPropSheetPage::_CallBack(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  168. {
  169. CScrapPropSheetPage * pspsp = (CScrapPropSheetPage*)ppsp;
  170. switch(uMsg)
  171. {
  172. case PSPCB_RELEASE:
  173. DebugMsg(DM_TRACE, TEXT("sc - TR: _ScrapPageCallBack is releasing _psext"));
  174. pspsp->_Release();
  175. break;
  176. }
  177. return TRUE;
  178. }
  179. HRESULT CScrapExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  180. {
  181. DebugMsg(DM_TRACE, TEXT("sc TR - CScrapExt::AddPage called"));
  182. HPROPSHEETPAGE hpage;
  183. HRESULT hres = S_OK;
  184. CScrapPropSheetPage spsp(this);
  185. hpage = CreatePropertySheetPage(&spsp);
  186. if (hpage)
  187. {
  188. BOOL bResult = lpfnAddPage(hpage, lParam);
  189. if (!bResult)
  190. {
  191. DestroyPropertySheetPage(hpage);
  192. hres = E_FAIL;
  193. }
  194. }
  195. return hres;
  196. }
  197. HRESULT CScrapExt::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
  198. {
  199. return S_FALSE;
  200. }
  201. HRESULT CScrapExt_CreateInstance(LPUNKNOWN * ppunk)
  202. {
  203. DebugMsg(DM_TRACE, TEXT("sc TR - CScrapExt_CreateInstance called"));
  204. CScrapExt* pscd = new CScrapExt();
  205. if (pscd) {
  206. *ppunk = (LPDATAOBJECT)pscd;
  207. return S_OK;
  208. }
  209. return E_OUTOFMEMORY;
  210. }