I have a .NET
application that I launch from an MFC
application using WinAPI's CreateProcess
function. The .NET application only has text labels and buttons. The problem is that the text of these labels and buttons is in Italian. I need to translate them into English. I solve this problem by finding the windows for these labels and buttons using FindWindowEx
and then replacing the text in them with the SetWindowText
function. The text of Labels was translated just fine. The problem is with the buttons. The old text remains displayed in the buttons. Even though when the GetWindowTextW
function is called on the button window, the translated value is returned. The Spy++ utility also returns a new value. I give below the source code of the function in the MFC application, which launches and translates the windows of the .NET application:
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.wShowWindow = SW_HIDE; //I launch .NET app hidden before translating
si.dwFlags = STARTF_USESHOWWINDOW;
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
//Full path to .NET app
CString ingran_name = DotNetAppFullPath;
if (!CreateProcess(NULL, // No module name (use command line).
(LPWSTR)(LPCWSTR)ingran_name, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Ambiente di esecuzione
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi)) // Pointer to PROCESS_INFORMATION structure.{
{
return;
}
Sleep(500);
//Main window .NET app
HWND ingran_main_hwnd = FindTopWindow(pi.dwProcessId);
CWnd* ingran_main_pWnd = CWnd::FromHandle(ingran_main_hwnd);
//Translate Label
CWnd* label_pWnd = FindWindowEx(ingran_main_hwnd, NULL, NULL, _T("OriginalTextLabel"));
CString reset_btn;
label_pWnd->GetWindowTextW(reset_btn);
label_pWnd->SetWindowText(_T("TranslatedTextLabel"));
label_pWnd->GetWindowTextW(reset_btn);
//Translate button
CWnd* button_pWnd = FindWindowEx(ingran_main_hwnd, NULL, NULL, _T("OriginalTextButton"));
button_pWnd->UnlockWindowUpdate();
button_pWnd->GetWindowTextW(reset_btn); //here I get "OriginalTextButton"
button_pWnd->SetWindowText(_T("TranslatedTextButton"));
button_pWnd->GetWindowTextW(reset_btn); //here I get "TranslatedTextButton"
button_pWnd->UpdateData(); //That didn't help
button_pWnd->UpdateWindow(); //And that didn't help too
//Now I show the main window
ingran_main_pWnd->ShowWindow(SW_SHOW);
I don't have the source code for the application that I need to localize. For my experiments with translation, in order to eliminate the influence of hidden factors that can prevent text replacement, I created my own MFC and .NET applications. In the MFC, when I click on the button, I run the above code. After running this code the .NET applications starts and the label text is replaced, the button text remains the same. Although if run under a debugger, then button_pWnd-> GetWindowTextW(reset_btn);
returns the replaced text - TranslatedTextButton. Also, when viewing the properties of the button window by the Spy++ utility, the title of the TranslatedTextButton window is displayed.