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

📄 xfloorwndctl.cpp

📁 类似于OutLook窗口的XFloorWnd ActiveX控件源程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					if (bDown)
					{
						rScroll.top = GetPage(nIndex)->m_rect.bottom;
						rScroll.bottom = m_rectClient.bottom;
						dyScroll = rScroll.bottom  - rScroll.top;
						if (m_bAsPage)
							for (int i = nIndex + 1; (i < GetCountPage()) && GetPage(i)->IsPullUp(); i++)
								dyScroll -= GetPage(i)->m_rect.Height() + 1;
					}
					else
					{
						rScroll.top = m_rectClient.top;
						rScroll.bottom = GetPage(nIndex)->m_rect.bottom + 1;
						dyScroll = rScroll.bottom  - rScroll.top;
						if (m_bAsPage)
							for (int i = nIndex; (i >=0 ) && GetPage(i)->IsPullDown(); i--)
								dyScroll -= GetPage(i)->m_rect.Height() + 1;
					}
					int nStep = 5;
					int nWhere = bDown ? nStep : -nStep;
					pPage->SetRectClient(m_rectClient);
					CBitmap* pBitmap = Preview(pPage->GetWindow());
					int tScroll = 0, dy = 0;
					for (int s = 0; s < dyScroll ; s += nStep)
					{
						dy = bDown ? max(0,min(nWhere,dyScroll-s)) : min(nWhere,dyScroll-s);
						::ScrollWindow(m_hWnd, 0, dy ,NULL,rScroll);
						tScroll += abs(dy);
						CDC* pDC = GetDC();
						CDC dcMem;
						if (dcMem.CreateCompatibleDC(pDC))
						{
							COLORREF colorBkGnd = TranslateColor(GetBackColor());
							CBrush brBkGnd(colorBkGnd);
							CBrush* pOldBrush = pDC->SelectObject(&brBkGnd);
							CBitmap* pOldBitmap = dcMem.SelectObject(pBitmap);
							if (bDown)
							{
								CRect rCS(CPoint(m_rectClient.left ,rScroll.top), CSize(m_rectClient.Width() , tScroll));
								pDC->PatBlt(rScroll.left,rScroll.top, rCS.left - rScroll.left, rCS.bottom - rScroll.top, PATCOPY);
								pDC->BitBlt(rCS.left ,rCS.top, rCS.Width() , rCS.Height(), &dcMem, 0, m_rectClient.Height() - tScroll, SRCCOPY);
								pDC->PatBlt(rCS.right ,rCS.top, rScroll.right - rCS.right, rCS.bottom - rScroll.top, PATCOPY);
							}
							else
							{
								CRect rCS(CPoint(m_rectClient.left ,rScroll.bottom - tScroll), CSize(m_rectClient.Width() , tScroll));
								pDC->PatBlt(rScroll.left,rCS.top, rCS.left - rScroll.left, rCS.Height(), PATCOPY);
								pDC->BitBlt(rCS.left ,rCS.top, rCS.Width() , rCS.Height(), &dcMem, 0, 0 , SRCCOPY);
								pDC->PatBlt(rCS.right,rCS.top, rScroll.right - rCS.right, rCS.Height(), PATCOPY);
							}
							dcMem.SelectObject(pOldBitmap);
							pDC->SelectObject(pOldBrush);
						}

						ReleaseDC(pDC);
						if (m_nSleep > 0)
							Sleep(m_nSleep * MulSleep);
					}
					delete pBitmap;
				}
				::SetThreadPriority(hThread, tPriority);
			}
}

// Function name	: CXFloorWndCtrl::OnLButtonDown
// Description	    : Call when user click the mouse
// Update			: Version 1.01
// Return type		: void 
// Argument         : UINT nFlags
// Argument         : CPoint point
void CXFloorWndCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	SetFocus();
	if (CFloorPageObject* pPage = GetPageFromPoint(point))
	{
		int nIndex = PtrPageToIndex(pPage);
		if (pPage != GetActivePage())
		{
			if (pPage->IsPullUp())
				PullDownPages(nIndex);
			else
				PullUpPages(nIndex);
		}
		else
			FireClickOnActivePage(nIndex);
	}
		
	COleControl::OnLButtonDown(nFlags, point);
}

void CXFloorWndCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	COleControl::OnLButtonUp(nFlags, point);
}

void CXFloorWndCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	CFloorPageObject* pPage = GetPageFromPoint(point);
	if (pPage)
		if (m_pFocusPage != pPage)
			if (pPage != m_pActivePage)
				pPage->OnFocus();
	if (m_pFocusPage)
		if (m_pFocusPage != pPage)
			m_pFocusPage->Invalidate(TRUE);
	m_pFocusPage = pPage;

	// Try to put a timer to erase the focused page when cursor outrun the area of this window
	KillTimer(IDTIMERERASEFOCUS);
	if (m_pFocusPage)
		SetTimer(IDTIMERERASEFOCUS, UPDATEIDTIMERERASEFOCUS, NULL);
	
	COleControl::OnMouseMove(nFlags, point);
}

// Function name	: CXFloorWndCtrl::GetPageFromPoint
// Description	    : Return page from point
// Return type		: CFloorPageObject* 
// Argument         : CPoint point
CFloorPageObject* CXFloorWndCtrl::GetPageFromPoint(CPoint point)
{
	for (int i = 0; i < GetCountPage(); i++)
		if (GetPage(i)->PtInObject(point))
			return GetPage(i);
	return NULL;
}

// Function name	: CXFloorWndCtrl::DeletePage
// Description	    : Delete the page with index nIndex. Call ActivatePage after
// Update			: Version 1.01
// Return type		: BOOL 
// Argument         : int nIndex
BOOL CXFloorWndCtrl::DeletePage(int nIndex)
{
	if (CFloorPageObject* pPage = GetPage(nIndex))
	{
		BOOL bDeleteActivePage = pPage == GetActivePage();
		delete pPage;
		m_pArPage->RemoveAt(nIndex);
		if (bDeleteActivePage)
			m_pActivePage = NULL;
		PullUpPages(nIndex);
		RecalcLayout();
		if (bDeleteActivePage)
			ActivatePage(max(min(nIndex, GetCountPage()-1),0));
		return TRUE;
	}
	return FALSE;
}

// Function name	: CXFloorWndCtrl::DeletePage
// Description	    : 
// Return type		: BOOL 
// Argument         : LPCTSTR lpszPageName
BOOL CXFloorWndCtrl::DeletePage(LPCTSTR lpszPageName)
{
	return DeletePage(PtrPageToIndex(GetPage(lpszPageName)));
}

// Function name	: CXFloorWndCtrl::OnTimer
// Description	    : Put a timer to erase the focus page if mouse pointer is outside of this window
// Return type		: void 
// Argument         : UINT nIDEvent
void CXFloorWndCtrl::OnTimer(UINT nIDEvent) 
{
	switch (nIDEvent)
	{
		case IDTIMERERASEFOCUS:
		{
			CPoint p; ::GetCursorPos(&p);
			if (this != CWnd::WindowFromPoint(p))
			{
				if (m_pFocusPage)
					m_pFocusPage->Invalidate(TRUE);
				m_pFocusPage = NULL;
				KillTimer(IDTIMERERASEFOCUS);
			}
			break;
		}
		case IDSTARTMOVELABEL:
		{
			KillTimer(IDSTARTMOVELABEL);
			CComboBox* pCombo = (CComboBox*)GetDlgItem(ID_LABELCOMBO);
			int nItem = pCombo->GetCurSel();
			CFloorPageObject* pPage = (CFloorPageObject*)pCombo->GetItemData(nItem);
			ActivatePage(PtrPageToIndex(pPage));
		}
	}
	
	COleControl::OnTimer(nIDEvent);
}

// Function name	: CXFloorWndCtrl::OnEraseBkgnd
// Description	    : Do not erase bkgnd of this control
// Return type		: BOOL 
// Argument         : CDC* pDC
BOOL CXFloorWndCtrl::OnEraseBkgnd(CDC* pDC) 
{
	return TRUE;
}

// Function name	: CXFloorWndCtrl::AddPage
// Description	    : Add a new Page. Called by interface
// Return type		: short 
// Argument         : LPCTSTR sName
short CXFloorWndCtrl::_AddPage(LPCTSTR sName) 
{
	int nIndex = NULL;
	AddPage(sName, &nIndex);
	return nIndex;
}

// Function name	: CXFloorWndCtrl::_DeletePage
// Description	    : Delete page nIndex. Called by interface
// Return type		: BOOL 
// Argument         : short nIndex
BOOL CXFloorWndCtrl::_DeletePage(short nIndex) 
{
	if (DeletePage(nIndex))
	{
		RecalcLayout();
		Invalidate();
		return TRUE;
	}
	return FALSE;
}

// Function name	: CXFloorWndCtrl::_GetPageName
// Description	    : return the name of page
// Return type		: BSTR 
// Argument         : short nIndex
BSTR CXFloorWndCtrl::_GetPageName(short nIndex) 
{
	CString strResult;
	if (CFloorPageObject* pPage = GetPage(nIndex))
		strResult = pPage->GetName();
	return strResult.AllocSysString();
}

// Function name	: CXFloorWndCtrl::_GetPage
// Description	    : 
// Return type		: short 
// Argument         : LPCTSTR lpszPageName
short CXFloorWndCtrl::_GetPage(LPCTSTR lpszPageName) 
{
	return PtrPageToIndex(GetPage(lpszPageName));
}

// Function name	: CXFloorWndCtrl::_ActivatePage
// Description	    : 
// Return type		: BOOL 
// Argument         : short nIndex
BOOL CXFloorWndCtrl::_ActivatePage(short nIndex) 
{
	ActivatePage(nIndex);
	return TRUE;
}

// Function name	: CXFloorWndCtrl::_AttachWindow
// Description	    : AttachWindow
// Return type		: BOOL 
// Argument         : short nIndex
// Argument         : long hWnd
BOOL CXFloorWndCtrl::_AttachWindow(short nIndex, long pWnd) 
{
	CWnd* pWndClient = (CWnd*)pWnd;
	if (pWndClient)
		if (::IsWindow(pWndClient->m_hWnd))
			if (CFloorPageObject* pPage = GetPage(nIndex))
				{
					pPage->Attach(pWndClient);
					return TRUE;
				}
	return FALSE;
}

// Function name	: CXFloorWndCtrl::_SetPageName
// Description	    : 
// Return type		: BOOL 
// Argument         : short nIndex
// Argument         : LPCTSTR lpszPageName
BOOL CXFloorWndCtrl::_SetPageName(short nIndex, LPCTSTR lpszPageName) 
{
	if (CFloorPageObject* pPage = GetPage(nIndex))	
	{
		pPage->SetName(lpszPageName);
		return TRUE;
	}
	return FALSE;
}

// Function name	: CXFloorWndCtrl::OnAnimationChanged
// Description	    : Called when something is happen eith m_bAnimation
// Return type		: void 
void CXFloorWndCtrl::OnAnimationChanged() 
{
	SetModifiedFlag();
}


void CXFloorWndCtrl::OnSleepChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

void CXFloorWndCtrl::OnSignChanged() 
{
	// TODO: Add notification handler code

	SetModifiedFlag();
}

// Function name	: CXFloorWndCtrl::GetHeight
// Description	    : Get the Height of page nIndex
// Return type		: short 
// Argument         : short nIndex
short CXFloorWndCtrl::GetHeight(short nIndex) 
{
	if (CFloorPageObject* pPage = GetPage(nIndex))	
		return pPage->GetHeight();
	return -1;
}

// Function name	: CXFloorWndCtrl::SetHeight
// Description	    : Set the new height of page nIndex to nNewValue
// Return type		: void 
// Argument         : short nIndex
// Argument         : short nNewValue
void CXFloorWndCtrl::SetHeight(short nIndex, short nNewValue) 
{
	if (CFloorPageObject* pPage = GetPage(nIndex))	
	{
		pPage->SetHeight(nNewValue);
		SetModifiedFlag();
	}
}

// Function name	: CXFloorWndCtrl::GetColor
// Description	    : return the default color of page
// Return type		: OLE_COLOR 
// Argument         : short nIndex
OLE_COLOR CXFloorWndCtrl::GetColor(short nIndex) 
{
	if (CFloorPageObject* pPage = GetPage(nIndex))	
	{
		LOGBRUSH logBrush;
		pPage->m_brBkGnd.GetLogBrush(&logBrush);
		return logBrush.lbColor;
	}
	return RGB(0,0,0);
}

// Function name	: CXFloorWndCtrl::SetColor
// Description	    : Set the new color of background's page
// Return type		: void 
// Argument         : short nIndex
// Argument         : OLE_COLOR nNewValue
void CXFloorWndCtrl::SetColor(short nIndex, OLE_COLOR nNewValue) 
{
	if (CFloorPageObject* pPage = GetPage(nIndex))	
	{
		pPage->SetBkGnd(TranslateColor(nNewValue));
		SetModifiedFlag();
	}
}

// Function name	: CXFloorWndCtrl::OnPagesChanged
// Description	    : 
// Return type		: void 
void CXFloorWndCtrl::OnPagesChanged()
{
	if (m_hWnd)
		if (::IsWindow(m_hWnd))
		{
			BOOL bSAnimation = m_bAnimation;
			m_bAnimation = FALSE;
			int i = 0;
			BOOL cont = TRUE;

⌨️ 快捷键说明

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