views:

86

answers:

3

I am building a Windows dialog box that has the standard 'OK' and 'Cancel' buttons. Given that Windows uses the same button text in its own dialogs is there a way for me to grab the correct strings to use on the buttons?

This way my application will have the correct strings no matter which language is being used, without me needing to localize it for lots of different languages myself. I am using C# but can happily use platform invoke to access an OS method if needed.

NOTE: Yes, I can easily localize the resources but I do not want to find and have to enter the zillion different language strings when it must be present within windows already. Please do not answer by saying localize the app!

+2  A: 

No, there is no standard, supported way to do this. Yes, Windows does store these strings and it's (with some effort) possible to obtain them, but there is no guarantee that they'll remain in the same location and under the same identifier from version to version.

While you might not want this to be the answer, the answer is, indeed, to localize your application. If you're localizing everything else (as you'd have to, unless you just wanted OK and Cancel to be localized), I'm not sure why it would be any great effort to include localized values for OK and Cancel as well.

Adam Robinson
Downvoter care to explain?
Adam Robinson
The question clearly says: "Please do not answer by saying localize the app!"
Eduardo Molteni
@Eduardo: It's the only valid answer. I didn't answer just by saying "localize the app"; I answered by saying "No, it isn't possible to do what you're after. The only way to obtain a localized string is to localize the app yourself." It's a perfectly valid--and correct--answer.
Adam Robinson
Do not agree, sorry. There other two answers are correct and address the question. Ahh, and I was not the downvoter.
Eduardo Molteni
+3  A: 

Well, if you use the standard MessageBox.Show() function and pass it approriate parameters it will automatically localize the yes/no/okay/cancel buttons for you.

What is more interesting is how you localize the message text.

Byron Whitlock
+3  A: 

In Visual Studio: File + Open + File, type c:\windows\system32\user32.dll. Open the String Table node and double click String Table. Scroll down to 800.

Microsoft takes a pretty no-nonsense stance against relying on these resource IDs. Given the number of programmers who've done what you're contemplating, it is however unlikely they can ever change these numbers. You'll need to P/Invoke LoadLibrary() and LoadString().

However, you're ultimate downfall on this plan is Vista/Win7 Ultimate with MUI language packs. Which allows the user to switch between languages without updating the resource strings in the DLLs. Such an edition will always have English strings.

Hans Passant