2017-08-18 05:08:22 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
WORD ctrlId;
|
|
|
|
char* text;
|
|
|
|
} _ToolTipMap;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class CToolTipDialog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
HWND m_hWndTooltip;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CToolTipDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddToolTip(WORD ctrlId, char* lpszText)
|
|
|
|
{
|
|
|
|
T* pT = static_cast<T*>(this);
|
|
|
|
|
2020-05-12 12:19:05 +00:00
|
|
|
std::wstring wcText = stdstr(lpszText).ToUTF16();
|
2017-08-18 05:08:22 +00:00
|
|
|
TOOLINFO toolInfo = { 0 };
|
|
|
|
toolInfo.cbSize = sizeof(toolInfo);
|
|
|
|
toolInfo.hwnd = pT->m_hWnd;
|
|
|
|
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
|
|
|
|
toolInfo.uId = (UINT_PTR) ::GetDlgItem(pT->m_hWnd, ctrlId);
|
2020-05-12 12:19:05 +00:00
|
|
|
toolInfo.lpszText = (LPWSTR)wcText.c_str();
|
2017-08-18 05:08:22 +00:00
|
|
|
SendMessage(m_hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DlgToolTip_Init()
|
|
|
|
{
|
|
|
|
T* pT = static_cast<T*>(this);
|
|
|
|
|
|
|
|
m_hWndTooltip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
|
|
|
|
WS_POPUP | TTS_ALWAYSTIP,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
pT->m_hWnd, NULL,
|
2021-04-12 11:35:39 +00:00
|
|
|
NULL, NULL);
|
2017-08-18 05:08:22 +00:00
|
|
|
|
|
|
|
const _ToolTipMap* map = pT->_GetToolTipMap();
|
|
|
|
|
|
|
|
for (int i = 0; map[i].ctrlId != 0; i++)
|
|
|
|
{
|
|
|
|
AddToolTip(map[i].ctrlId, map[i].text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BEGIN_TOOLTIP_MAP() static const _ToolTipMap* _GetToolTipMap() { static const _ToolTipMap map[] = {
|
|
|
|
#define TOOLTIP(ctrlId, text) { ctrlId, text },
|
2021-03-17 09:28:00 +00:00
|
|
|
#define END_TOOLTIP_MAP() { 0 } }; return map; }
|