project64/Source/Project64/UserInterface/WTLControls/TooltipDialog.h

57 lines
1.5 KiB
C
Raw Normal View History

2017-08-18 05:08:22 +00:00
#pragma once
2022-09-26 02:31:54 +00:00
typedef struct
{
WORD ctrlId;
char * text;
2017-08-18 05:08:22 +00:00
} _ToolTipMap;
template <class T>
class CToolTipDialog
{
private:
2022-09-26 02:31:54 +00:00
HWND m_hWndTooltip;
2017-08-18 05:08:22 +00:00
public:
2022-09-26 02:31:54 +00:00
CToolTipDialog()
{
}
2017-08-18 05:08:22 +00:00
2022-09-26 02:31:54 +00:00
void AddToolTip(WORD ctrlId, char * lpszText)
{
T * pT = static_cast<T *>(this);
2017-08-18 05:08:22 +00:00
2020-05-12 12:19:05 +00:00
std::wstring wcText = stdstr(lpszText).ToUTF16();
2022-09-26 02:31:54 +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);
toolInfo.lpszText = (LPWSTR)wcText.c_str();
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,
NULL, NULL);
const _ToolTipMap * map = pT->_GetToolTipMap();
for (int i = 0; map[i].ctrlId != 0; i++)
{
AddToolTip(map[i].ctrlId, map[i].text);
}
}
2017-08-18 05:08:22 +00:00
};
#define BEGIN_TOOLTIP_MAP() static const _ToolTipMap* _GetToolTipMap() { static const _ToolTipMap map[] = {
#define TOOLTIP(ctrlId, text) { ctrlId, text },
#define END_TOOLTIP_MAP() { 0 } }; return map; }