 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mike Collins Guest
|
Posted: Tue Apr 10, 2007 3:07 pm Post subject: Storing UNICODE in mixed string resource |
|
|
Hi all, hope everyone had a good Easter break.
Got an on running problem and still having issues resolving it. I posted a
few months back but didn't seem to resolve the issue. The background to the
problem is that i HAVE to identify an dialog by it's caption. We have a
convoluted system which is too far down the development path to change. The
system needs to close a particular dialog box created by a MS dll. The
Windows class name is not sufficient to identify the dialog (#32770) and so
I have to enumerate all windows looking for a particular caption. This
system works fine until the software is deployed on non-English platforms,
where the caption changes according to the language being used. After
searching MSDN, we have found that there are approximately 26 core languages
that are supported by MS and which cause the caption to change. So far, we
have got all of the roman-based ANSI versions and copied there captions into
a resource file. The software basically gets the system local and then
looks up the corrisponding caption for comparission. Again, this works
fine, our enum call-back looks like this:
BOOL CALLBACK Main::EnumWinProc(HWND hWnd, long lParam)
{
char cCaption[255], cClassID[255];
GetWindowText(hWnd, cCaption, sizeof(&cCaption));
GetClassName(hWnd, cClassID, sizeof(&cClassID));
AnsiString sStoredCaption;
// Load caption from string table resource based on system local
if ((strcmp(cClassID, "#32770")==0)
&&(strcmp(cCaption, sStoredCaption.c_str())==0))
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
return FALSE;
}
else
return TRUE;
}
The problem that I'm having now is dealing with platforms that use
non-roman, Unicode strings i.e. Hebrew and Russian. On these systems, i can
get the caption but i seem unable to store it in my string table along side
the other ANSI captions (I get a resource compile error).
My first question is, how can i store these string in my string resource?
Do i need to convert them to escape characters first?
My second question is, how do i modify the above call-back so that it can
work with either UNI or ANSI without having to compile separate versions -
I'm trying to make something generic that will work seamlessly on both
platforms.
I hope this makes sense,
Many thanks in advance,
Mike Collins |
|
| Back to top |
|
 |
poojo hackma Guest
|
Posted: Tue Apr 10, 2007 6:37 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
Hi Mike,
Have you tried using TCHAR instead of the familiar "char" and LPTSTR instead
of LPSTR or "char*"?
Both TCHAR and LPTSTR can handle either a char or a wchar, depending on the
way the project is compiled. Not sure if that will solve your problem, but
we've started using that in all of our code to reduce possible problems down
the road.
As for easy "escape characters" to convert from ANSI to UNICODE, I asked
this some time back and was told that there really isn't a good one-to-one
conversion for it.
If you must play with something, the closest functions you are going to find
are WideCharToMultiByte and MultiByteToWideChar, but they don't work all the
time.
HTH,
~Joe |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Tue Apr 10, 2007 8:31 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
Mike Collins wrote:
| Quote: | So far, we have got all of the roman-based ANSI versions and
copied there captions into a resource file.
The problem that I'm having now is dealing with platforms that use
non-roman, Unicode strings i.e. Hebrew and Russian.
|
How about +always+ using Wide chars?
Then you just have to have all your caption resources as wide strings.
| Quote: | char cCaption[255], cClassID[255];
|
wchar_t wcCaption[255];
char cClassID[255];
| Quote: | GetWindowText(hWnd, cCaption, sizeof(&cCaption));
|
GetWindowTextW( hWnd, wcCaption, sizeof(&wcCaption) );
| Quote: | GetClassName(hWnd, cClassID, sizeof(&cClassID));
|
GetClassNameA( hWnd, cClassID, sizeof(&cClassID) );
| Quote: | AnsiString sStoredCaption;
|
WideString wsStoredCaption;
| Quote: | // Load caption from string table resource based on system local
if ((strcmp(cClassID, "#32770")==0)
&&(strcmp(cCaption, sStoredCaption.c_str())==0))
|
if ((strcmp(cClassID, "#32770")==0)
&&( lstrcmpW( wcCaption, wsStoredCaption.c_str())==0)) |
|
| Back to top |
|
 |
JF Jolin Guest
|
Posted: Tue Apr 10, 2007 8:35 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
In addition to what poojo have said
Here are some precisions with UNICODE vs MBCS
http://www.codeproject.com/cpp/unicode.asp
10 Apr 2007 06:07:59 -0400, Mike Collins <its@TheBottomOfThePost> wrote:
| Quote: | My first question is, how can i store these string in my string resource?
|
; String table
STRINGTABLE
BEGIN
#ifdef _UNICODE
IDS_FOLDER L"C:\\WINDOWS" // UNICODE string
#else
IDS_FOLDER "C:\\WINDOWS" // MBCS string
#endif
END
| Quote: | My second question is, how do i modify the above call-back so that it can
work with either UNI or ANSI without having to compile separate versions -
I'm trying to make something generic that will work seamlessly on both
platforms.
|
#include <tchar.h>
BOOL CALLBACK Main::EnumWinProc(HWND hWnd, long lParam)
{
TCHAR cCaption[255], cClassID[255];
GetWindowText(hWnd, cCaption, sizeof(&cCaption)/sizeof(TCHAR));
GetClassName(hWnd, cClassID, sizeof(&cClassID)/sizeof(TCHAR));
AnsiString sStoredCaption;
// Load caption from string table resource based on system local
if ((_tcscmp(cClassID, TEXT("#32770"))==0)
&&(_tcscmp(cCaption, sStoredCaption.c_str())==0))
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
return FALSE;
}
else
return TRUE;
}
For compilation with UNICODE
Use the compiler switch -tWU
or make use of #define _UNICODE
Good day
__
JF Jolin |
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Tue Apr 10, 2007 9:07 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
Mike Collins wrote:
| Quote: | Thanks bob, thats pretty much as i though i.e. us the W api calls. But how
do i store the captions in resource file.
|
See JF Jolin's answer:
IDS_FOLDER L"C:\\WINDOWS" // UNICODE string
| Quote: | At the minute, if i paste a UNICODE caption into my resource stringtable
|
How are you doing that?
| Quote: | i get a compile error.
|
Such as?
| Quote: | Do i need to conver the UNICODE values into escape values first and then paste
them into the resource. I believe i have a linux utility that will do this
for me...
|
Looks like you do need to do that. See example
IDS_RUSSIANSTRING L"\x0421\x043f\x0440\x0430\x0432\x043a\x0430"
http://msdn2.microsoft.com/en-us/library/aa381050.aspx |
|
| Back to top |
|
 |
Mike Collins Guest
|
Posted: Tue Apr 10, 2007 9:59 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
Thanks bob, thats pretty much as i though i.e. us the W api calls. But how
do i store the captions in resource file. At the minute, if i paste a
UNICODE caption into my resource stringtable i get a compile error. Do i
need to conver the UNICODE values into escape values first and then paste
them into the resource. I believe i have a linux utility that will do this
for me...
"Bob Gonder" <notbg (AT) notmindspring (DOT) invalid> wrote in message
news:ns8n13toikgnmrtth262dtekr5qfj8daoo (AT) 4ax (DOT) com...
| Quote: | Mike Collins wrote:
So far, we have got all of the roman-based ANSI versions and
copied there captions into a resource file.
The problem that I'm having now is dealing with platforms that use
non-roman, Unicode strings i.e. Hebrew and Russian.
How about +always+ using Wide chars?
Then you just have to have all your caption resources as wide strings.
|
|
|
| Back to top |
|
 |
Mike Collins Guest
|
Posted: Tue Apr 10, 2007 11:12 pm Post subject: Re: Storing UNICODE in mixed string resource |
|
|
Bingo - thats what i was looking for.
I need to convert to escape characters and then preceed it with an L, there
after, i should be able to interchange between the wide string and ansi
string accordingly.
Thanks for the help
Mike
"Bob Gonder" <notbg (AT) notmindspring (DOT) invalid> wrote in message
news:42cn13dg2ujt0n9qvmi28fkd28oqbq2482 (AT) 4ax (DOT) com...
| Quote: | Mike Collins wrote:
Thanks bob, thats pretty much as i though i.e. us the W api calls. But
how |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|