Author Topic: Question about WinExist and Double-byte characters  (Read 4628 times)

gauthierda

  • Newbie
  • *
  • Posts: 3
Question about WinExist and Double-byte characters
« on: July 29, 2013, 09:51:26 am »
Hi,

I am wondering if the WinExist function should support double byte characters.  I'm trying to build an package that searches for a Window with a Chinese title. 

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Question about WinExist and Double-byte characters
« Reply #1 on: July 29, 2013, 10:33:14 am »
Yes WinExist should support double-byte character sets.
Deana F.
Technical Support
Wilson WindowWare Inc.

gauthierda

  • Newbie
  • *
  • Posts: 3
Re: Question about WinExist and Double-byte characters
« Reply #2 on: July 29, 2013, 10:51:44 am »
Ok, Thanks.  Now the question, how would I enter it?

"重置Internet Explorer 设置"  is what I want to enter, but if I try to cut and paste it into WinBatch Studio, I wind up with "?? Internet Explorer ??"


td

  • Tech Support
  • *****
  • Posts: 3463
    • WinBatch
Re: Question about WinExist and Double-byte characters
« Reply #3 on: July 29, 2013, 11:13:39 am »
Hi,

I am wondering if the WinExist function should support double byte characters.  I'm trying to build an package that searches for a Window with a Chinese title.

Like most WinBatch functions WinExist converts string input to Unicode UTF-16 on all currently supported systems.  By default the conversion is performed using the current system ANSI code page.  If your system happens to be set to the correct Chinese ANSI code page, the conversion will work and any existing window should be found.  However, if your system's default code page is something other than a Chinese one, you will have difficulty finding the window. 

There are two workarounds you might want to consider, if you system is not defaulted to a Chinese code page. You could try telling WinBatch to temporarily use a Chinese code page like 950 or 936 by using the ChrGetCodePage and ChrSetCodePage functions for your call to WinExist.  These code pages would need to be available on your system for this approach to work.

The other approach would be to convert the window title to Unicode before passing it to WinExist.  There are several ways to do the conversion with both the ChrHexToUnicode or BinaryConvert functions coming to mind as possible approaches but there are other techniques.  ChrHexToUnicode is probably the easiest if you can assume your window name or names is or are not going to change frequently.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3463
    • WinBatch
Re: Question about WinExist and Double-byte characters
« Reply #4 on: July 29, 2013, 11:26:24 am »
Ok, Thanks.  Now the question, how would I enter it?

"重置Internet Explorer 设置"  is what I want to enter, but if I try to cut and paste it into WinBatch Studio, I wind up with "?? Internet Explorer ??"

Right click in the WinBatch Studio window displaying your document and selection the  "Insert Unicode Text" menu option.  This will generate a call to ChrHexToUnicode for you.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Question about WinExist and Double-byte characters
« Reply #5 on: July 29, 2013, 11:46:10 am »
I should have clarified. WinBatch Studio is an Ascii editor. In order to use Unicode text in WinBatch Studio, you must call ChrHexToUnicode. WinBatch studio has simplified the process. WinBatch Studio has a completely configurable context menu accessed by clicking the right mouse button anywhere within an open file. In this instance you can use the Insert Unicode Text menu option. When prompted paste the Chinese characters into the dialog. The menu option will auto magically fill in the appropriate line of code. It will look something like this:"

Code: Winbatch
sChinese = ChrHexToUnicode("CD916E7F49006E007400650072006E006500740020004500780070006C006F007200650072002000BE8B6E7F")
ret = WinExist( sChinese )
if ret
   Pause('Notice','Window Exists')
else
   Pause('Notice','Window Does Not Exist')
endif
Deana F.
Technical Support
Wilson WindowWare Inc.

gauthierda

  • Newbie
  • *
  • Posts: 3
Re: Question about WinExist and Double-byte characters
« Reply #6 on: July 29, 2013, 12:02:29 pm »
Thanks for the help!  That looks like it will do the trick!

Dan