// This shows how to attach a tooltip to a control, // and make it a balloon shaped. // Thanks go to Saar(tornado@goblineye.com) for this code!!
// Create the tooltip // The tooltip is created as top-most so the parent will never hide it // Also, created as a cool baloon tooltip
HWND hwndTool = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hDlg, NULL, g_hInstance, NULL);
TOOLINFO toolInfo; toolInfo.cbSize = sizeof(toolInfo); // The tooltip subclasses the tool it uses so it can intercept messages like WM_MOUSEMOVE etc, // we also mention the uId will be the handle to the tool toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; // Handle to the window that contains the tool toolInfo.hwnd = hDlg; // Handle to the tool (in this case: a listview control) toolInfo.uId = (unsigned int)GetDlgItem(hDlg, IDC_MAINLISTCTRL); // The text that always appears toolInfo.lpszText = "Some useful info";
// Add the tool to the control SendMessage(hwndTool, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); // Set a nice title to the baloon SendMessage(hwndTool, TTM_SETTITLE, 1, (LPARAM)"Title of tooltip"); // Activate the tooltip SendMessage(hwndTool, TTM_ACTIVATE, true, 0); // and viola, finished. // Remember to destroy the window later when you're done DestroyWindow(hwndTool);
BTW - Don't forget to init common controls ( for the list view )! INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_TREEVIEW_CLASSES; InitCommonControlsEx(&icex); |