Re: How about a resource string cache?
"Goran" <goran.pusic@gmail.com> wrote in message
news:80bc9aa9-18b8-4699-9651-af400084756c@x16g2000prn.googlegroups.com...
Hi all!
You know all these CString::LoadString that you probably have all over
the place in your code? It just came to me... Wouldn't it be nice to
make a cache of already-loaded strings instead of loading them every
time?
I also don't think the cache will help, but FYI Joe's site taught me
something I value a lot more: the ability to not call CString::LoadString
at all!
CString str;
str.LoadString(IDS_MY_DESIRED_STR);
printf(str);
can be replaced:
CString str(MAKEINTRESOURCE(IDS_MY_DESIRED_STR));
printf( (LPCTSTR) str);
which is further refined:
printf( (LPCTSTR) CString(MAKEINTRESOURCE(IDS_MY_DESIRED_STR)) );
which is almost as readable as a hard-coded string:
printf("My desired string");
Finally we get to the point where it is no longer necessary to replace a
1-line hard-coded string with 3 lines just to move the string into a
stringtable; the replacement code is also 1 line! Now that's what modern
programming is all about.
Although Qt has an even better way:
printf(tr("My desired string"));
The tr() macro replaces the hard-coded string with its localized equivalent,
if it exists in the active translation. It truly doesn't get any easier
than that. In a lot of ways, Qt is the framework MFC would have been, had
MS kept improving its core functionality (and not just adding controls like
ribbons). I'm liking Qt an awful lot compared to MFC, and the Dev10 preview
doesn't promise to change that much, unfortunately.
-- David