📄 hintwindow.cpp
字号:
// HintWindow.cpp : 实现文件
//
#include "stdafx.h"
#include "SoccerDoctor.h"
#include "HintWindow.h"
// CHintWindow
IMPLEMENT_DYNAMIC(CHintWindow, CWnd)
CHintWindow::CHintWindow()
{
_nDelay = 500; // 缺省延迟500ms
_nLast = 2000; // 缺省持续5s
_bDisplayed = false;
}
CHintWindow::~CHintWindow()
{
}
BEGIN_MESSAGE_MAP(CHintWindow, CWnd)
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
// CHintWindow 消息处理程序
void CHintWindow::CreateHintWindow(CWnd* pParentWnd)
{
CreateEx(NULL, NULL, "Hint", WS_CHILD ,0, 0, 10, 10, pParentWnd->GetSafeHwnd(), NULL);
_tipPen.CreatePen(PS_SOLID, 1, RGB(0,0,0));
_tipFont.CreateFont(15, 0, 0, 0, FW_REGULAR, 0, 0, 0, 0, 0, 0, 0, 0, "MS Sans Serif");
_tipBrush.CreateSolidBrush(RGB(255, 255, 225));
ShowWindow(SW_HIDE);
}
void CHintWindow::ShowHint(const CPoint& winPos,const CString& strHint)
{
if(!GetSafeHwnd()){
return ;
}
if(_winPos != winPos || _strHint != strHint)
{
StopDelayTimer();
StopLastTimer();
ShowWindow(SW_HIDE);
_bDisplayed = false;
_winPos = winPos;
_strHint = strHint;
// ReSize the tip window according to tip text
CRect clientRect;
GetClientRect(&clientRect);
CPaintDC dc(this);
CFont* pOldFont = dc.SelectObject(&_tipFont);
CSize stringSize = dc.GetTextExtent(_strHint);
clientRect.bottom = _winPos.y ;
clientRect.left = _winPos.x ;
clientRect.top = clientRect.bottom - stringSize.cy ;
clientRect.right = clientRect.left + stringSize.cx ;
// Give some extra widht and height to window
clientRect.InflateRect(2,2,2,2);
MoveWindow(&clientRect);
dc.SelectObject(pOldFont);
StartDelayTimer();
}
}
void CHintWindow::StartDelayTimer()
{
SetTimer(ID_HINT_DELAYTIMER, _nDelay, 0);
}
void CHintWindow::StopDelayTimer()
{
KillTimer(ID_HINT_DELAYTIMER);
}
void CHintWindow::StartLastTimer()
{
SetTimer(ID_HINT_LASTTIMER, _nLast, 0);
}
void CHintWindow::StopLastTimer()
{
KillTimer(ID_HINT_LASTTIMER);
}
void CHintWindow::OnPaint()
{
CPaintDC dc(this);
// Select them
CPen* pOldPen = dc.SelectObject(&_tipPen);
CFont* pOldFont = dc.SelectObject(&_tipFont);
CBrush* pOldBsh = dc.SelectObject(&_tipBrush);
// Draw a rectangle to give background color
CRect clientRect;
GetClientRect(&clientRect);
dc.Rectangle(&clientRect);
// Set Transparent mode so that it will not show fonts back color
dc.SetBkMode(TRANSPARENT);
// Now display the tip
dc.TextOut(2, 2, _strHint);
// Select Old Pen, Font and Brush
dc.SelectObject(pOldBsh);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldFont);
}
void CHintWindow::OnTimer(UINT nIDEvent)
{
if(nIDEvent == ID_HINT_DELAYTIMER)
{
Invalidate();
StopDelayTimer(); // Stop the timer because now there is no need to continue with it
StartLastTimer();
ShowWindow(SW_SHOW);
}else if(nIDEvent == ID_HINT_LASTTIMER){
ShowWindow(SW_HIDE);
StopLastTimer();
}
CWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -