⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multipanestatusbarex.h

📁 这是一本学习 window编程的很好的参考教材
💻 H
📖 第 1 页 / 共 2 页
字号:
	}
	void AnimDestroyWindow(void)
	{
		if (::IsWindow(m_Anim.m_hWnd))
		{
			m_Anim.Close();
			m_Anim.ShowWindow(SW_HIDE);
			m_Anim.DestroyWindow();
		}
		m_Anim.m_hWnd = NULL;
		m_iAnimPane = -1;
	}
	BEGIN_MSG_MAP(CMPSBarWithBitmaps<TParent>)
		MESSAGE_HANDLER(SB_SIMPLE, OnSimple)
	END_MSG_MAP()
		
	// The animation should be displayed only when the status bar is in multiple pane mode.
	LRESULT OnSimple(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		if (::IsWindow(m_Anim.m_hWnd))
			m_Anim.ShowWindow(wParam ? SW_HIDE: SW_SHOW);

		bHandled = FALSE;
		return 0;
	}

	// Move the animation around when the pane on top of which it lies also moves.
    BOOL UpdatePanesLayout(void)
	{
		if (m_iAnimPane != -1)
		{
			T* pt = static_cast<T*>(this);
			RECT rc;
			pt->GetRect(m_iAnimPane, &rc);
			::InflateRect(&rc, -1, -1); 
			m_Anim.MoveWindow(&rc);
		}
		return TRUE; // Mixed function.
	}
	// Create an animation.
	BOOL AnimCreate(int iPane,         // Status pane where we'll create the progress bar.
#if _WTL_VER >= 0x0710	// It's nice when WTL stuff makes it into ATL, we can keep hoping...  ;-)
		ATL::_U_STRINGorID FileName,   // Path to an AVI file, or resouce holding it.
#else
		WTL::_U_STRINGorID FileName,   // Path to an AVI file, or resouce holding it.
#endif
		DWORD dwStyle =	ACS_TRANSPARENT | ACS_CENTER | ACS_AUTOPLAY, // OR to this if adding styles
		DWORD dwExStyle = 0
		) 
	{
		// Check there is such a pane
		T* pt = static_cast<T*>(this);
		ATLASSERT(::IsWindow(pt->m_hWnd));
		if (0 > iPane || iPane >= pt->m_nPanes)
			return FALSE;
		// Check there is not an animation already open.
		if (::IsWindow(m_Anim.m_hWnd))
			return FALSE;
		// Get the pane's rectangle
		RECT rc;
		pt->GetRect( iPane, &rc );
		::InflateRect(&rc, -1, -1); 
	
		// Create the window, using the status bar (this) as a parent.
		m_Anim.Create ( pt->m_hWnd, rc, NULL, WS_VISIBLE | WS_CHILD | dwStyle,  dwExStyle); 
		if (!m_Anim.Open(FileName))
			return FALSE;
		if (!m_Anim.Play(0, -1, -1))
			return FALSE;
		// Hold this, we'll need it to move around.
		m_iAnimPane = iPane;
		return TRUE;
	}
	
	//  Simple containment
	BOOL AnimSeek(UINT nTo)                        { return m_Anim.Seek(nTo); }
	BOOL AnimStop()                                { m_Anim.Stop(); }
	BOOL AnimPlay(UINT nFrom, UINT nTo, UINT nRep) { return m_Anim.Play(nFrom, nTo, nRep); }
	
protected:
	CAnimateCtrl m_Anim;	  // The contained control
    int m_iAnimPane;          // Pane ordinal where the progress bar resides, or -1 when off.
};


