You can do :
At beginning (#pragma for Visual Styles) :
#include <commctrl.h>
#pragma comment(lib, "comctl32")
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
BOOL AddTool(int nMessage, HWND hWndTooltip, HWND hWnd, TCHAR* pszTooltip, RECT* rectTool, int nID);
HWND CreateTooltip(HWND hWndParent, HWND hWnd, TCHAR* pszTooltip);
HWND g_hWndTooltip = NULL;
void ScreenToClientRect(HWND hWndClient, RECT& rcInOut);
At end of WM_CREATE :
g_hWndTooltip = CreateTooltip(hwnd, hwnd, TEXT(""));
TCHAR wsBuffer[4096];
for (i = 0; i < NUM; i++)
{
wsprintf(wsBuffer, TEXT("Tooltip : %d"), i);
if ((button[i].iStyle == BS_GROUPBOX))
{
RECT rect;
GetWindowRect(hwndButton[i], &rect);
ScreenToClientRect(hwnd, rect);
AddTool(TTM_ADDTOOL, g_hWndTooltip, hwnd, wsBuffer, &rect, -1);
}
else
AddTool(TTM_ADDTOOL, g_hWndTooltip, hwndButton[i], wsBuffer, NULL, -1);
}
Utility functions :
HWND CreateTooltip(HWND hWndParent, HWND hWnd, TCHAR* pszTooltip)
{
HWND hWndTooltip = NULL;
TOOLINFO ti = { 0 };
RECT rect;
hWndTooltip = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hWndParent,
NULL,
GetModuleHandle(0),
NULL
);
if (NULL != hWndTooltip)
{
SetWindowPos(hWndTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
GetClientRect(hWnd, &rect);
//ti.cbSize = sizeof(TOOLINFO);
ti.cbSize = (6 > SendMessage(hWndTooltip, CCM_GETVERSION, 0, 0)) ? TTTOOLINFOW_V2_SIZE : sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hWnd;
ti.hinst = GetModuleHandle(0);
ti.uId = 0;
ti.lpszText = pszTooltip;
ti.rect = rect;
BOOL bReturn = SendMessage(hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
}
SetFocus(hWnd);
return hWndTooltip;
}
BOOL AddTool(int nMessage, HWND hWndTooltip, HWND hWnd, TCHAR* pszTooltip, RECT* rectTool, int nID)
{
TOOLINFO ti = { 0 };
//ti.cbSize = sizeof(TOOLINFO);
ti.cbSize = (6 > SendMessage(hWndTooltip, CCM_GETVERSION, 0, 0)) ? TTTOOLINFOW_V2_SIZE : sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.hwnd = hWnd;
ti.hinst = GetModuleHandle(0);
ti.lpszText = pszTooltip;
if (rectTool == NULL)
{
ti.uId = (UINT)hWnd;
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.rect.left = ti.rect.top = ti.rect.bottom = ti.rect.right = 0;
}
else
{
ti.uId = nID;
ti.uFlags = TTF_SUBCLASS;
SetRect(&ti.rect, rectTool->left, rectTool->top, rectTool->right, rectTool->bottom);
}
if (!SendMessage(hWndTooltip, nMessage, 0, (LPARAM)&ti))
return FALSE;
return TRUE;
}
void ScreenToClientRect(HWND hWndClient, RECT& rcInOut)
{
POINT ptTopLeft;
ptTopLeft.x = rcInOut.left;
ptTopLeft.y = rcInOut.top;
POINT ptBottomRight;
ptBottomRight.x = rcInOut.right;
ptBottomRight.y = rcInOut.bottom;
ScreenToClient(hWndClient, &ptTopLeft);
ScreenToClient(hWndClient, &ptBottomRight);
rcInOut.left = ptTopLeft.x;
rcInOut.top = ptTopLeft.y;
rcInOut.right = ptBottomRight.x;
rcInOut.bottom = ptBottomRight.y;
}