我想在我的应用程序窗口中显示unicode工具提示,但是他们似乎不显示。非Unicode文本显示正确,但只要我尝试做Unicode,没有工具提示出现。以下是我目前正在做的,任何帮助表示感谢。Unicode工具提示没有显示
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;
感谢您的注意。你是对的,不应该在那里,当我测试的时候,我忘了删除它。但是,这并不能解决我的问题。没有这个标志,仍然没有工具提示出现。 – Martin 2010-03-30 14:15:08
父窗口是否也是Unicode?也许在使用Unicode工具提示和ANSI父窗口之间存在不兼容问题。 – 2010-03-31 17:44:39