Unicode Tooltips Not Displaying

I am trying to display Unicode tooltips in my application window, however they do not seem to be displayed. Non-Unicode text displays correctly, but as soon as I try to execute Unicode, a tooltip will not appear. The following is what I am doing now; any gratitude thanks you.

HWND parentHwnd = pickInfo->getViewer().getCachedHwnd(); CWnd *pWnd = CWnd::FromHandlePermanent(parentHwnd); HINSTANCE hInstance = GetModuleHandle(NULL); if (isUnicode) m_toolInfoW.lpszText = L"This tooltip does not show up at all."; else m_toolInfoA.lpszText = "Non unicode text"; if (!m_bTooltipInitialized){ ::SendMessage(m_tooltipHwnd, WM_DESTROY, 0,0); if(isUnicode) m_tooltipHwnd = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parentHwnd, NULL, hInstance, NULL); else m_tooltipHwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parentHwnd, NULL, hInstance, NULL); if (GetLastError() != 0) return; ::SetWindowPos(m_tooltipHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // Set the max text width before multi-line tooltip is used. ::SendMessage(m_tooltipHwnd, TTM_SETMAXTIPWIDTH, 0, m_nMaxWinTooltipWidth); if (isUnicode){ m_toolInfoW.uFlags = TTF_SUBCLASS | TTF_IDISHWND | TTF_TRACK; m_toolInfoW.hinst = hInstance; m_toolInfoW.hwnd = parentHwnd; m_toolInfoW.uId = (UINT_PTR)parentHwnd; ::GetClientRect (parentHwnd, &m_toolInfoW.rect); ::SendMessage(m_tooltipHwnd, TTM_ADDTOOLW, 0, (LPARAM) (LPTOOLINFOW) &m_toolInfoW); ::SendMessage(m_tooltipHwnd, TTM_ACTIVATE, TRUE, (LPARAM)(LPTOOLINFOW) &m_toolInfoW); } else{ m_toolInfoA.uFlags = TTF_SUBCLASS | TTF_IDISHWND; m_toolInfoA.hinst = hInstance; m_toolInfoA.hwnd = parentHwnd; m_toolInfoA.uId = (UINT_PTR)parentHwnd; ::GetClientRect (parentHwnd, &m_toolInfoA.rect); ::SendMessage(m_tooltipHwnd, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_toolInfoA); ::SendMessage(m_tooltipHwnd, TTM_ACTIVATE, TRUE, (LPARAM)(LPTOOLINFO) &m_toolInfoA); } m_bTooltipInitialized = true; } if (isUnicode) ::SendMessage(m_tooltipHwnd, TTM_UPDATETIPTEXTW, 0, (LPARAM) (LPTOOLINFOW) &m_toolInfoW); else ::SendMessage(m_tooltipHwnd, TTM_UPDATETIPTEXT, 0, (LPARAM) (LPTOOLINFO) &m_toolInfoA); //Repaint the screen so that the area beneath the previous location of the tooltip is restored correctly. ::UpdateWindow(pWnd->GetParentOwner()->GetSafeHwnd()); pWnd = NULL; 
+4
source share
3 answers

The problem is that you are trying to use generic version 6 controls, but you cannot use it.

More details

 typedef struct tagTOOLINFOW { UINT cbSize; UINT uFlags; HWND hwnd; UINT_PTR uId; RECT rect; HINSTANCE hinst; LPWSTR lpszText; LPARAM lParam; #if (NTDDI_VERSION >= NTDDI_WINXP) void *lpReserved; #endif } TTTOOLINFOW, NEAR *PTOOLINFOW, *LPTTTOOLINFOW; 

for xp +, the CommCtrl.h header file assumes that you will use comctl version 6, but if you do not include it explicitly with the manifest file, you will still use the old version of comctl version 5.X. Then there is a problem, the size of TOOLINFO version 5.x differs from version 6.x.

So, if you need to use comctl version 5 under windows xp +, you have to run TOOLINFO with the following code,

 TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO) - 4; 

Otherwise, you must enable the visual style using the manifest file or the prgram directive:

 #pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 

Finally, I would recommend always including visual viewing in xp +. Here is a comparison of visual effects:

common controls 5.x

common controls 6.x

Note. If you use ANSI / MBCS to compile the program, sizeof (TOOLINFO) will be 48, which already deleted the lpReserved member. Thus, the ANSI version will work, but UNICODE will fail.

+6
source

In the case of Unicode, you have TTF_TRACK , which I think requires you to show or hide the tooltip manually. In the case of ANSI, you do not have this option.

http://msdn.microsoft.com/en-us/library/bb760252(VS.85).aspx

Scroll down to "Implement tracking tips."

+1
source

A good explanation and solution that will work Jichao above, but a hard wiring of the size of the TOOLINFO structure will fix only the tooltips. If the problem is that the program was compiled with the general control 6.0+, but can be run (say) on Windows XP with 6.0+, it is either not installed or not installed completely (for example, someone installed IE, but never used or updated it), then a more general solution is to limit the use of the application to standard 5.x controls only.

As you can see here , there are more things that have texture resizing than just hints.

What I did to ensure that everything works on Windows XP will put the following at the top of my program before any of them (in the case of visual studio, a good place will be at the top of targetver.h if you have one):

 #define _WIN32_WINNT 0x0500 
+1
source

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


All Articles