winctrl.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //------------------------------------------------------------------------------
  2. // File: WinCtrl.h
  3. //
  4. // Desc: DirectShow base classes - defines classes for video control
  5. // interfaces.
  6. //
  7. // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
  8. //------------------------------------------------------------------------------
  9. #ifndef __WINCTRL__
  10. #define __WINCTRL__
  11. #define ABSOL(x) (x < 0 ? -x : x)
  12. #define NEGAT(x) (x > 0 ? -x : x)
  13. // Helper
  14. BOOL WINAPI PossiblyEatMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  15. class CBaseControlWindow : public CBaseVideoWindow, public CBaseWindow
  16. {
  17. protected:
  18. CBaseFilter *m_pFilter; // Pointer to owning media filter
  19. CBasePin *m_pPin; // Controls media types for connection
  20. CCritSec *m_pInterfaceLock; // Externally defined critical section
  21. COLORREF m_BorderColour; // Current window border colour
  22. BOOL m_bAutoShow; // What happens when the state changes
  23. HWND m_hwndOwner; // Owner window that we optionally have
  24. HWND m_hwndDrain; // HWND to post any messages received
  25. BOOL m_bCursorHidden; // Should we hide the window cursor
  26. public:
  27. // Internal methods for other objects to get information out
  28. HRESULT DoSetWindowStyle(long Style,long WindowLong);
  29. HRESULT DoGetWindowStyle(__out long *pStyle,long WindowLong);
  30. BOOL IsAutoShowEnabled() { return m_bAutoShow; };
  31. COLORREF GetBorderColour() { return m_BorderColour; };
  32. HWND GetOwnerWindow() { return m_hwndOwner; };
  33. BOOL IsCursorHidden() { return m_bCursorHidden; };
  34. inline BOOL PossiblyEatMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  35. {
  36. return ::PossiblyEatMessage(m_hwndDrain, uMsg, wParam, lParam);
  37. }
  38. // Derived classes must call this to set the pin the filter is using
  39. // We don't have the pin passed in to the constructor (as we do with
  40. // the CBaseFilter object) because filters typically create the
  41. // pins dynamically when requested in CBaseFilter::GetPin. This can
  42. // not be called from our constructor because is is a virtual method
  43. void SetControlWindowPin(CBasePin *pPin) {
  44. m_pPin = pPin;
  45. }
  46. public:
  47. CBaseControlWindow(__inout CBaseFilter *pFilter, // Owning media filter
  48. __in CCritSec *pInterfaceLock, // Locking object
  49. __in_opt LPCTSTR pName, // Object description
  50. __inout_opt LPUNKNOWN pUnk, // Normal COM ownership
  51. __inout HRESULT *phr); // OLE return code
  52. // These are the properties we support
  53. STDMETHODIMP put_Caption(__in BSTR strCaption);
  54. STDMETHODIMP get_Caption(__out BSTR *pstrCaption);
  55. STDMETHODIMP put_AutoShow(long AutoShow);
  56. STDMETHODIMP get_AutoShow(__out long *AutoShow);
  57. STDMETHODIMP put_WindowStyle(long WindowStyle);
  58. STDMETHODIMP get_WindowStyle(__out long *pWindowStyle);
  59. STDMETHODIMP put_WindowStyleEx(long WindowStyleEx);
  60. STDMETHODIMP get_WindowStyleEx(__out long *pWindowStyleEx);
  61. STDMETHODIMP put_WindowState(long WindowState);
  62. STDMETHODIMP get_WindowState(__out long *pWindowState);
  63. STDMETHODIMP put_BackgroundPalette(long BackgroundPalette);
  64. STDMETHODIMP get_BackgroundPalette(__out long *pBackgroundPalette);
  65. STDMETHODIMP put_Visible(long Visible);
  66. STDMETHODIMP get_Visible(__out long *pVisible);
  67. STDMETHODIMP put_Left(long Left);
  68. STDMETHODIMP get_Left(__out long *pLeft);
  69. STDMETHODIMP put_Width(long Width);
  70. STDMETHODIMP get_Width(__out long *pWidth);
  71. STDMETHODIMP put_Top(long Top);
  72. STDMETHODIMP get_Top(__out long *pTop);
  73. STDMETHODIMP put_Height(long Height);
  74. STDMETHODIMP get_Height(__out long *pHeight);
  75. STDMETHODIMP put_Owner(OAHWND Owner);
  76. STDMETHODIMP get_Owner(__out OAHWND *Owner);
  77. STDMETHODIMP put_MessageDrain(OAHWND Drain);
  78. STDMETHODIMP get_MessageDrain(__out OAHWND *Drain);
  79. STDMETHODIMP get_BorderColor(__out long *Color);
  80. STDMETHODIMP put_BorderColor(long Color);
  81. STDMETHODIMP get_FullScreenMode(__out long *FullScreenMode);
  82. STDMETHODIMP put_FullScreenMode(long FullScreenMode);
  83. // And these are the methods
  84. STDMETHODIMP SetWindowForeground(long Focus);
  85. STDMETHODIMP NotifyOwnerMessage(OAHWND hwnd,long uMsg,LONG_PTR wParam,LONG_PTR lParam);
  86. STDMETHODIMP GetMinIdealImageSize(__out long *pWidth,__out long *pHeight);
  87. STDMETHODIMP GetMaxIdealImageSize(__out long *pWidth,__out long *pHeight);
  88. STDMETHODIMP SetWindowPosition(long Left,long Top,long Width,long Height);
  89. STDMETHODIMP GetWindowPosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight);
  90. STDMETHODIMP GetRestorePosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight);
  91. STDMETHODIMP HideCursor(long HideCursor);
  92. STDMETHODIMP IsCursorHidden(__out long *CursorHidden);
  93. };
  94. // This class implements the IBasicVideo interface
  95. class CBaseControlVideo : public CBaseBasicVideo
  96. {
  97. protected:
  98. CBaseFilter *m_pFilter; // Pointer to owning media filter
  99. CBasePin *m_pPin; // Controls media types for connection
  100. CCritSec *m_pInterfaceLock; // Externally defined critical section
  101. public:
  102. // Derived classes must provide these for the implementation
  103. virtual HRESULT IsDefaultTargetRect() PURE;
  104. virtual HRESULT SetDefaultTargetRect() PURE;
  105. virtual HRESULT SetTargetRect(RECT *pTargetRect) PURE;
  106. virtual HRESULT GetTargetRect(RECT *pTargetRect) PURE;
  107. virtual HRESULT IsDefaultSourceRect() PURE;
  108. virtual HRESULT SetDefaultSourceRect() PURE;
  109. virtual HRESULT SetSourceRect(RECT *pSourceRect) PURE;
  110. virtual HRESULT GetSourceRect(RECT *pSourceRect) PURE;
  111. virtual HRESULT GetStaticImage(__inout long *pBufferSize,__out_bcount_part(*pBufferSize, *pBufferSize) long *pDIBImage) PURE;
  112. // Derived classes must override this to return a VIDEOINFO representing
  113. // the video format. We cannot call IPin ConnectionMediaType to get this
  114. // format because various filters dynamically change the type when using
  115. // DirectDraw such that the format shows the position of the logical
  116. // bitmap in a frame buffer surface, so the size might be returned as
  117. // 1024x768 pixels instead of 320x240 which is the real video dimensions
  118. __out virtual VIDEOINFOHEADER *GetVideoFormat() PURE;
  119. // Helper functions for creating memory renderings of a DIB image
  120. HRESULT GetImageSize(__in VIDEOINFOHEADER *pVideoInfo,
  121. __out LONG *pBufferSize,
  122. __in RECT *pSourceRect);
  123. HRESULT CopyImage(IMediaSample *pMediaSample,
  124. __in VIDEOINFOHEADER *pVideoInfo,
  125. __inout LONG *pBufferSize,
  126. __out_bcount_part(*pBufferSize, *pBufferSize) BYTE *pVideoImage,
  127. __in RECT *pSourceRect);
  128. // Override this if you want notifying when the rectangles change
  129. virtual HRESULT OnUpdateRectangles() { return NOERROR; };
  130. virtual HRESULT OnVideoSizeChange();
  131. // Derived classes must call this to set the pin the filter is using
  132. // We don't have the pin passed in to the constructor (as we do with
  133. // the CBaseFilter object) because filters typically create the
  134. // pins dynamically when requested in CBaseFilter::GetPin. This can
  135. // not be called from our constructor because is is a virtual method
  136. void SetControlVideoPin(__inout CBasePin *pPin) {
  137. m_pPin = pPin;
  138. }
  139. // Helper methods for checking rectangles
  140. virtual HRESULT CheckSourceRect(__in RECT *pSourceRect);
  141. virtual HRESULT CheckTargetRect(__in RECT *pTargetRect);
  142. public:
  143. CBaseControlVideo(__inout CBaseFilter *pFilter, // Owning media filter
  144. __in CCritSec *pInterfaceLock, // Serialise interface
  145. __in_opt LPCTSTR pName, // Object description
  146. __inout_opt LPUNKNOWN pUnk, // Normal COM ownership
  147. __inout HRESULT *phr); // OLE return code
  148. // These are the properties we support
  149. STDMETHODIMP get_AvgTimePerFrame(__out REFTIME *pAvgTimePerFrame);
  150. STDMETHODIMP get_BitRate(__out long *pBitRate);
  151. STDMETHODIMP get_BitErrorRate(__out long *pBitErrorRate);
  152. STDMETHODIMP get_VideoWidth(__out long *pVideoWidth);
  153. STDMETHODIMP get_VideoHeight(__out long *pVideoHeight);
  154. STDMETHODIMP put_SourceLeft(long SourceLeft);
  155. STDMETHODIMP get_SourceLeft(__out long *pSourceLeft);
  156. STDMETHODIMP put_SourceWidth(long SourceWidth);
  157. STDMETHODIMP get_SourceWidth(__out long *pSourceWidth);
  158. STDMETHODIMP put_SourceTop(long SourceTop);
  159. STDMETHODIMP get_SourceTop(__out long *pSourceTop);
  160. STDMETHODIMP put_SourceHeight(long SourceHeight);
  161. STDMETHODIMP get_SourceHeight(__out long *pSourceHeight);
  162. STDMETHODIMP put_DestinationLeft(long DestinationLeft);
  163. STDMETHODIMP get_DestinationLeft(__out long *pDestinationLeft);
  164. STDMETHODIMP put_DestinationWidth(long DestinationWidth);
  165. STDMETHODIMP get_DestinationWidth(__out long *pDestinationWidth);
  166. STDMETHODIMP put_DestinationTop(long DestinationTop);
  167. STDMETHODIMP get_DestinationTop(__out long *pDestinationTop);
  168. STDMETHODIMP put_DestinationHeight(long DestinationHeight);
  169. STDMETHODIMP get_DestinationHeight(__out long *pDestinationHeight);
  170. // And these are the methods
  171. STDMETHODIMP GetVideoSize(__out long *pWidth,__out long *pHeight);
  172. STDMETHODIMP SetSourcePosition(long Left,long Top,long Width,long Height);
  173. STDMETHODIMP GetSourcePosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight);
  174. STDMETHODIMP GetVideoPaletteEntries(long StartIndex,long Entries,__out long *pRetrieved,__out_ecount_part(Entries, *pRetrieved) long *pPalette);
  175. STDMETHODIMP SetDefaultSourcePosition();
  176. STDMETHODIMP IsUsingDefaultSource();
  177. STDMETHODIMP SetDestinationPosition(long Left,long Top,long Width,long Height);
  178. STDMETHODIMP GetDestinationPosition(__out long *pLeft,__out long *pTop,__out long *pWidth,__out long *pHeight);
  179. STDMETHODIMP SetDefaultDestinationPosition();
  180. STDMETHODIMP IsUsingDefaultDestination();
  181. STDMETHODIMP GetCurrentImage(__inout long *pBufferSize,__out_bcount_part(*pBufferSize, *pBufferSize) long *pVideoImage);
  182. };
  183. #endif // __WINCTRL__