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.

218 lines
5.8 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "prevwnd.h"
  4. #include <shpriv.h>
  5. DWORD g_dwThreadID = 0;
  6. class CAutoplayForSlideShow : public IHWEventHandler,
  7. public IDropTarget,
  8. public NonATLObject
  9. {
  10. public:
  11. CAutoplayForSlideShow() : _cRef(1) {}
  12. // IUnknown
  13. STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
  14. STDMETHOD_(ULONG, AddRef)();
  15. STDMETHOD_(ULONG, Release)();
  16. // IHWEventHandler
  17. STDMETHOD(Initialize)(LPCWSTR pszParams);
  18. STDMETHOD(HandleEvent)(LPCWSTR pszDeviceID, LPCWSTR pszAltDeviceID,
  19. LPCWSTR pszEventType);
  20. STDMETHOD(HandleEventWithContent)(LPCWSTR pszDeviceID,
  21. LPCWSTR pszAltDeviceID, LPCWSTR pszEventType,
  22. LPCWSTR pszContentTypeHandler, IDataObject* pdtobj);
  23. // IDropTarget ***
  24. STDMETHODIMP DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  25. STDMETHODIMP DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  26. STDMETHODIMP DragLeave(void);
  27. STDMETHODIMP Drop(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
  28. private:
  29. LONG _cRef;
  30. };
  31. STDMETHODIMP CAutoplayForSlideShow::QueryInterface(REFIID riid, void **ppv)
  32. {
  33. static const QITAB qit[] =
  34. {
  35. QITABENT(CAutoplayForSlideShow, IHWEventHandler),
  36. QITABENT(CAutoplayForSlideShow, IDropTarget),
  37. { 0 },
  38. };
  39. return QISearch(this, qit, riid, ppv);
  40. }
  41. STDMETHODIMP_(ULONG) CAutoplayForSlideShow::AddRef()
  42. {
  43. return InterlockedIncrement(&_cRef);
  44. }
  45. STDMETHODIMP_(ULONG) CAutoplayForSlideShow::Release()
  46. {
  47. ASSERT( 0 != _cRef );
  48. ULONG cRef = InterlockedDecrement(&_cRef);
  49. if ( 0 == cRef )
  50. {
  51. delete this;
  52. }
  53. return cRef;
  54. }
  55. STDAPI CAutoplayForSlideShow_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  56. {
  57. CAutoplayForSlideShow* pass = new CAutoplayForSlideShow();
  58. if (!pass)
  59. {
  60. *ppunk = NULL; // incase of failure
  61. return E_OUTOFMEMORY;
  62. }
  63. HRESULT hr = pass->QueryInterface(IID_PPV_ARG(IUnknown, ppunk));
  64. pass->Release();
  65. return hr;
  66. }
  67. STDMETHODIMP CAutoplayForSlideShow::Initialize(LPCWSTR)
  68. {
  69. // We don't care about params a this point
  70. return S_OK;
  71. }
  72. STDMETHODIMP CAutoplayForSlideShow::HandleEvent(LPCWSTR pszDeviceID,
  73. LPCWSTR pszAltDeviceID, LPCWSTR pszEventType)
  74. {
  75. return E_NOTIMPL;
  76. }
  77. DWORD WINAPI SlideShowThread(void* pv)
  78. {
  79. IStream *pstm = (IStream *)pv;
  80. IDataObject* pdtobj;
  81. HRESULT hr = CoGetInterfaceAndReleaseStream(pstm, IID_PPV_ARG(IDataObject, &pdtobj));
  82. if (SUCCEEDED(hr))
  83. {
  84. CPreviewWnd cwndPreview;
  85. hr = cwndPreview.Initialize(NULL, SLIDESHOW_MODE, TRUE);
  86. if (SUCCEEDED(hr))
  87. {
  88. // 4 is the walk depth, make sure we pick up pictures
  89. if (cwndPreview.CreateSlideshowWindow(4))
  90. {
  91. hr = cwndPreview.StartSlideShow(pdtobj);
  92. if (SUCCEEDED(hr))
  93. {
  94. MSG msg;
  95. while (GetMessage(&msg, NULL, 0, 0))
  96. {
  97. TranslateMessage(&msg);
  98. DispatchMessage(&msg);
  99. }
  100. ::PostThreadMessage(g_dwThreadID, WM_QUIT, 0, 0);
  101. }
  102. }
  103. else
  104. {
  105. hr = E_FAIL;
  106. }
  107. }
  108. pdtobj->Release();
  109. }
  110. return hr;
  111. }
  112. HRESULT _StartSlideShowThread(IDataObject *pdo)
  113. {
  114. IStream *pstm;
  115. HRESULT hr = CoMarshalInterThreadInterfaceInStream(IID_IDataObject, pdo, &pstm);
  116. if (SUCCEEDED(hr))
  117. {
  118. // maybe do threadref?
  119. if (!SHCreateThread(SlideShowThread, pstm, CTF_COINIT, NULL))
  120. {
  121. pstm->Release();
  122. hr = E_FAIL;
  123. }
  124. }
  125. return hr;
  126. }
  127. STDMETHODIMP CAutoplayForSlideShow::HandleEventWithContent(
  128. LPCWSTR pszDeviceID, LPCWSTR pszAltDeviceID, LPCWSTR pszEventType,
  129. LPCWSTR pszContentTypeHandler, IDataObject* pdtobj)
  130. {
  131. return _StartSlideShowThread(pdtobj);
  132. }
  133. // IDropTarget::DragEnter
  134. HRESULT CAutoplayForSlideShow::DragEnter(IDataObject *pdtobj, DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  135. {
  136. *pdwEffect = DROPEFFECT_COPY;
  137. return S_OK;;
  138. }
  139. // IDropTarget::DragOver
  140. HRESULT CAutoplayForSlideShow::DragOver(DWORD grfKeyState, POINTL ptl, DWORD *pdwEffect)
  141. {
  142. *pdwEffect = DROPEFFECT_COPY;
  143. return S_OK;;
  144. }
  145. // IDropTarget::DragLeave
  146. HRESULT CAutoplayForSlideShow::DragLeave(void)
  147. {
  148. return S_OK;
  149. }
  150. // IDropTarget::DragDrop
  151. HRESULT CAutoplayForSlideShow::Drop(IDataObject *pdtobj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
  152. {
  153. *pdwEffect = DROPEFFECT_COPY;
  154. return _StartSlideShowThread(pdtobj);
  155. }
  156. void WINAPI ImageView_COMServer(HWND hwnd, HINSTANCE hAppInstance, LPTSTR pszCmdLine, int nCmdShow)
  157. {
  158. HRESULT hrOle = SHCoInitialize();
  159. if (SUCCEEDED(hrOle))
  160. {
  161. g_dwThreadID = GetCurrentThreadId();
  162. IUnknown* punkFact;
  163. // the preview window will init GDI+
  164. HRESULT hr = DllGetClassObject(CLSID_AutoplayForSlideShow, IID_PPV_ARG(IUnknown, &punkFact));
  165. if (SUCCEEDED(hr))
  166. {
  167. DWORD dwROC;
  168. hr = CoRegisterClassObject(CLSID_AutoplayForSlideShow, punkFact, CLSCTX_LOCAL_SERVER,
  169. REGCLS_SINGLEUSE, &dwROC);
  170. if (SUCCEEDED(hr))
  171. {
  172. MSG msg;
  173. while (GetMessage(&msg, NULL, 0, 0))
  174. {
  175. TranslateMessage(&msg);
  176. DispatchMessage(&msg);
  177. }
  178. CoRevokeClassObject(dwROC);
  179. }
  180. punkFact->Release();
  181. }
  182. SHCoUninitialize(hrOle);
  183. }
  184. }