template <class T> class CAnyhingInPaneImpl
{
public:
	// You can have up to 15 free-style controls per status bar.
	enum { MAX_ANY = 15 };

	BEGIN_MSG_MAP(CAnyhingInPaneImpl<T>)
		MESSAGE_HANDLER(SB_SIMPLE, OnSimple)
	END_MSG_MAP()
	
	// Show bitmaps when the status bar is in multi pane state, hide them when it's simple.
	LRESULT OnSimple(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		int sw = (wParam) ? SW_HIDE: SW_SHOW;
		// Hide all children (static bitmaps)
		for (int i = 0; i < MAX_ANY; i++)
		{
			if (m_AnyManager[i].hw)
				::ShowWindow(m_AnyManager[i].hw, sw);
		}
		bHandled = false;
		return 0;
	}
	
	// Move free-style controls around to stay on top of their panes.
	BOOL UpdatePanesLayout(void)
	{
		RECT rc;	
		T *pT = static_cast<T*>(this);
		for (int i = 0;   i < MAX_ANY; i++)
		{
			if (m_AnyManager[i].hw)
			{
				pT->GetRect( m_AnyManager[i].iPane, &rc );
				::InflateRect(&rc, -1, -1); 
				CWindow cs(m_AnyManager[i].hw);
				cs.MoveWindow(&rc);
				cs.Invalidate();
			}
		} // for
		return TRUE;
	}
	// Add a window to the status bar, in a pane chosen by ordinal.
	BOOL AddAny(int iPane, // Zero based ordinal (not resource ID) of the chosen pane.
		        HWND hw, // Handle to a window, whatever control you like (or a dialog of yours)...
		        bool bManage = false) // If true, DestroyWindow() will be called on the HWND.
	{
		if (!::IsWindow(hw))
			return false;
		// If the pane was in use, release it.
		if (!FreeAny(iPane))
			return FALSE;
		// Use the first available array entry to put the selected bitmap.
		T *pT = static_cast<T *>(this);
		for (int i = 0; i < MAX_ANY; i++)
		{
			if (!m_AnyManager[i].hw)
			{
				RECT rct;
				pT->GetRect( iPane, &rct);
				::InflateRect(&rct, -1, -1);
				CWindow wnd;
				wnd.Attach(hw);
				wnd.MoveWindow(&rct);
				m_AnyManager[i].hw = hw;
				m_AnyManager[i].iPane = iPane;
				m_AnyManager[i].bManage = bManage;
				UpdatePanesLayout();
				return TRUE;
			}
		}
		return FALSE;
	}
	// If there is a window in the selected pane, hide it and unlink it from the pane.
	BOOL FreeAny(int iPane)
	{
		T *pT = static_cast<T *>(this);
		// Check we're really talking about a pane.
		if (iPane < 0 || iPane >= pT->m_nPanes)
			return FALSE;
		// Find the pane in the array.
		for (int i = 0; i < MAX_ANY; i++)
		{
			if (m_AnyManager[i].iPane == iPane)
			{
				// If the pane is in use, release whatever is there.
				if (m_AnyManager[i].bManage && ::IsWindow(m_AnyManager[i].hw))
					::DestroyWindow(m_AnyManager[i].hw);
				::ShowWindow(m_AnyManager[i].hw, SW_HIDE);
				// Initialize array entry to suitable values.        
				m_AnyManager[i].Clear();
				break;
			}
		}
		return TRUE; // The pane exists, and is free.
	}
	CAnyhingInPaneImpl<T>()
	{
	}
	
	virtual ~CAnyhingInPaneImpl<T>()
	{
		// Destroy all windows, release all managed bitmaps.
		for (int i = 0; i < MAX_ANY; i++)
		{
			if (m_AnyManager[i].bManage && ::IsWindow(m_AnyManager[i].hw))
				::DestroyWindow(m_AnyManager[i].hw);
		}
	}
	
   protected:
		// This class ties one bitmap/HWND/pane.	   
	   class CAnyManager
	   {
	   public:
		   HWND hw;
		   short iPane;
		   bool bManage; 
		   CAnyManager(): hw(NULL), bManage(false), iPane(-1)
		   {}
		   void Clear(void)
		   {
				hw = NULL;
				bManage = false;
				iPane = -1;
		   }
	   };  // class CBmpManager
	   CAnyManager m_AnyManager[MAX_ANY]; // 15 are more than enough, I hope.
	   
}; // class CAnyhingInPaneImpl



/////////////////////////////////////////////////////////////////////////////////////////
// Concrete classes, you can use them as member variables.
/////////////////////////////////////////////////////////////////////////////////////////

// This class adds progress bar functionality to a multi pane status bar
class CMPSBarWithProgress: 
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgress>,
	  public CProgressBarInPaneImpl<CMPSBarWithProgress>

{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithProgress"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithProgress)
		CHAIN_MSG_MAP(CProgressBarInPaneImpl<CMPSBarWithProgress>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgress>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgress>::UpdatePanesLayout();
		CProgressBarInPaneImpl<CMPSBarWithProgress>::UpdatePanesLayout();
		return ret;
	}
};	// class CMPSBarWithProgress


// This class adds bitmap functionality (up to 15) to a multi pane status bar
class CMPSBarWithBitmaps:
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithBitmaps>,
	  public CBitmapInPaneImpl<CMPSBarWithBitmaps>
{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithBitmaps"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithBitmaps)
		CHAIN_MSG_MAP(CBitmapInPaneImpl<CMPSBarWithBitmaps>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithBitmaps>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithBitmaps>::UpdatePanesLayout();
 		CBitmapInPaneImpl<CMPSBarWithBitmaps>::UpdatePanesLayout();
		return ret;
	}
}; // CMPSBarWithBitmaps

// This class adds progress bar and bitmap functionality to a multi pane status bar
class CMPSBarWithProgressAndBMP: 
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgressAndBMP>,
	  public CProgressBarInPaneImpl<CMPSBarWithProgressAndBMP>,
	  public CBitmapInPaneImpl<CMPSBarWithProgressAndBMP>

