Do I need to destroy the tooltip?

In my application, I process the WM_HELP message and then create a tooltip for the control using this method:

Taken from: http://msdn.microsoft.com/en-us/library/bb760252(v=vs.85).aspx

 HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) { if (!toolID || !hDlg || !pszText) { 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(NULL, TOOLTIPS_CLASS, NULL, WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hDlg, NULL, g_hInst, NULL); if (!hwndTool || !hwndTip) { return (HWND)NULL; } // Associate the tooltip with the tool. TOOLINFO toolInfo = { 0 }; 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; } 

The tooltip disappears as soon as I move the mouse pointer.

My questions:

  • Is the tooltip destroyed or is it just hidden?
  • If it is hidden, then how to destroy it and when?

Thanks.

+4
source share
3 answers

Some time has passed since I did some WinAPI programming, but if my memory serves me ...

The CreateWindowEx call passes hDlg as the hWndParent parameter, meaning that the dialog box is now the parent of the tooltip.

The DestroyWindow MSDN documentation says:

If the specified window is a parent or user window, DestroyWindow automatically destroys the associated child or its windows when it destroys the parent or user window. The function first destroys the child or belonging to the window, and then destroys the parent or user window.

So, you can assume that the window of your popup will be destroyed in the end. Be careful if you call CreateToolTip in response to each WM_HELP message, as you end up with a few pop-ups at the top of the memory until your dialog is closed and DestroyWindow is finally called.

As stated in vz0, you can create a tooltip once, hang it on a window handle, and then show a tooltip in response to a help message, rather than creating it again.

In your comment on vz0's answer, you said:

There are several ways in which the tooltip passes. example: mouse movement, timeout, etc.

All this leads to hiding the window, so the tooltip descriptor remains valid and can be displayed again using ShowWindow .

+2
source

For each call to CreateWindowEx , a corresponding DestroyWindow call is required.

Alternatively, instead of creating and destroying a window, every time you can use the ShowWindow call with SW_SHOW and SW_HIDE to show and hide the popup.

+2
source

In my experience, I had DestroyWindow() in the tooltip, so HFONT (font GDI resource) was correctly issued. Once between two windows there was a connection between parents and children, but my system changes this at runtime and may be to blame. Perhaps this does not harm if your system generalizes it.

0
source

Source: https://habr.com/ru/post/1337772/


All Articles