///////////////////////////////////////////////////////////////////////////
//
// FILE NAME
//
// XInfoTip.cpp
//
// COMPONENT
//
// CXInfoTip class implementation
//
// DESCRIPTION
//
// (see header)
//
// AUTHOR
//
// Mark Bozeman 09-16-2001
//
///////////////////////////////////////////////////////////////////////////
#include "stdafx.h" // PCH
#include "XInfoTip.h" // Class interface
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define CX_ROUNDED 12 // Tip horizontal roundness
#define CY_ROUNDED 10 // Tip vertical roundness
#define DEFAULT_CX_LEADER 25 // Width of tip lead
#define DEFAULT_CY_LEADER 25 // Height of tip lead
#define CX_ICON_MARGIN 5 // Width of margin between icon and tip text
#define DEFAULT_SHOW_DELAY 500 // Default show delay (ms)
#define DEFAULT_TIMER_HIDE 2000 // Hide timer (ms)
static char XINFOTIPCLASS_NAME[]="CXInfoTip";
CXInfoTip::CXInfoTip():m_ToolMap(10)
{
// Register the class
WNDCLASS ClassInfo;
ZeroMemory(&ClassInfo,sizeof(ClassInfo));
HINSTANCE hResourceHandle=AfxGetResourceHandle();
if(!GetClassInfo(hResourceHandle,XINFOTIPCLASS_NAME,&ClassInfo))
{
ClassInfo.hIcon=NULL;
ClassInfo.hCursor=::LoadCursor(hResourceHandle,IDC_ARROW);
ClassInfo.hbrBackground=::CreateSolidBrush(RGB(255,255,255));
ClassInfo.lpszClassName=XINFOTIPCLASS_NAME;
ClassInfo.lpszMenuName="";
ClassInfo.hInstance=hResourceHandle;
ClassInfo.lpfnWndProc=::DefWindowProc;
ClassInfo.style=CS_DBLCLKS;
ClassInfo.cbClsExtra=0;
ClassInfo.cbWndExtra=0;
if(!RegisterClass(&ClassInfo))
{
AfxThrowResourceException();
}
}
// Set the icon ¡¢tip text¡¢icon size¡¢text color¡¢background color¡¢font
m_hIcon = NULL;
m_IconSize = CSize(0, 0);
m_szText = _T("");
m_TextColor =RGB(0,0,0);
m_BackColor =RGB(255,255,255);
m_pFont =NULL;
// Set the delay defaults
m_nTimer = 0;
m_nShowDelay = DEFAULT_SHOW_DELAY;
m_nShowRemain = DEFAULT_TIMER_HIDE;
// Set the default window region¡¢leader width¡¢leader height¡¢window size
m_nLeaderWidth =DEFAULT_CX_LEADER;
m_nLeaderHeight=DEFAULT_CY_LEADER;
m_WindowSize=CSize(0,0);
m_WindowRgn=NULL;
// Set the initial mouse point
m_ptOrigin = CPoint(0, 0);
}
CXInfoTip::~CXInfoTip()
{
if(!m_ToolMap.IsEmpty())
{
m_ToolMap.RemoveAll();
}
if(m_WindowRgn != NULL)
{
::DeleteObject(m_WindowRgn);
m_WindowRgn=NULL;
}
}
// Message map
BEGIN_MESSAGE_MAP(CXInfoTip, CWnd)
//{{AFX_MSG_MAP(CXInfoTip)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CXInfoTip::Create(CWnd* pParentWnd)
{
BOOL bSuccess=FALSE;
if(pParentWnd != NULL && IsWindow(pParentWnd->m_hWnd))
{
bSuccess = CreateEx(NULL, XINFOTIPCLASS_NAME, NULL, WS_POPUP, 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), NULL, NULL);
}
return bSuccess;
}
void CXInfoTip::Show(CPoint *pt,CString szText,HICON hIcon,CFont* pFont,COLORREF TextColor,COLORREF BackColor)
{
if (pt != NULL)
{
m_ptOrigin = *pt;
}
else
{
GetCursorPos(&m_ptOrigin);
}
m_szText = szText;
m_hIcon = hIcon;
m_pFont = pFont;
m_TextColor = TextColor;
m_BackColor = BackColor;
Show();
}
void CXInfoTip::OnPaint()
{
CPaintDC dc( this ); // device context for painting
CRect rc;
CBrush WindowBrush;
CBrush FrameBrush;
CBrush InnerFrameBrush;
CRgn *pRegion;
HRGN WindowRgn=NULL;
CFont *pOldFont=NULL;
CFont *pNewFont=NULL;
// Get the client rectangle
GetClientRect(rc);
// Create the brushes
InnerFrameBrush.CreateSolidBrush(::GetSysColor(COLOR_SCROLLBAR));
FrameBrush.CreateSolidBrush(::GetSysColor(COLOR_WINDOWTEXT));
WindowBrush.CreateSolidBrush(m_BackColor);
// Get the window region
WindowRgn=::CreateRectRgn(0,0,0,0);
GetWindowRgn(WindowRgn);
pRegion = CRgn::FromHandle(WindowRgn);
// Draw the frame
dc.FillRgn(pRegion, &WindowBrush);
dc.FrameRgn(pRegion, &InnerFrameBrush, 3, 3);
dc.FrameRgn(pRegion, &FrameBrush, 1, 1);
// Adjust the area for the icon
rc.DeflateRect(CX_ROUNDED, CY_ROUNDED, 0, 0);
if (m_hIcon != NULL)
rc.left = rc.left + m_IconSize.cx + CX_ICON_MARGIN;
// Set the font
if(m_pFont != NULL)
{
pOldFont = dc.SelectObject(m_pFont);
}
else
{
pNewFont= CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
pOldFont= dc.SelectObject(pNewFont);
}
// Draw the tip text
dc.SetBkMode( TRANSPARENT );
dc.SetTextColor(m_TextColor);
dc.DrawText(m_szText, &rc, DT_TOP | DT_LEFT | DT_EXPANDTABS |DT_WORDBREAK);
// Draw the icon
if (m_hIcon != NULL)
DrawIconEx(dc.m_hDC, CX_ROUNDED, CY_ROUNDED, m_hIcon, m_IconSize.cx, m_IconSize.cy, 0, NULL, DI_NORMAL);
// Clean up GDI
dc.SelectObject(pOldFont);
if(pNewFont != NULL)
{
pNewFont->DeleteObject();
}
WindowBrush.DeleteObject();
InnerFrameBrush.DeleteObject();
FrameBrush.DeleteObject();
pRegion->DeleteObject();
}
/////////////////////////////////////////////////////////////////////
//
// CXInfoTip::GetWindowRegion()
//
// DESCRIPTION
//
// Retrieves the window region
//
// RETURNS
//
// [BOOL] - TRUE on success, FALSE on failure
//
// PARAMETERS
//
// [pDC] - Pointer to display device context
// [hRegion] - Filled with the calculated window region
// [Size] - Filled with the calculated window size
// or NULL.
//
/////////////////////////////////////////////////////////////////////
BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size /* = NULL */)
{
CRect rcWnd;
POINT ptLeader[3];
HRGN LeaderRegion=NULL;
HRGN CaptionRegion=NULL;
CFont *pOldFont=NULL;
CFont *pNewFont=NULL;
ASSERT(pDC != NULL);
ASSERT(hRegion != NULL);
// Calculate the are for the tip text
if(m_pFont != NULL)
{
pOldFont = pDC->SelectObject(m_pFont);
}
else
{
pNewFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
pOldFont = pDC->SelectObject(pNewFont);
}
pDC->DrawText(m_szText, &rcWnd, DT_CALCRECT);
pDC->SelectObject(pOldFont);
if(pNewFont != NULL)
{
pNewFont->DeleteObject();
}
// Adjust for the rounded corners
rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED);
// Adjust for icon
if (m_hIcon != NULL)
rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN;
if (rcWnd.Height() < m_IconSize.cy)
rcWnd.bottom = rcWnd.top + m_IconSize.cy;
// Calculate the leader triangle coordinates
ptLeader[0].x = rcWnd.Width() - CX_ROUNDED;
ptLeader[0].y = rcWnd.Height() - CY_ROUNDED;
ptLeader[1].x = ptLeader[0].x;
ptLeader[1].y = ptLeader[0].y + m_nLeaderHeight;
ptLeader[2].x = ptLeader[0].x - m_nLeaderWidth;
ptLeader[2].y = rcWnd.Height() - CY_ROUNDED;
// Create the caption region
CaptionRegion=::CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED);
// Create the leader region
LeaderRegion=::CreatePolygonRgn(ptLeader, 3, ALTERNATE);
// Combine the regions
CombineRgn(*hRegion, CaptionRegion, LeaderRegion, RGN_OR);
// Set the window size
if (Size != NULL)
{
Size->cx = rcWnd.Width();
Size->cy = rcWnd.Height() + m_nLeaderHeight;
}
//Destroy the caption region and leader region
::DeleteObject(CaptionRegion);
::DeleteObject(LeaderRegion);
return TRUE;
}
int CXInfoTi
XInfo.rar_xin
版权申诉
144 浏览量
2022-09-22
17:38:29
上传
评论
收藏 6KB RAR 举报
weixin_42651887
- 粉丝: 80
- 资源: 1万+
最新资源
- linux简介及基础教程及特点阐述.txt
- 数据结构课程设计课作业资料
- java简介及基础教程及特点阐述.txt
- 一个简单的数据分析脚本示例,它使用Python和pandas库来读取CSV文件、执行一些基本的数据清洗和转换,并进行简单的可视化
- AD7124+PT100 基于STM32f103的代码 检测多路温度(100~-200)并输出
- CHROME webdriver Version: 125.0.6422.78 win64
- python读取一个CSV文件,对数据进行一些基本的数据清洗和处理,然后进行可视化
- openEuler-20.03-LTS-SP4-aarch64-dvd.zip.001
- openEuler-20.03-LTS-SP4-aarch64-dvd.zip.002
- openEuler-20.03-LTS-SP4-aarch64-dvd.zip.003
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