Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Windows ToolTip Control without bounding to a tool
    primarykey
    data
    text
    <p>I want to use the native windows tooltip control (pure Win32 API, no MFC stuff).</p> <p>I read the doc, it seems that I have to send a TTM_ADDTOOL message to bond a tool to the tooltip control. Only after that can I send TTM_TRACKACTIVATE &amp; TTM_TRACKPOSITION to show the tooltip.</p> <p>But I want to display the tooltip anywhere I want it to be. For example, when the mouse hovers over a region of my window. This region is not a tool in the eye of Windows, it's just a region in my window.</p> <p>Perhaps I can bond the window to the tooltip control, but, doesn't this mean that I have to bond every window I created to the tooltip control?</p> <p>Is there an easy solution so that I don't have to send TTM_ADDTOOL messages for every window?</p> <hr> <p>I actually have written some code, but the tooltip just doesn't appear. Anders' answer solves some questions actually. And after I poke around my code, I make it work.</p> <p>In case someone wants to know how it work:</p> <pre><code>HWND toolTipWnd = ::CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW,0,WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, 0,0,appHandle,0); TOOLINFOW ti = {}; ti.cbSize = sizeof(TOOLINFOW); ti.uFlags = TTF_ABSOLUTE | TTF_IDISHWND /* | TTF_TRACK */; // Don't specify TTF_TRACK here. Otherwise the tooltip won't show up. ti.hwnd = toolTipWnd; // By doing this, you don't have to create another window. ti.hinst = NULL; ti.uId = (UINT)toolTipWnd; ti.lpszText = L""; ::SendMessageW(toolTipWnd, TTM_ADDTOOLW, 0, (LPARAM)&amp;ti); ::SendMessageW(toolTipWnd, TTM_SETMAXTIPWIDTH,0, (LPARAM)350); </code></pre> <p>This will create a tooltip window which is not bound to any other window. So when you want to show the tooltip (e.g. in responds to WM_MOUSEHOVER message), call this:</p> <pre><code>TOOLINFOW ti = {}; ti.cbSize = sizeof(TOOLINFOW); ti.hwnd = toolTipWnd; ti.uId = (UINT)toolTipWnd; ti.lpszText = L"Sample Tip Text"; ::SendMessageW(toolTipWnd,TTM_UPDATETIPTEXTW,0,(LPARAM)&amp;ti); // This will update the tooltip content. ::SendMessageW(toolTipWnd,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&amp;ti); ::SendMessageW(toolTipWnd, TTM_TRACKPOSITION,0,(LPARAM)MAKELONG(x,y)); // Update the position of your tooltip. Screen coordinate. //::SendMessageW(toolTipWnd,TTM_POPUP,0,0); // TTM_POPUP not working.. Don't know why. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload