How to use Windows ToolTip Control without bounding to a tool

后端 未结 2 1993
感动是毒
感动是毒 2021-01-04 10:32

I want to use the native windows tooltip control (pure Win32 API, no MFC stuff).

I read the doc, it seems that I have to send a TTM_ADDTOOL message to bond a tool to

2条回答
  •  無奈伤痛
    2021-01-04 10:58

    Addition Windows 10 (Visual Studio 2015, Win32 Console Application)

    #include "Commctrl.h"                   
    #pragma comment (lib,"comctl32.lib")    
    #pragma comment(linker,"\"/manifestdependency:type='win32' \
    name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
    processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    
    TOOLINFOW ti = {};
    ti.cbSize = sizeof(TOOLINFOW);
    ti.uFlags = TTF_ABSOLUTE | TTF_IDISHWND | TTF_TRACK ; // WITH TTF_TRACK! Otherwise the tooltip doesn't follow TTM_TRACKPOSITION message!
    ti.hwnd = toolTipWnd;                       
    ti.hinst = 0;
    ti.uId = (UINT)toolTipWnd;
    ti.lpszText = L"";
    
    LRESULT result; 
    int error; 
    if (!SendMessageW(toolTipWnd, TTM_ADDTOOLW, 0, (LPARAM)&ti)) {
        MessageBox(NULL, L"Couldn't create the ToolTip control.", L"Error", MB_OK);
        error = 0;
        error = GetLastError();
    }
    if (!SendMessageW(toolTipWnd, TTM_SETMAXTIPWIDTH, 0, (LPARAM)350)) {
        MessageBox(NULL, L"Couldn't create the ToolTip control.", L"Error", MB_OK);
        error = 0;
        error = GetLastError();
    }
    

提交回复
热议问题