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;