🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by Mike Collins Tue, 10 Apr 2007 10:07
Storing UNICODE in mixed string resource
#2129
Author: Mike Collins
Date: Tue, 10 Apr 2007 10:07
54 lines
3285 bytes
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 
Re: Storing UNICODE in mixed string resource
#2130
Author: poojo hackma
Date: Tue, 10 Apr 2007 13:37
20 lines
1739 bytes
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 
Re: Storing UNICODE in mixed string resource
#2132
Author: Bob Gonder
Date: Tue, 10 Apr 2007 15:31
34 lines
2027 bytes
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.

>   char cCaption[255], cClassID[255];

	wchar_t	wcCaption[255];
	char	cClassID[255];

>   GetWindowText(hWnd, cCaption, sizeof(&cCaption));

	GetWindowTextW( hWnd, wcCaption, sizeof(&wcCaption) );

>   GetClassName(hWnd, cClassID, sizeof(&cClassID));

	GetClassNameA( hWnd, cClassID, sizeof(&cClassID) );

>   AnsiString sStoredCaption;

	WideString  wsStoredCaption;

>   // 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))
Re: Storing UNICODE in mixed string resource
#2133
Author: JF Jolin
Date: Tue, 10 Apr 2007 15:35
64 lines
2405 bytes
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:

> 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


> 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
Re: Storing UNICODE in mixed string resource
#2134
Author: Bob Gonder
Date: Tue, 10 Apr 2007 16:07
25 lines
1827 bytes
Mike Collins wrote:

>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

>  At the minute, if i paste a UNICODE caption into my resource stringtable

How are you doing that?

> i get a compile error.

Such as?

>  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
Re: Storing UNICODE in mixed string resource
#2131
Author: Mike Collins
Date: Tue, 10 Apr 2007 16:59
20 lines
1890 bytes
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@notmindspring.invalid> wrote in message 
news:ns8n13toikgnmrtth262dtekr5qfj8daoo@4ax.com...
> 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.
>
Re: Storing UNICODE in mixed string resource
#2135
Author: Mike Collins
Date: Tue, 10 Apr 2007 18:12
16 lines
1594 bytes
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@notmindspring.invalid> wrote in message 
news:42cn13dg2ujt0n9qvmi28fkd28oqbq2482@4ax.com...
> Mike Collins wrote:
>
>>Thanks bob, thats pretty much as i though i.e. us the W api calls.  But 
>>how
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads