当前位置:网站首页>Duilib implements tooltip custom mouse prompt window
Duilib implements tooltip custom mouse prompt window
2022-07-19 09:40:00 【nSponge】
problem :
DuiLib The default control mouse prompt only supports strings , Found in the actual work needs , Just string is not enough , In the mouse over prompt, you want to have pictures or moving pictures or multi text information display , So we need to increase ToolTip Custom window processing .
solve :
1、 increase UICCustomToolTipUI.h file
#pragma once
namespace DuiLib {
/* * Customize the mouse prompt callback */
class IToolTipCallBack {
public:
virtual LPCTSTR GetCustomToolTip(CControlUI* pTipOwner, LPCTSTR pstrTipCtrl) = 0;
};
/* * Customize mouse tips */
class CCustomToolTipUI : public CWindowWnd
{
public:
CCustomToolTipUI(CControlUI* pOwner);
~CCustomToolTipUI(void);
void Init(LPCTSTR pstrXml, IToolTipCallBack* callback);
protected:
LPCTSTR GetWindowClassName() const;
UINT GetClassStyle() const;
void OnFinalMessage(HWND hWnd);
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
void Walk(CControlUI* pCtrl);
private:
CPaintManagerUI m_pm;
CDuiString m_sXml; //!< Part object that triggers the mouse prompt
IToolTipCallBack* m_pCallBack; //!< tooltip XML File path
CControlUI* m_pOwner; //!< Usually the main window object
};
}// namespace Duilib
2、 increase UICCustomToolTipUI.cpp file
#include "StdAfx.h"
#include "UICustomToolTipUI.h"
namespace DuiLib {
CCustomToolTipUI::CCustomToolTipUI(CControlUI* pOwner)
: m_pOwner(pOwner)
, m_pCallBack(NULL)
{
}
CCustomToolTipUI::~CCustomToolTipUI(void)
{
}
LPCTSTR CCustomToolTipUI::GetWindowClassName() const
{
return TOOLTIPS_CLASS;
}
UINT CCustomToolTipUI::GetClassStyle() const
{
return 0;
}
void CCustomToolTipUI::OnFinalMessage(HWND hWnd)
{
//delete this;
}
void CCustomToolTipUI::Init(LPCTSTR pstrXml, IToolTipCallBack* callback)
{
ASSERT(pstrXml);
m_pCallBack = callback;
m_pm.Init(m_hWnd);
CDialogBuilder builder;
CControlUI* pRoot = builder.Create(pstrXml, (UINT)0, NULL, &m_pm);
ASSERT(pRoot && "Failed to parse XML");
m_pm.AttachDialog(pRoot);
if (m_pCallBack)
{
Walk(pRoot);
}
}
LRESULT CCustomToolTipUI::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;
if (uMsg == WM_DESTROY) {
}
else if (uMsg == WM_WINDOWPOSCHANGING || uMsg == WM_WINDOWPOSCHANGED) {
WINDOWPOS* pos = (WINDOWPOS*)lParam;
pos->cx = m_pm.GetInitSize().cx;
pos->cy = m_pm.GetInitSize().cy;
}
else if (uMsg == WM_PAINT || uMsg == WM_ERASEBKGND) {
return m_pm.MessageHandler(uMsg, wParam, lParam, lRes);
}
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
}
/* Traverse widgets , Display text on the specified control */
void CCustomToolTipUI::Walk(CControlUI* pCtrl)
{
if (pCtrl == NULL)
{
return;
}
IContainerUI* pContainer = static_cast<IContainerUI*>(pCtrl->GetInterface(L"IContainer"));
if (pContainer != NULL)
{
for (int i = 0; i < pContainer->GetCount(); ++i)
{
CControlUI* pItem = pContainer->GetItemAt(i);
Walk(pItem);
}
}
else
{
bool bFlag = pCtrl->GetDisplayCustomTTFlag();
if (bFlag)
pCtrl->SetText(m_pCallBack->GetCustomToolTip(m_pOwner, pCtrl->GetName()));
}
}
}//namespace Duilib
3、 stay UIControl.h in Add custom mouse prompt related variables and interfaces
//...
// Customize mouse tips
virtual void SetUserToolTipXml(LPCTSTR pstrXml);
virtual CDuiString GetUserToolTipXml() const;
virtual void SetToolTipCallBack(IToolTipCallBack* pCallBack);
virtual IToolTipCallBack* GetToolTipCallback() const;
virtual void SetDisplayCustomTT(bool bDisplay);
virtual bool GetDisplayCustomTTFlag() const;
//...
// Customize prompt window variables
CDuiString m_sToolTipXml; //!< tooltip XML File path
bool m_bDisplayCustomTT; //!< Whether to display prompt text on this control
IToolTipCallBack* m_pTTCallBack; //!< Usually the main window object
4、 stay UIControl.cpp in Add user-defined mouse prompt interface implementation
void CControlUI::SetUserToolTipXml(LPCTSTR pstrXml)
{
m_sToolTipXml = pstrXml;
}
CDuiString CControlUI::GetUserToolTipXml() const
{
return m_sToolTipXml;
}
void CControlUI::SetToolTipCallBack(IToolTipCallBack* pCallBack)
{
m_pTTCallBack = pCallBack;
}
IToolTipCallBack* CControlUI::GetToolTipCallback() const
{
return m_pTTCallBack;
}
void CControlUI::SetDisplayCustomTT(bool bDisplay)
{
m_bDisplayCustomTT = bDisplay;
}
bool CControlUI::GetDisplayCustomTTFlag()const
{
return m_bDisplayCustomTT;
}
stay SetAttribute in increase :
else if (_tcscmp(pstrName, _T("usertooltipxml")) == 0) SetUserToolTipXml(pstrValue);
else if (_tcscmp(pstrName, _T("displayusertt")) == 0) SetDisplayCustomTT(_tcscmp(pstrValue, _T("true")) == 0);
5、 stay UIManger.h in Add custom mouse prompt related variables and interface callback
// Set custom mouse prompt callback
void SetToolTipCallback(IToolTipCallBack* pToolTipCallback);
// Customize mouse tips
CCustomToolTipUI* m_pCustomToolTipWnd;
IToolTipCallBack* m_pCustToolTipCallback;
6、 stay UIManger.cpp in Add relevant interface processing
void CPaintManagerUI::SetToolTipCallback(IToolTipCallBack* pToolTipCallback)
{
if (pToolTipCallback == nullptr)
return;
m_pCustToolTipCallback = pToolTipCallback;
}
stay MessageHandler Interface Medium WM_MOUSEHOVER Add :
if( m_hwndTooltip == NULL ) {
m_hwndTooltip = ::CreateWindowEx(0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hWndPaint, NULL, m_hInstance, NULL);
::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM) &m_ToolTip);
::SendMessage(m_hwndTooltip,TTM_SETMAXTIPWIDTH,0, pHover->GetToolTipWidth());
::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
}
if (m_pCustomToolTipWnd) {
m_pCustomToolTipWnd->Unsubclass();
}
if (pHover->GetUserToolTipXml() != L"") {
delete m_pCustomToolTipWnd;
m_pCustomToolTipWnd = new CCustomToolTipUI(pHover);
if (m_pCustomToolTipWnd == nullptr)
return 0;
if (m_pCustToolTipCallback) pHover->SetToolTipCallBack(m_pCustToolTipCallback);
m_pCustomToolTipWnd->Subclass(m_hwndTooltip);
m_pCustomToolTipWnd->Init(pHover->GetUserToolTipXml(), pHover->GetToolTipCallback());
}
::SendMessage(m_hwndTooltip, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(pt.x, pt.y));
7、 stay WindowImplBase.h in Add custom mouse prompt support
class UILIB_API WindowImplBase
: public CWindowWnd
, public CNotifyPump
, public INotifyUI
, public IDialogBuilderCallback
, public IToolTipCallBack //!< New base class
{
//...
/* * Get the prompt information of the control with the specified name * param [in] pTipOwner Usually mouse Hover object * param [in] pstrTipCtrl Prompt widget name */
virtual LPCTSTR GetCustomToolTip(DuiLib::CControlUI* pTipOwner, LPCTSTR pstrTipCtrl);
//...
};
8、 stay WindowImplBase.cpp Add custom mouse prompts to support processing
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
//...
// Support custom prompt window
m_pm.SetToolTipCallback(this);
//...
}
LPCTSTR WindowImplBase::GetCustomToolTip(DuiLib::CControlUI* pTipOwner, LPCTSTR pstrTipCtrl)
{
return _T("");
}
9、 stay UIlib.h in increase Newly increased UICustonToolTipUI.h file
//...
#include "Control/UICustomToolTipUI.h"
//...
10、 In the dialog implementation file increase UI File and code processing
void CTestDlg::InitWindow()
{
// Close button to add custom prompt window display
DuiLib::CButtonUI* pButtonUI = static_cast<DuiLib::CButtonUI*>(m_pm.FindControl(_T("btn_test")));
if (pButtonUI)
{
pButtonUI->SetToolTipCallBack(this);
pButtonUI->SetUserToolTipXml(_T("testToolTip.xml"));
}
}
Mouse prompt window UI file : Here is an example of a dynamic graph
<?xml version="1.0" encoding="utf-8"?>
<Window size="30,30" mininfo="30,30" caption="0,0,0,0" sizebox="4,4,4,4" bktrans="false">
<HorizontalLayout inset="3,3,3,3">
<GifAnim width="20" height="20" resourcetext="true" tooltip="tooltip_downloadting" displayusertt="true" autoplay="true" bkimage="download.gif" />
</HorizontalLayout>
</Window>
Final rendering :

