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