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

📄 wzdtt2.cpp

📁 《vc++扩展编程实例》源码。运用Visual C++ 5.0或6.0的高级编程技巧
💻 CPP
字号:
// WzdFlyby.cpp : implementation file
//

#include "stdafx.h"
#include "wzd.h"
#include "WzdFlyby.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CWzdFlyby::CWzdFlyby()
{
}

CWzdFlyby::~CWzdFlyby()
{
	ResetHelp()
}

/////////////////////////////////////////////////////////////////////////////
// CWzdFlyby messages

BEGIN_MESSAGE_MAP(CWzdFlyby, CWnd)
	//{{AFX_MSG_MAP(CWzdFlyby)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_MOUSEMOVE,OnMouseMessage)
	ON_MESSAGE(WM_LBUTTONDOWN,OnMouseMessage)
	ON_MESSAGE(WM_RBUTTONDOWN,OnMouseMessage)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CWzdFlyby setup

void CWzdFlyby::Create(CWnd *pWnd)
{
	// create hidden window
	LPCTSTR lpszClass = AfxRegisterWndClass(CS_SAVEBITS,::LoadCursor(NULL,IDC_ARROW),(HBRUSH)(COLOR_INFOBK+1));
	CreateEx(WS_EX_TOPMOST,lpszClass,"",WS_POPUP,0,0,0,0,pWnd,NULL);

	// use ansi font
	CFont *pFont=CFont::FromHandle((HFONT)::GetStockObject(ANSI_VAR_FONT));
	SetFont(pFont);
}

void CWzdFlyby::AddHelp(int x,int y,int z,int t,LPCSTR str)
{
	m_flybyHelp.Add(new CWzdHelpText(x,y,z,t,str));
}

void CWzdFlyby::ResetHelp()
{
	while (m_flybyHelp.GetUpperBound()>-1)
	{
		delete m_flybyHelp[0];
		m_flybyHelp.RemoveAt(0);
	}
}


/////////////////////////////////////////////////////////////////////////////
// CWzdFlyby show bubble help

void CWzdFlyby::Flyby(CPoint point)
{
	// if app isn't active, no bubble help!
	if (!GetFocus()) return;

	// if mouse is moving over one of our areas, start capture countdown
	for (int i=0;i<m_flybyHelp.GetUpperBound();i++)
	{
		if (m_flybyHelp[i]->m_rect.PtInRect(point))
		{
			KillTimer(m_nTimerId);
			m_nTimerId=SetTimer(CAPTURE,500,NULL);
			m_pFlybyHelp=m_flybyHelp[i];
			break;
		}
	}
}

void CWzdFlyby::OnTimer(UINT nIDEvent) 
{
	// if 1/2 second timer, show bubble help
	if (nIDEvent==CAPTURE)
	{
		CPoint point;
		::GetCursorPos(&point);
		GetParent()->ScreenToClient(point);
		if (m_pFlybyHelp->m_rect.PtInRect(point))
		{
			CClientDC dc;

			// determine size of window
			CRect rect;
			dc.DrawText(m_pFlybyHelp->m_text,&rect,DT_LEFT|DT_CALCRECT);
			rect.Inflate(3,3,3,3); // add a buffer

			// position window
			SetWindowPos(&wndTop, point.x, point.y+10, rect.Width(), rect.Height(),
						SWP_SHOWWINDOW|SWP_NOACTIVATE );

			// draw text in it
			dc.SetBkMode(TRANSPARENT);
 			dc.DrawText(m_pFlybyHelp->m_text, &rect, DT_LEFT|DT_VCENTER));

			// capture mouse cursor and start display timer
			SetCapture();
			m_nTimerId=SetTimer(DISPLAY,5000,NULL);
		}
	}

	// else if 5 second timer, hide help
	else if (nIDEvent==DISPLAY)
	{
		ReleaseCapture();
		ShowWindow(SW_HIDE);
	}
	
	CWnd::OnTimer(nIDEvent);
}

/////////////////////////////////////////////////////////////////////////////
// CWzdFlyby hide bubble help

LRESULT CWzdFlyby::OnMouseMessage(WPARAM wParam, LPARAM lParam)
{
	// get message
	MSG msg=CWnd::GetCurrentMessage();

	// get mouse position relative to parent
	CPoint point(LOWORD(lParam),HIWORD(lParam));
	ClientToScreen(&point);
	GetParent()->ScreenToClient(&point);

	// if this is a mouse move within capture area, just reset timer
	if (msg.message==WM_MOUSEMOVE && m_pFlybyHelp.PtInRect(point))
	{
		KillTimer(m_nTimerId);
		m_nTimerId=SetTimer(DISPLAY,5000,NULL);
	}

	// else hide bubble window and forward message to window below
	else
	{
		// hide window
		ReleaseCapture();
		ShowWindow(SW_HIDE);

		// find window under cursor
		GetParent()->ClientToScreen(&point);
		CWnd *pWnd = WindowFromPoint(point);
		if (pWnd == this) pWnd = GetParent();

		// if over a client area, just forward message there
		int ht = (int)pWnd->SendMessage(WM_NCHITTEST,0,lParam);
		if (ht == HTCLIENT) 
		{
			pWnd->ScreenToClient(&point);
			pWnd->PostMessage(msg.message,wParam,lParam);
		}
		// else convert message to nonclient and post
		else
		{
			switch (msg.message)
			{
				case WM_LBUTTONDOWN:
					msg.message=WM_NCLBUTTONDOWN;
					break;
				case WM_RBUTTONDOWN:
					msg.message=WM_NCRBUTTONDOWN;
					break;
				case WM_MOUSEMOVE:
					msg.message=WM_NCMOUSEMOVE;
					break;
			}
			pWnd->PostMessage(msg.message,ht,MAKELONG(point.x,point.y));
		}
	}
	return 0L;
}

⌨️ 快捷键说明

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