0

An MFC application need an edit ctrl in dialog for edit Tamil language. But I found the Tamil language does not have code page in Windows (Yes, there isn't Tamil system locale), and the Unicode option is not in my situation.

Saw someone idea, Embedding HWND into external process using SetParent

I wanna to create another application built with UNICODE option, embed its window to the dialog, but failed. Check the MSDN, SetParent need the parent and child window in one application.

So, how can I implement it?

@MSalters

I solved it by override virtual BOOL CWinThread::PumpMessage(), force the message loop use W version API.

BOOL CtamildlgApp::PumpMessage()
{
    _AFX_THREAD_STATE *pState = AfxGetThreadState();

    if ( !::GetMessageW( &( pState->m_msgCur ), NULL, NULL, NULL ) )
    {
        // Note: prevents calling message loop things in 'ExitInstance'
        // will never be decremented
        return FALSE;
    }

    // process this message

    if ( pState->m_msgCur.message != WM_KICKIDLE )
    {
        ::TranslateMessage( &( pState->m_msgCur ) );
        ::DispatchMessageW( &( pState->m_msgCur ) );
    }

    return TRUE;
}

Then CreateWindowExW(... MSFTEDIT_CLASS ...)

Community
  • 1
  • 1
  • Look here: http://www.codeproject.com/Articles/11040/Multiple-language-support-for-MFC-applications-wit, here: http://msdn.microsoft.com/en-us/goglobal/bb978454.aspx and here: http://msdn.microsoft.com/library/dd319076%28VS.85%29.aspx – paulsm4 Sep 21 '12 at 07:10

1 Answers1

0

Tamil is indeed harder than usual. But still there's one thing obvious: use Unicode, not MBCS. Internally, all Windows functions are Unicode. The MBCS wrappers use the current code page to translate from multi-byte encodings to UTF-16. E.g. when you call MessageBoxA("Some String"), the current code page is used to translate that into a call of MessageBoxW(L"Some String").

Now, this directly means that you cannot call MessageBoxA("Narrow Tamil String") since there's no code page to convert that into the appropriate wide string. You MUST call the Unicode function MessageBoxW("Narrow Tamil String") directly.

MFC cannot magically make this problem go away. It may provide a nicer syntax for some calls, wrapping Win32 idioms in classes, constructors and destuctors. But it can't create missing code pages out of thin air.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • If only show the Taminl language, use DrawTextW can do the work. But need edit, I have no idea. – Wenbo Huang Sep 21 '12 at 09:22
  • That's just a `CreateWindowExW(... MSFTEDIT_CLASS ...)` call in the end. – MSalters Sep 21 '12 at 09:47
  • @WenboHuang: That may be a valid question in its own right, especially if you can show code. But be clear there what fails. Adding the control, or using Tamil in it? – MSalters Sep 24 '12 at 08:02
  • I add follow code in my dialog OnInitDialog method: // TODO: Add extra initialization here LoadLibrary( TEXT( "Msftedit.dll" ) ); CreateWindowExW( 0, MSFTEDIT_CLASS, NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_TABSTOP, 0, 0, 300, 100, this->m_hWnd, NULL, NULL, NULL ); It show '?' when I input Tamil character. – Wenbo Huang Sep 25 '12 at 01:46
  • @WenboHuang: Don't put questions in comments. And you might want to add exactly how you input that character. – MSalters Sep 25 '12 at 07:49