1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
HWND CreateToolTip(HWND hwndTool, string text)
{
/*INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);*/
if (text=="")
{
return FALSE;
}
// Get the window of the tool.
//HWND hwndTool = GetDlgItem(hDlg, toolID);
// Create the tooltip. g_hInst is the global instance handle.
HWND hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
GetParent(hwndTool), NULL,
hinstance, NULL);
if (!hwndTool || !hwndTip)
{
MessageBox(NULL, "Couldn't create the ToolTip control.", "Error", MB_OK);
return (HWND)NULL;
}
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = TTTOOLINFOA_V1_SIZE;
toolInfo.hwnd = GetParent(hwndTool);
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText =(LPSTR) text.c_str();
if (SendMessage(hwndTip, TTM_ACTIVATE, TRUE, 0)) //Will add the Tool Tip on Control
{
int err = GetLastError();
MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);
}
if (!SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo)) //Will add the Tool Tip on Control
{
int err = GetLastError();
MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);
}
return hwndTip;
}
|