{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithProgressAndBMP"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithProgressAndBMP)
		CHAIN_MSG_MAP(CProgressBarInPaneImpl<CMPSBarWithProgressAndBMP>)
		CHAIN_MSG_MAP(CBitmapInPaneImpl<CMPSBarWithProgressAndBMP>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgressAndBMP>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithProgressAndBMP>::UpdatePanesLayout();
 		CBitmapInPaneImpl<CMPSBarWithProgressAndBMP>::UpdatePanesLayout();
		CProgressBarInPaneImpl<CMPSBarWithProgressAndBMP>::UpdatePanesLayout();
		return ret;
	}
}; // CMPSBarWithProgressAndBMP

// This class adds animation functionality to a multi pane status bar
class CMPSBarWithAnimation: 
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithAnimation>,
	  public CAnimationInPaneImpl<CMPSBarWithAnimation>
{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithAnimation"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithAnimation)
		CHAIN_MSG_MAP(CAnimationInPaneImpl<CMPSBarWithAnimation>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithAnimation>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithAnimation>::UpdatePanesLayout();
		CAnimationInPaneImpl<CMPSBarWithAnimation>::UpdatePanesLayout();
		return ret;
	}
}; // CMPSBarWithAnimation

// This class adds progress bar, bitmap and animation functionality to a multi pane status bar
class CMPSBarWithPrg_BMP_Anim: 
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithPrg_BMP_Anim>,
	  public CProgressBarInPaneImpl<CMPSBarWithPrg_BMP_Anim>,
	  public CBitmapInPaneImpl<CMPSBarWithPrg_BMP_Anim>,
	  public CAnimationInPaneImpl<CMPSBarWithPrg_BMP_Anim>
{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithPrg_BMP_Anim"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithPrg_BMP_Anim)
		CHAIN_MSG_MAP(CProgressBarInPaneImpl<CMPSBarWithPrg_BMP_Anim>)
		CHAIN_MSG_MAP(CAnimationInPaneImpl<CMPSBarWithPrg_BMP_Anim>)
		CHAIN_MSG_MAP(CBitmapInPaneImpl<CMPSBarWithPrg_BMP_Anim>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithPrg_BMP_Anim>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithPrg_BMP_Anim>::UpdatePanesLayout();
 		CBitmapInPaneImpl<CMPSBarWithPrg_BMP_Anim>::UpdatePanesLayout();
 		CAnimationInPaneImpl<CMPSBarWithPrg_BMP_Anim>::UpdatePanesLayout();
		CProgressBarInPaneImpl<CMPSBarWithPrg_BMP_Anim>::UpdatePanesLayout();
		return ret;
	}
}; // CMPSBarWithAll

// This class adds progress bar, bitmap and animation functionality to a multi pane status bar
class CMPSBarWithAll: 
      public CMultiPaneStatusBarCtrlImpl<CMPSBarWithAll>,
	  public CProgressBarInPaneImpl<CMPSBarWithAll>,
	  public CBitmapInPaneImpl<CMPSBarWithAll>,
	  public CAnimationInPaneImpl<CMPSBarWithAll>,
	  public CAnyhingInPaneImpl<CMPSBarWithAll>
{
public:

    DECLARE_WND_SUPERCLASS(_T("CMPSBarWithAll"), GetWndClassName())

	BEGIN_MSG_MAP(CMPSBarWithAll)
		CHAIN_MSG_MAP(CProgressBarInPaneImpl<CMPSBarWithAll>)
		CHAIN_MSG_MAP(CAnimationInPaneImpl<CMPSBarWithAll>)
		CHAIN_MSG_MAP(CBitmapInPaneImpl<CMPSBarWithAll>)
		CHAIN_MSG_MAP(CAnyhingInPaneImpl<CMPSBarWithAll>)
		CHAIN_MSG_MAP(CMultiPaneStatusBarCtrlImpl<CMPSBarWithAll>)
	END_MSG_MAP()

	BOOL UpdatePanesLayout(void)
	{
		BOOL ret = CMultiPaneStatusBarCtrlImpl<CMPSBarWithAll>::UpdatePanesLayout();
		CAnyhingInPaneImpl<CMPSBarWithAll>::UpdatePanesLayout();
 		CBitmapInPaneImpl<CMPSBarWithAll>::UpdatePanesLayout();
 		CAnimationInPaneImpl<CMPSBarWithAll>::UpdatePanesLayout();
		CProgressBarInPaneImpl<CMPSBarWithAll>::UpdatePanesLayout();
		return ret;
	}
}; // CMPSBarWithAll

#endif // !defined(AFX_MULTIPANESTATUSBARWITHPROGRESS_H__D2F37B4C_6E3D_450D_94B5_B14D377226FA__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -