Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MFC String-table in C# ?

24 views
Skip to first unread message

Giovanni Dicanio

unread,
Oct 16, 2008, 1:54:02 PM10/16/08
to
Hi,

maybe a bit OT for this newsgroup, but I know that people here use C#, too.

So, does anyone know how the MFC string-table technique map to C#/WinForm?

I initially thought about using an integer->string map in C#, but is there
some built-in mechanism to manage that?

Thanks,
Giovanni


Giovanni Dicanio

unread,
Oct 16, 2008, 5:05:05 PM10/16/08
to

"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> ha scritto nel
messaggio news:ugqw1g7L...@TK2MSFTNGP03.phx.gbl...

> So, does anyone know how the MFC string-table technique map to C#/WinForm?

...after some web search, it seems that C# has a ResourceManager class for
that purpose.

Giovanni


Mark Salsbery [MVP]

unread,
Oct 16, 2008, 5:47:06 PM10/16/08
to
"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> wrote in message
news:enJn5L9L...@TK2MSFTNGP02.phx.gbl...


You can also use assembly resources "embedded" in your C# app. Add a
resource (resx) file to your project, set it's namespace property if
desired.
Open it and add string resources (or other types).

Then in your code you can use a simpler way to access the strings than the
ResourceManager:

//example
string str = MyResourcesNamespace.Resource1.String1;


where MyResourcesNamespace is the namespace I specified, Resource1 is the
resx file I added, and String1 is the name of a string resource I added.

So simple even a C++ guy can do it :)

Mark

>
> Giovanni
>
>

Giovanni Dicanio

unread,
Oct 16, 2008, 6:05:09 PM10/16/08
to

"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospam> ha scritto nel
messaggio news:%238OJAj9...@TK2MSFTNGP03.phx.gbl...

> Then in your code you can use a simpler way to access the strings than the
> ResourceManager:
>
> //example
> string str = MyResourcesNamespace.Resource1.String1;
>
>
> where MyResourcesNamespace is the namespace I specified, Resource1 is the
> resx file I added, and String1 is the name of a string resource I added.

Thanks Mark!
It is simpler than the ResourceManager class!

> So simple even a C++ guy can do it :)

;-)

Giovanni


Mark Salsbery [MVP]

unread,
Oct 17, 2008, 12:41:06 PM10/17/08
to
"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> wrote in message
news:O1Gxdt9L...@TK2MSFTNGP04.phx.gbl...

>
> It is simpler than the ResourceManager class!


It's simpler because Visual Studio does the resource manager work for you!


I thought I'd add (in case you didn't see it) you can also use localized
resources this way.

Here's an example:

Walkthrough: Localizing Windows Forms
http://msdn.microsoft.com/en-us/library/y99d1cd3(VS.71).aspx


The link shows using a ResourceManager to access the strings, but if you add
a resource file like I described in my last post, the designer generates
that code wrapped in a class.

The resources in that first file become the neutral (not language specific)
resources.

To add culture-specific strings, you can add another resource file with the
same name except with a culture info name (e.g. Resource1.fr-FR.resx).

After adding the same named strings to that resource file, a thread's
CurrentUICulture setting will determine which resource is used:

// Set the current thread's CurrentUICulture
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

// the thread's CurrentUICulture determines where the string is loaded from!
string str = MyResourcesNamespace.Resource1.String1;


I really like how easy the C# dev environment makes this :)

Cheers,
Mark

Mark Salsbery [MVP]

unread,
Oct 17, 2008, 12:52:52 PM10/17/08
to
"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospam> wrote in message
news:ORwTscHM...@TK2MSFTNGP04.phx.gbl...

> To add culture-specific strings, you can add another resource file with
> the same name except with a culture info name (e.g. Resource1.fr-FR.resx).


...and if you add localized resources, don't forget to deploy the magically
generated satellite assemblies!

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

Giovanni Dicanio

unread,
Oct 17, 2008, 4:36:01 PM10/17/08
to
Thank you very much Mark for all this rich information!

Cheers,
Giovanni


Ajay Kalra

unread,
Oct 21, 2008, 10:21:07 PM10/21/08
to

"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospam> wrote in message
news:%238OJAj9...@TK2MSFTNGP03.phx.gbl...>

> You can also use assembly resources "embedded" in your C# app. Add a
> resource (resx) file to your project,

Thats how we use it and it works fine for us.

--
Ajay

Tom Serface

unread,
Oct 22, 2008, 11:31:26 AM10/22/08
to
I also use resx files and I really like the paradigm for ASP.NET especially.
It is VERY easy to add new languages and it defaults to the default language
for any key that is not defined in a sub language file. I wish MFC had
something like that.

Tom

"Ajay Kalra" <ajay...@yahoo.com> wrote in message
news:93878438-7A57-4D74...@microsoft.com...

Giovanni Dicanio

unread,
Oct 22, 2008, 1:27:43 PM10/22/08
to

"Tom Serface" <tom.n...@camaswood.com> ha scritto nel messaggio
news:DC464E5C-B5AF-4F23...@microsoft.com...

>I also use resx files and I really like the paradigm for ASP.NET
>especially. It is VERY easy to add new languages and it defaults to the
>default language for any key that is not defined in a sub language file. I
>wish MFC had something like that.

Yes, Tom.

After I discovered this .NET mechanism, I find it better than the MFC one.

There is lots of work for MFC improvement to be done :)

G

Ajay Kalra

unread,
Oct 22, 2008, 11:05:38 PM10/22/08
to

"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> wrote in message
news:e53dauG...@TK2MSFTNGP03.phx.gbl...

Or move to the superior environment :-)

--
Ajay

0 new messages