ANSI / Unicode applications (Only Visual Project Type)
From version 1.04.0.0001
Easy Code Masm visual
projects can built ANSI or Unicode applications in a very easy way. To
switch between
ANSI and Unicode mode, just check/uncheck the Build
project as Unicode (Windows NT
or later) option in the Project
Properties.
If that
option is checked, the built application will be Unicode,
otherwise it will be
ANSI
(default).
For maintaining compatibilty with all Windows platforms, Unicode
applications built in
the Easy Code Masm
visual mode will dynamically switch to ANSI when running on
Windows 95/98/ME. On the other hand, applications not built as Unicode
(that is, having
the Build project as Unicode
option unchecked) will always be ANSI although they run on
Windows NT or later systems. For you to know how an application
is running on, Easy Code defines the APP_UNICODE
constant ONLY if the
the application is running as Unicode.
If you prefer, you can call the IsAppUnicode
method, which returns
TRUE
or FALSE
depending on whether the application is running as Unicode
or not. That way, you can prepare an
application to work fine in all Windows versions. To do so,
just take care of using the
appropiate functions and messages when they are related to
text, and passing the text strings in the right format.
WARNING: All this functionality just applies to
visual projects. However, the APP_UNICODE
constant
can still be used for classics projects by selecting/unselecting
this option.
In order to support this new format,
the new TextAddrW macro for
Unicode
text has been included, and from version 1.05.0.0002
there is a new macro, TextStr,
which automatically returns text in ANSI or Unicode format,
depending on whether the Build
project as Unicode (Windows
NT or later) option is checked
or not. Also, all Easy
Code Masm methods
using text strings have been
improved by adding their corresponding ANSI and Unicode versions. For
example, the SetText
method has been complemented
with SetTextA
and SetTextW.
The SetText
method automatically calls the ANSI or Unicode version
depending on which platform of Windows it is running on and whether the
application was
built as Unicode or not, while SetTextA
and SetTextW
always call, respectively, the ANSI and Unicode version
of the method (see Easy
Code Masm methods). That way,
you can
mix ANSI and Unicode text in the same application. Let's see some
sample code (where hWnd
is the handle to the object which text is to be set):
IFDEF APP_UNICODE
Mov Eax, TextAddrW("Hello") ;Unicode mode
ELSE
Mov Eax, TextAddr("Hello") ;ANSI mode
ENDIF
Invoke SetText, hWnd, Eax
Invoke SetTextA, hWnd, TextAddr("Hello")
Invoke IsAppUnicode
.If Eax
Invoke SetWindowTextW, hWnd, TextAddrW("Hello") ;Unicode mode
.Else
Invoke SetWindowTextA, hWnd, TextAddr("Hello") ;ANSI mode
.EndIf
Invoke IsAppUnicode
.If Eax
Mov Edx, TextAddrW("Hello") ;Unicode mode
Mov Eax, SetWindowTextW
.Else
Mov Edx, TextAddr("Hello") ;ANSI mode
Mov Eax, SetWindowTextA
.EndIf
Push Edx
Push hWnd
Call Eax
Mov Eax, TextStr("Hello")
Invoke SetText, hWnd, Eax
WARNING:
As said before, all file names
and paths related to projects are always
managed as ANSI text. When
Easy Code runs in Unicode mode (that is, on Windows NT or later) the
dialog
box for opening and saving files is also a Unicode window. However,
once a
file is selected, its path and name are always converted to ANSI for
compatibility
reasons, so please take that into account when selecting folders or
naming objects and
files for your projects.
REMARKS: Although all names for projects, fonts, windows and controls are always ANSI names, methods retrieving or setting those names (i.e. GetFontName and SetFontName) will expect and return Unicode strings if the application is running as Unicode. On the other hand, when calling the Create method for creating a window, you can pass its name (first parameter) both, with an ANSI or a Unicode string.
IMPORTANT:
The code
editor
ALWAYS
works in ANSI mode and it ALWAYS
needs an ANSI fixed-pitch font in order to
properly work.