📄 oxtooltipctrl.h
字号:
//OXToolTipCtrl.h
#if !defined(_OXTOOLTIPCTRL_H__)
#define _OXTOOLTIPCTRL_H__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "OXDllExt.h"
class COXToolTipInfo;
struct OXTOOLINFO : public TOOLINFO
{
#if (_WIN32_IE < 0x0300)
LPARAM lParam; // Application defined value that is associated with the tool
#endif
int nWidth; // Width of box, or 0 for default
COLORREF clrTextColor; // text color
COLORREF clrBackColor; // background color
OXTOOLINFO::OXTOOLINFO()
{
cbSize = sizeof(OXTOOLINFO);
}
void operator=(COXToolTipInfo& RHS);
};
// this structure holds all the tooltip information internall
class OX_CLASS_DECL COXToolTipInfo : public CObject
{
public:
UINT uFlags; // Not used
HWND hWnd; // Window handle of the control
UINT nIDTool; // ID of tool
CRect rectBounds; // Bounding rect for toolinfo to be displayed
LPCTSTR szText; // Either LPSTR_TEXTCALLBACK or NULL
CString strText; // Tooltip text if szText is NULL, or empty.
int nWidth; // Width of box, or 0 for default
COLORREF clrTextColor; // text color
COLORREF clrBackColor; // background color
LPARAM lParam; // Application defined value that is associated
// with the tool
void operator=(OXTOOLINFO& RHS)
{
uFlags = RHS.uFlags;
hWnd = RHS.hwnd;
nIDTool = RHS.uId;
rectBounds = RHS.rect;
if (RHS.lpszText == LPSTR_TEXTCALLBACK)
{
szText = RHS.lpszText;
strText.Empty();
}
else
{
szText = NULL;
strText = RHS.lpszText;
}
nWidth = RHS.nWidth;
clrTextColor = RHS.clrTextColor;
clrBackColor = RHS.clrBackColor;
lParam = RHS.lParam;
}
void operator=(COXToolTipInfo& RHS)
{
uFlags = RHS.uFlags;
hWnd = RHS.hWnd;
nIDTool = RHS.nIDTool;
rectBounds = RHS.rectBounds;
strText = RHS.strText;
nWidth = RHS.nWidth;
clrTextColor = RHS.clrTextColor;
clrBackColor = RHS.clrBackColor;
lParam = RHS.lParam;
}
};
inline void OXTOOLINFO::operator=(COXToolTipInfo& RHS)
{
cbSize = sizeof(OXTOOLINFO);
uFlags = RHS.uFlags;
hwnd = RHS.hWnd;
uId = RHS.nIDTool;
rect = RHS.rectBounds;
hinst = AfxGetResourceHandle();
if (RHS.szText == LPSTR_TEXTCALLBACK)
lpszText = LPSTR_TEXTCALLBACK;
else
lpszText = (LPTSTR)(LPCTSTR) RHS.strText;
lParam = RHS.lParam;
nWidth = RHS.nWidth;
clrTextColor = RHS.clrTextColor;
clrBackColor = RHS.clrBackColor;
}
/////////////////////////////////////////////////////////////////////////////
// COXToolTipCtrl window
class OX_CLASS_DECL COXToolTipCtrl : public CWnd
{
public:
COXToolTipCtrl();
virtual ~COXToolTipCtrl();
//Operations
public:
BOOL GetToolInfo(OXTOOLINFO& ToolInfo, CWnd* pWnd, UINT nIDTool = 0);
void SetToolInfo(OXTOOLINFO* pToolInfo);
void GetMargin(LPRECT lprc) const;
void GetText(CString& str, CWnd* pWnd, UINT nIDTool = 0);
void SetDelayTime(DWORD dwDuration, int nTime);
int SetMaxTipWidth(int nWidth);
void SetTipTextColor(COLORREF clr);
void SetTipBkColor(COLORREF clr);
COLORREF GetTipTextColor() const;
COLORREF GetTipBkColor() const;
int GetMaxTipWidth() const;
int GetDelayTime(DWORD dwDuration) const;
BOOL Create(CWnd* pParentWnd);
BOOL AddTool(CWnd* pWnd, UINT nIDText,LPCRECT lpRectTool = NULL, UINT nIDTool = 0);
BOOL AddTool(CWnd* pWnd, LPCTSTR lpszText,LPCRECT lpRectTool = NULL, UINT nIDTool = 0);
void DelTool(CWnd* pWnd, UINT nIDTool = 0);
void RelayEvent(MSG* pMsg);
BOOL HitTest(CWnd* pWnd, POINT pt, OXTOOLINFO* pToolInfo) const;
void Pop();
//inline
inline void SetDelayTime(UINT nDelay) { m_nDisplayDelay = nDelay; }
inline void Activate(BOOL bActivate) { m_bActivated = bActivate; }
inline int GetToolCount() const { return m_arrTools.GetSize(); }
inline void SetMargin(LPRECT lprc) { m_rectMargin = lprc; }
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(COXToolTipCtrl)
//}}AFX_VIRTUAL
protected:
virtual CRect CalculateInfoBoxRect(CPoint& pt, COXToolTipInfo* pToolTip,CRect& rectTextBounds) const;
virtual CRect GetBoundsRect(CString strText, int nWidth) const;
inline BOOL IsVisible() const { return ((GetStyle() & WS_VISIBLE) == WS_VISIBLE); }
CString GetTooltipText(COXToolTipInfo *pToolTip);
COXToolTipInfo* GetToolInfoPtr(CWnd* pWnd, UINT nIDTool /*=0*/);
CWnd* GetChildWindowFromPoint(POINT& point) const;
void StartNewTool(COXToolTipInfo* pToolInfo);
void DisplayToolTip(CPoint& pt, BOOL bExtended = FALSE);
COXToolTipInfo* FindToolFromPoint(POINT& pt);
BOOL IsCursorInTool(COXToolTipInfo* pToolInfo) const;
BOOL IsCursorInToolTip() const;
CString GetFieldFromString(CString ref, int nIndex, TCHAR ch) const;
BOOL SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw = TRUE);
LPLOGFONT GetSystemToolTipFont() const;
protected:
CWnd* m_pParentWnd; // Parent window of all the tools
CRect m_rectMargin; // Margin between text and tooltip window edge
int m_nMaxWidth; // Max tooltip width
CPoint m_ptOffset; // offset from the cursor to the topleft of
CFont m_Font;
LOGFONT m_LogFont; // Current font in use
DWORD m_dwTextStyle; // The style in which to draw the text
BOOL m_bUsingSystemFont; // Use system tooltip font?
COXToolTipInfo *m_pCurrentToolTip; // Current tooltip information
UINT m_nCheckInterval; // Time in ms between check of the tip
UINT m_nDisplayTime; // Time in ms to display the tip
UINT m_nElapsedTime; // Elapsed display time of the tip
UINT m_nDisplayDelay; // Delay in ms before the tip is displayed
BOOL m_bActivated; // Are tips activated?
BOOL m_bTipCancelled; // Has the current tooltip been cancelled?
BOOL m_bHasExtendedText; // TRUE if the tooltip contains extended text
BOOL m_bExtended; // Is the tip displaying extended info?
COLORREF m_crBackColor; // Default background color of tips
COLORREF m_crTextColor; // Default foreground color of tips
HWND m_hOldFocusWnd; // window that had focus before the tooltip
// was clicked on
static LPCTSTR m_szArrowSpace; // Spaces (' ') added to allow room for arrow in text
protected:
enum { eIDDisplayToolEvent = 1, eIDCheckToolEvent = 2};
private:
CObArray m_arrTools; // Collection of all tools
// Generated message map functions
protected:
//{{AFX_MSG(COXToolTipCtrl)
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnDestroy();
afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
//}}AFX_MSG
afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam);
afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -