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

58 lines
1.2 KiB
C
Raw Normal View History

2017-08-18 05:08:22 +00:00
#pragma once
#include "stdafx.h"
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,
NULL, NULL);
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 },
#define END_TOOLTIP_MAP() { 0 } }; return map; }