Board index » cppbuilder » Translation for the Application->MessageBox (Yes and No).

Translation for the Application->MessageBox (Yes and No).


2005-03-06 03:23:31 AM
cppbuilder106
Hello,
Is it possible to have translated the MessageBox to show translation for the
Yes and No button ?? ...
if (Application->MessageBox(myLoadString(IDS_LANG1_STRING85).c_str(),
myLoadString(IDS_LANG1_STRING86).c_str(), MB_YESNO) == IDNO)
I have an application that needs to have all the strings translated to
another language (French for example) and need to have the Yes and No button
translated to French.
What will be the best approach to translate the MessageBox strings.
Thanks for your help.
Jean Boivin
 
 

Re:Translation for the Application->MessageBox (Yes and No).

"Jean Boivin" < XXXX@XXXXX.COM >wrote in message
Quote
Hello,

Is it possible to have translated the MessageBox to show translation for
the
Yes and No button ?? ...

if (Application->MessageBox(myLoadString(IDS_LANG1_STRING85).c_str(),
myLoadString(IDS_LANG1_STRING86).c_str(), MB_YESNO) == IDNO)

I have an application that needs to have all the strings translated to
another language (French for example) and need to have the Yes and No
button
translated to French.
What will be the best approach to translate the MessageBox strings.
Unfortunately, MessageBox() and MessageBoxEx() cannot be translated
directly, as the button texts depend on the current translation selected in
the OS.
So the solution depends on two things: 1) what translation tool(s) you use
(or plan to use) and, 2) how much work you are willing to do.
The solution I finally settled on was to write a MessageBox() replacement
function implemented in terms of the VCL function CreateMessageBox(). In my
case, I used Localizer to do the actual translation work which, fortunately,
has the ability to translate the resource strings in the VCL. This made the
task relatively simple, for once I had the replacement function written, all
I had to do was use Localizer to translate the text ("Yes", "No", "OK",
"Cancel", etc.), and Localizer then takes care of the loading the
appropriate translation at runtime.
If you don't have a translation tool such as Localizer, then about the only
option you have is to write your own MessageBox function to give you the
kind of flexibilty you need. You may not need automatic dialog sizing, or
all possible combinations of "Yes", "Yes to All", etc., in which case,
writing your own MessageBox should be fairly straight forward.
I am not necessarily advocating Localizer (it works, but it has its quirks
and problems too), but any translation tool worth its salt should be able to
translate the VCL's resource strings. If you have one that can do that,
then a CreateMessageBox-based solution is by far the easiest, IMO.
Good luck,
- Dennis
 

Re:Translation for the Application->MessageBox (Yes and No).

"Dennis Jones" < XXXX@XXXXX.COM >wrote:
Quote

[...] then about the only option you have is to write your
own MessageBox function [...]
//-------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
protected: // User declarations
virtual void __fastcall WndProc(TMessage &Message);
private: // User declarations
#define APP_MESSAGEBOX_MESSAGE (WM_USER + 1)
AnsiString MessageBoxCaption;
void __fastcall SetupMessageBox();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//-------------------------------------------------------------
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//-------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//-------------------------------------------------------------
BOOL CALLBACK EnumChildCallBack( HWND hWnd, LPARAM lParam )
{
char Buffer[256] = {0};
if( ::GetClassName(hWnd, Buffer, 255) )
{
if( stricmp(Buffer, (char*)lParam) == 0 )
{
::GetWindowText( hWnd, Buffer, 255 );
if( stricmp(Buffer, "OK") == 0 ) strcpy(Buffer, "OK Button");
else if( stricmp(Buffer, "Cancel") == 0 ) strcpy(Buffer, "Cancel Button");
else if( stricmp(Buffer, "&Yes") == 0 ) strcpy(Buffer, "&Yes Button");
else if( stricmp(Buffer, "&No") == 0 ) strcpy(Buffer, "&No Button");
else if( stricmp(Buffer, "&Abort") == 0 ) strcpy(Buffer, "&Abort Button");
else if( stricmp(Buffer, "&Retry") == 0 ) strcpy(Buffer, "&Retry Button");
else if( stricmp(Buffer, "&Ignore") == 0 ) strcpy(Buffer, "&Ignore Button");
::SetWindowText( hWnd, Buffer );
}
}
return TRUE;
}
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
//
}
//-------------------------------------------------------------
void __fastcall TForm1::WndProc(TMessage &Message)
{
if( Message.Msg == APP_MESSAGEBOX_MESSAGE )
{
SetupMessageBox( this );
}
TForm::WndProc(Message);
}
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String Text;
Text.sprintf("First row of message.\nSecond row of message.");
MessageBoxCaption = "This is the message box caption";
::PostMessage( Handle, APP_MESSAGEBOX_MESSAGE, 0, 0 );
::MessageBox( Handle, Text.c_str(), MessageBoxCaption.c_str(), MB_ICONERROR | MB_ABORTRETRYIGNORE );
}
//-------------------------------------------------------------
void __fastcall TForm1::SetupMessageBox( TForm* pForm )
{
RECT R;
int x, y, w, h;
HWND MessageBoxHandle = FindWindow( MAKEINTRESOURCE(WC_DIALOG), MessageBoxCaption.c_str() );
if( MessageBoxHandle )
{
AnsiString WindowClassName = "Button";
::EnumChildWindows( MessageBoxHandle, (WNDENUMPROC)EnumChildCallBack, (LPARAM)WindowClassName.c_str() );
::GetWindowRect( MessageBoxHandle, &R );
w = R.right - R.left;
h = R.bottom - R.top;
// center the box
x = pForm->Left + ((pForm->Width - w) / 2);
y = pForm->Top + ((pForm->Height - h) / 2);
// keep on screen
if( x < 0 ) x = 0;
else if( x + w>Screen->Width ) x = Screen->Width - w;
if( y < 0 ) y = 0;
else if ( y + h>Screen->Height ) y = Screen->Height - h;
// set new windows position
::SetWindowPos( MessageBoxHandle, 0, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
}
}
//-------------------------------------------------------------
~ JD
 

{smallsort}

Re:Translation for the Application->MessageBox (Yes and No).

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
Unfortunately, MessageBox() and MessageBoxEx() cannot
be translated directly, as the button texts depend on the
current translation selected in the OS.
MessageBoxEx() takes a LanguageID parameter that specifies the language to
use for the buttons.
Gambit
 

Re:Translation for the Application->MessageBox (Yes and No).

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
news:422a7b0e$ XXXX@XXXXX.COM ...

>Unfortunately, MessageBox() and MessageBoxEx() cannot
>be translated directly, as the button texts depend on the
>current translation selected in the OS.

MessageBoxEx() takes a LanguageID parameter that specifies the language to
use for the buttons.
True, but it requires that the desired language file both exist and be
installed on the end-user's computer, which may not always be the case, or
even desirable. MessageBoxEx is, therefore, only useful if you know (or can
otherwise guarantee) that your program will run on a computer on which that
is the case, but enforcing that requirement on your end-users might not be
practical.
- Dennis