OK! Get it done !
边栏推荐
- Componentized advanced -- slot
- LDA分类器
- Develop the first Flink app
- 【C语言】自定义类型初阶知识点
- [C language] storage of shaping data
- The study found that DNA nano device injection can be safely used for medical purposes
- 【C语言】数组知识点总结
- [C language] Pointer exercise 2 - real written test questions and analysis
- KNN classifier
- 第十一章 STL 之 queue
猜你喜欢
![[C language] void type and void* pointer type](/img/4c/3643d850bfcb57db93496ec9bba06e.png)
[C language] void type and void* pointer type

第一部分—C语言基础篇_3. 运算符与表达式

Flink小知识--任务调度slot的配置 slotSharingGroup

第十章 STL 之 stack

Part I - Fundamentals of C language_ 1. Overview of C language

Es conceptual model and basic faults

将视频格式转换为gif图片格式

Part I - Fundamentals of C language_ 5. Arrays and strings

Interview questions - design test cases for:: memcpy function

Fundamentals of C language -- 2-3 pointers and arrays
随机推荐
企业数字化转型,为何 SaaS 模式如此重要?
[C language] data type and meaning
AcWing 257. 关押罪犯 题解(二分图)
Part I - Fundamentals of C language_ 1. Overview of C language
Anycontrol demo demo demo
易贝按关键字搜索EBAY商品 API 返回值说明
Add - before the command in makefile to ignore the error caused by the command and continue to execute the next command
mysql进阶(六)模糊查询的四种常见用法介绍
Pytorch calls cublasltmattmul to do GEMM and add bias. It's well written
AnyControl Demo演示
[hero planet July training leetcode problem solving daily] 17th kuansou
第一部分—C语言基础篇_3. 运算符与表达式
[performance optimization methodology series] VI. summary
第一部分—C语言基础篇_6. 函数
Part I - Fundamentals of C language_ 5. Arrays and strings
Series operation of vector container (detailed explanation)
【C语言】浮点型在内存的存储
C语言编译过程
Chapter 10 stack of STL
[C language] storage of floating-point type in memory