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

📄 bcgphotspotimagectrl.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	dc.DPtoLP (&pt);

	for (POSITION pos = m_lstHotSpots.GetHeadPosition (); pos != NULL;)
	{
		CBCGPHotSpot* pHotSpot = m_lstHotSpots.GetNext (pos);
		ASSERT_VALID (pHotSpot);

		if (pHotSpot->IsPointWithin (pt))
		{
			if (::WindowFromPoint (ptScreen) != GetSafeHwnd ())
			{
				return NULL;
			}

			return pHotSpot;
		}
	}

	return NULL;
}
//********************************************************************************
void CBCGPHotSpotImageCtrl::RedrawRect (CRect rect)
{
	CClientDC dc (this);
	OnPrepareDC (&dc);

	dc.LPtoDP (&rect);

	RedrawWindow (rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnMouseMove(UINT /*nFlags*/, CPoint point) 
{
	CBCGPHotSpot* pHot = HitTest (point);

	if (m_pHot == pHot)
	{
		return;
	}

	// ----------------
	// No new hot areas
	// ----------------
	if (pHot == NULL)
	{
		if (m_pHot != NULL)
		{
			// remove old hotlight
			CRect rectUpdate = m_pHot->m_rect;
			m_pHot = NULL;

			if (m_hbmpHot != NULL)
			{
				RedrawRect (rectUpdate);
			}

			if (m_pClicked == NULL)
			{
				ReleaseCapture ();
			}
		}
		
		return;
	}
	else if (pHot != NULL)
	{
		// ------------
		// New hot spot
		// ------------
		if (m_pHot == NULL)
		{
			if (GetCapture () != NULL)
			{
				return;
			}

			SetCapture ();
		}
		else
		{
			// remove old hotlight
			CRect rectHotSpot = m_pHot->m_rect;
			m_pHot = NULL;

			if (m_hbmpHot != NULL)
			{
				RedrawRect (rectHotSpot);
			}
		}
		
		// add new hotlight
		m_pHot = pHot;

		if (HasHotImage ())
		{
			RedrawRect (pHot->m_rect);
		}
	}
}
//*******************************************************************************
BOOL CBCGPHotSpotImageCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	if (nFlags & (MK_SHIFT | MK_CONTROL))
	{
		return FALSE;
	}
	
	UNUSED_ALWAYS(pt);

	DWORD dwStyle = GetStyle();
	CScrollBar* pBar = GetScrollBarCtrl(SB_VERT);
	BOOL bHasVertBar = ((pBar != NULL) && pBar->IsWindowEnabled()) ||
					(dwStyle & WS_VSCROLL);

	SCROLLINFO scrollInfo;
	ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));

    scrollInfo.cbSize = sizeof(SCROLLINFO);
	scrollInfo.fMask = SIF_ALL;

	GetScrollInfo (bHasVertBar ? SB_VERT : SB_HORZ, &scrollInfo);

	if (scrollInfo.nPos >= scrollInfo.nMax)
	{
		return FALSE;
	}

	int nSteps = abs(zDelta) / WHEEL_DELTA * 4;

	for (int i = 0; i < nSteps; i++)
	{
		UINT nSBCode = zDelta < 0 ? SB_LINEDOWN : SB_LINEUP;

		if (bHasVertBar)
		{
			OnVScroll (nSBCode, 0, NULL);
		}
		else
		{
			OnHScroll (nSBCode, 0, NULL);
		}
	}

	return TRUE;
}
//********************************************************************************
void CBCGPHotSpotImageCtrl::OnLButtonDown(UINT /*nFlags*/, CPoint point) 
{
	m_nSelectedNum = 0;
	m_pClicked = HitTest (point);

	SetFocus ();
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnLButtonUp(UINT /*nFlags*/, CPoint point) 
{
	if (m_pHot == NULL && m_pClicked == NULL)
	{
		return;
	}

	ReleaseCapture ();

	BOOL bIsHotSpotClick = (m_pHot != NULL && m_pHot == HitTest (point) &&
		m_pClicked == m_pHot);

	CRect rectHotSpot = (m_pHot != NULL) ? m_pHot->m_rect : CRect (0, 0, 0, 0);
	CRect rectClicked = (m_pClicked != NULL) ? m_pClicked->m_rect : CRect (0, 0, 0, 0);

	UINT nSelectedNum = m_pHot != NULL ? m_pHot->m_nID : 0;

	m_pHot = NULL;
	m_pClicked = NULL;

	if (HasHotImage ())
	{
		RedrawRect (rectHotSpot);

		if (!rectClicked.IsRectEmpty () && rectClicked != rectHotSpot)
		{
			RedrawRect (rectClicked);
		}
	}

	if (bIsHotSpotClick)
	{
		CWnd* pParent = GetParent ();
		if (pParent != NULL)
		{
			m_nSelectedNum = nSelectedNum;
			pParent->SendMessage (	WM_COMMAND,
									MAKEWPARAM (GetDlgCtrlID (), BN_CLICKED),
									(LPARAM) m_hWnd);
		}
	}
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnCancelMode() 
{
	CButton::OnCancelMode();
	
	if (m_pHot != NULL || m_pClicked != NULL)
	{
		CRect rectHotSpot = m_pHot != NULL ? m_pHot->m_rect : CRect (0, 0, 0, 0);
		CRect rectClicked = (m_pClicked != NULL) ? m_pClicked->m_rect : CRect (0, 0, 0, 0);

		m_pHot = NULL;
		m_pClicked = NULL;
		ReleaseCapture ();

		if (HasHotImage ())
		{
			RedrawRect (rectHotSpot);

			if (!rectClicked.IsRectEmpty () && rectClicked != rectHotSpot)
			{
				RedrawRect (rectClicked);
			}
		}
	}

	m_pClicked = NULL;
	m_nSelectedNum = 0;
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnSize(UINT nType, int cx, int cy) 
{
	CButton::OnSize(nType, cx, cy);
	
	UpdateScrollBars ();
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if (pScrollBar != NULL && pScrollBar->SendChildNotifyLastMsg())
		return;     // eat it

	// ignore scroll bar msgs from other controls
	if (pScrollBar != GetScrollBarCtrl(SB_VERT))
		return;

	OnScroll(MAKEWORD(-1, nSBCode), nPos);
}
//*******************************************************************************
void CBCGPHotSpotImageCtrl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	if (pScrollBar != NULL && pScrollBar->SendChildNotifyLastMsg())
		return;     // eat it

	// ignore scroll bar msgs from other controls
	if (pScrollBar != GetScrollBarCtrl(SB_HORZ))
		return;

	OnScroll(MAKEWORD(nSBCode, -1), nPos);
}
//********************************************************************************
void CBCGPHotSpotImageCtrl::UpdateScrollBars ()
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	static BOOL bInUpdate = FALSE;
	if (bInUpdate)
	{
		return;
	}

	bInUpdate = TRUE;

	CRect rectClient;
	GetClientRect (rectClient);

	SCROLLINFO scrollInfo;
	scrollInfo.cbSize = sizeof (SCROLLINFO);
	scrollInfo.fMask = SIF_RANGE | SIF_PAGE;
	scrollInfo.nMin = 0;
	scrollInfo.nMax = m_sizeImage.cx;
	scrollInfo.nPage = rectClient.Width ();
	
	if (!SetScrollInfo (SB_HORZ, &scrollInfo))
	{
		SetScrollRange (SB_HORZ, 0, m_sizeImage.cx, TRUE);
	}

	scrollInfo.nMax = m_sizeImage.cy;
	scrollInfo.nPage = rectClient.Height ();
	
	if (!SetScrollInfo (SB_VERT, &scrollInfo))
	{
		SetScrollRange (SB_VERT, 0, m_sizeImage.cy, TRUE);
	}

	bInUpdate = FALSE;
}
//*******************************************************************************
int CBCGPHotSpotImageCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CButton::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	UpdateScrollBars ();
	return 0;
}
//*******************************************************************************
BOOL CBCGPHotSpotImageCtrl::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
{
	// calc new x position
	int x = GetScrollPos(SB_HORZ);
	int xOrig = x;

	switch (LOBYTE(nScrollCode))
	{
	case SB_TOP:
		x = 0;
		break;
	case SB_BOTTOM:
		x = INT_MAX;
		break;
	case SB_LINEUP:
		x -= m_lineDev.cx;
		break;
	case SB_LINEDOWN:
		x += m_lineDev.cx;
		break;
	case SB_PAGEUP:
		x -= m_pageDev.cx;
		break;
	case SB_PAGEDOWN:
		x += m_pageDev.cx;
		break;
	case SB_THUMBTRACK:
		x = nPos;
		break;
	}

	// calc new y position
	int y = GetScrollPos(SB_VERT);
	int yOrig = y;

	switch (HIBYTE(nScrollCode))
	{
	case SB_TOP:
		y = 0;
		break;
	case SB_BOTTOM:
		y = INT_MAX;
		break;
	case SB_LINEUP:
		y -= m_lineDev.cy;
		break;
	case SB_LINEDOWN:
		y += m_lineDev.cy;
		break;
	case SB_PAGEUP:
		y -= m_pageDev.cy;
		break;
	case SB_PAGEDOWN:
		y += m_pageDev.cy;
		break;
	case SB_THUMBTRACK:
		y = nPos;
		break;
	}

	BOOL bResult = OnScrollBy(CSize(x - xOrig, y - yOrig), bDoScroll);
	if (bResult && bDoScroll)
		UpdateWindow();

	return bResult;
}
//*******************************************************************************
BOOL CBCGPHotSpotImageCtrl::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
{
	int xOrig, x;
	int yOrig, y;

	// don't scroll if there is no valid scroll range (ie. no scroll bar)
	CScrollBar* pBar;
	DWORD dwStyle = GetStyle();
	pBar = GetScrollBarCtrl(SB_VERT);
	if ((pBar != NULL && !pBar->IsWindowEnabled()) ||
		(pBar == NULL && !(dwStyle & WS_VSCROLL)))
	{
		// vertical scroll bar not enabled
		sizeScroll.cy = 0;
	}
	pBar = GetScrollBarCtrl(SB_HORZ);
	if ((pBar != NULL && !pBar->IsWindowEnabled()) ||
		(pBar == NULL && !(dwStyle & WS_HSCROLL)))
	{
		// horizontal scroll bar not enabled
		sizeScroll.cx = 0;
	}

	// adjust current x position
	xOrig = x = GetScrollPos(SB_HORZ);
	int xMax = GetScrollLimit(SB_HORZ);
	x += sizeScroll.cx;
	if (x < 0)
		x = 0;
	else if (x > xMax)
		x = xMax;

	// adjust current y position
	yOrig = y = GetScrollPos(SB_VERT);
	int yMax = GetScrollLimit(SB_VERT);
	y += sizeScroll.cy;
	if (y < 0)
		y = 0;
	else if (y > yMax)
		y = yMax;

	// did anything change?
	if (x == xOrig && y == yOrig)
		return FALSE;

	if (bDoScroll)
	{
		// do scroll and update scroll positions
//		ScrollWindow(-(x-xOrig), -(y-yOrig));
		if (x != xOrig)
			SetScrollPos(SB_HORZ, x);
		if (y != yOrig)
			SetScrollPos(SB_VERT, y);
		RedrawWindow ();
	}

	return TRUE;
}
//*******************************************************************************
CPoint CBCGPHotSpotImageCtrl::GetDeviceScrollPosition() const
{
	CPoint pt(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
	ASSERT(pt.x >= 0 && pt.y >= 0);

	return pt;
}

⌨️ 快捷键说明

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