我使用 MSDN 中的功能为控件创建工具提示
HWND CreateToolTip(int toolID, HINSTANCE hInst, HWND hDlg, PTSTR pszText) {
if (!toolID || !hDlg || !pszText) {
return FALSE;
}
HWND hwndTool = GetDlgItem(hDlg, toolID);
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
if (!hwndTool || !hwndTip) {
return (HWND)NULL;
}
TOOLINFO toolInfo;
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return hwndTip;
}
然后在WndProc
WM_CREATE
我创建按钮Button=CreateWindowEx(
0,
L"BUTTON",
L"My Button",
WS_VISIBLE|WS_CHILD,
10, 10, 100, 24,
hWnd,
(HMENU)ID_TOOLTIP,
hInst,
NULL);
最后创建工具提示tooltip_mess = CreateToolTip(ID_TOOLTIP, hInst, hWnd, (PTSTR)"Tooltip message");
但是它不起作用,我看不到我的工具提示,我做错了什么?