Вопрос

This is an old problem that I've never figured out - wondered if someone here might happen to know the answer off of the top of your head...

In some parts of our software (MFC/Win32/MBCS) my code will only receive

TTN_NEEDTEXTW

In other parts of our software, I'll receive the MBCS correct message

TTN_NEEDTEXTA

It makes no sense to me.

I understand that our software can be compiled Unicode or not (we are set to use Multibyte character set). And I have the vague recollection that each window can be constructed Unicode or not, though this is a vague memory, nothing concrete.

Does anyone know why we'd be getting the wide version message some places in our code, despite being compiled as multibyte?

NOTES:

  • We're definitely not sending this message - presumably the ToolTip control is.
  • We're definitely only receiving the (W) message in some places, and definitely only receiving the (A) message in others.
  • I'm certain that all compilation modules use MBCS, not Unicode, and that the build targets all specify MBCS not Unicode.
  • This seems to happen only for CMainFrame hosted windows and controls. i.e. Windows outside of the main frame can use narrow versions (say in a dialog box).
Это было полезно?

Решение

The common control sends you a WM_NOTIFYFORMAT message to ask you "Would you prefer to receive MBCS notifications or Unicode notifications?" The default is to respond based on whether the window was created via CreateWindowExW or CreateWindowExA.

Другие советы

With an MFC ansi app (that handles unicode data), I had this issue with CStatic derived classes and tooltip where I was getting TTN_NEEDTEXTA instead of, in my case, the desired TTN_NEEDTEXTW.

Using the accepted answer, managed to get TTN_NEEDTEXTW.

BEGIN_MESSAGE_MAP(CStaticDerived, CStatic)
ON_WM_NOTIFYFORMAT()
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnTTNeedText)
END_MESSAGE_MAP()

UINT CStaticDerived::OnNotifyFormat(
    CWnd *pWnd,
    UINT nCommand) {

    if (pWnd->m_hWnd
            == AfxGetModuleThreadState()->m_pToolTip->m_hWnd) {
        // want TTN_NEEDTEXTW for tooltips
        return NFR_UNICODE;
    }

    return __super::OnNotifyFormat(pWnd, nCommand);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top