﻿;----< see the UTF-8 byte order mark in an ordinary text editor
;------------------------------------------------------------------
;
;      HelloUnicode2 - copyright Jeremy Gordon 2004
;
;      SIMPLE UNICODE PROGRAM DISPLAYING UNICODE CHARACTERS
;      in various languages in a modal dialog box 
;      and then in a MessageBox
;      The modal dialog box is made using a template in data
;      instead of the usual resource file
;
;      Important! View this file using Internet Explorer, help
;      or a Unicode editor (copy and paste it into the editor).
;
;      This program does not work on Windows 9x or ME, because
;      DialogBoxIndirectParamW is not available on that platform.
;
;      Assemble using GoAsm HelloUnicode2 
;      This produces a PE COFF file.
;      Then link using:-
;      GoLink HelloUnicode2.obj kernel32.dll user32.dll gdi32.dll
;      (add /debug coff if you want to watch the program in the debugger)
;
;------------------------------------------------------------------
;
;*******************************************************************
;
DATA SECTION
;
ALIGN 4         ;just to emphasise this must be dword aligned
;*********************** here is the dialog template for the dialog
DIALOG_TEMPLATE DD 10000000h |0C00000h  |800h     |40h|  \
                   80h          |80000h    +20000h
            ;style WS_VISIBLE+WS_CAPTION+DS_CENTER+DS_SETFONT
            ;      DS_MODALFRAME+WS_SYSMENU+WS_MINIMIZEBOX
             DD 0                 ;extended style
             DW 6                 ;no. items in dialog box
             DW 0D                ;top left x position
             DW 0D                ;top left y position
             DW 160D              ;box width
             DW 128D              ;box height
             DW 0                 ;menu array (no menu)
             DW 0                 ;class array (use default)
             DUS 'HelloUnicode2 demonstration',0   ;title
             DW 10                ;font point size
             DUS 'Microsoft Sans Serif',0
            ;we know (from experimentation) that this font
            ;can display the characters we have in this file
            ;note that the string must be as here -
            ;and "MS Sans Serif" is wrong
;*********************************** make a box for the following group
ALIGN 4         ;must be dword aligned
DD 50000000h          +7h
;(WS_CHILD+WS_VISIBLE)+BS_GROUPBOX
DD 0           ;extended style
DW 6           ;control top left x position
DW 6           ;control top left y position
DW 148         ;control width
DW 116         ;control height
DW 0           ;control identifier
DW -1          ;look at next for class
DW 80h         ;button control
DUS 'Unicode strings drawn with MS Sans Serif',0
DW 0           ;elements to send to DlgProc
;*********************************** next control
ALIGN 4         ;must be dword aligned
DD 50000000h          
;(WS_CHILD+WS_VISIBLE)
DD 0           ;extended style
DW 10          ;control top left x position
DW 23          ;control top left y position
DW 140         ;control width
DW 10          ;control height
DW 1h          ;control identifier
DW -1          ;look at next for class
DW 82h         ;static control
DUS 'Здравствуй Мир (Russian)',0  
DW 0           ;elements to send to DlgProc
;*********************************** next control
ALIGN 4         ;must be dword aligned
DD 50000000h
;(WS_CHILD+WS_VISIBLE)
DD 0           ;extended style
DW 10          ;control top left x position
DW 43          ;control top left y position
DW 140         ;control width
DW 10          ;control height
DW 2h          ;control identifier
DW -1          ;look at next for class
DW 82h         ;static control
DUS 'Καλημέρα κόσμε (Greek)',0
DW 0           ;elements to send to DlgProc
;*********************************** next control
ALIGN 4         ;must be dword aligned
DD 50000000h
;(WS_CHILD+WS_VISIBLE)
DD 0           ;extended style
DW 10          ;control top left x position
DW 63          ;control top left y position
DW 140         ;control width
DW 10          ;control height
DW 3h          ;control identifier
DW -1          ;look at next for class
DW 82h         ;static control
DUS 'הטקסט הבא יהיה מודגש (Hebrew)',0
DW 0           ;elements to send to DlgProc
;*********************************** next control
ALIGN 4         ;must be dword aligned
DD 50000000h
;(WS_CHILD+WS_VISIBLE)
DD 0           ;extended style
DW 10D         ;control top left x position
DW 83          ;control top left y position
DW 140         ;control width
DW 10          ;control height
DW 4h          ;control identifier
DW -1          ;look at next for class
DW 82h         ;static control
DUS '!ﻢﻟﺎﻌﻟﺎﺑ ًﻼﻫﺃ (Arabic)',0
DW 0           ;elements to send to DlgProc
;*********************************** next control
ALIGN 4         ;must be dword aligned
DD 50000000h
;(WS_CHILD+WS_VISIBLE)
DD 0           ;extended style
DW 10D         ;control top left x position
DW 103         ;control top left y position
DW 140         ;control width
DW 10          ;control height
DW 4h          ;control identifier
DW -1          ;look at next for class
DW 82h         ;static control
DUS 'ให้แสดงข้อความว่า (Thai)',0
DW 0           ;elements to send to DlgProc
;
ALIGN 4
VARIOUS_STRINGS DUS 'Здравствуй Мир (Russian)',0Dh,0Ah
		DUS 'Καλημέρα κόσμε (Greek)',0Dh,0Ah
		DUS 'הטקסט הבא יהיה מודגש (Hebrew)',0Dh,0Ah
		DUS '!ﻢﻟﺎﻌﻟﺎﺑ ًﻼﻫﺃ (Arabic)',0Dh,0Ah
		DUS 'ให้แสดงข้อความว่า (Thai)',0Dh,0Ah,0
;
OSVERSIONINFO DD 148        ;size of this simple structure
              DB 144 DUP 0  ;and remainder of the structure
;*******************************************************************
;*  CODE
;*******************************************************************
CODE SECTION
;
;***************************************************** PROGRAM START
START:
;************************ first, be polite to Windows 9x and ME users
MOV ESI,ADDR OSVERSIONINFO      ;simple structure for GetVersionExA
PUSH ESI
CALL GetVersionExA      ;Unicode version of the API not available under W9x/ME
CMP D[ESI+10h],1        ;see from platform id if NT,2000,XP and above
JA >L2                  ;yes so proceed
;************************ no its W95/98/ME ..
PUSH 40h                ;information + ok button
PUSH 'HelloUnicode2'
PUSH 'Sorry this program cannot run on your Windows platform'
PUSH 0                  ;make it child of desktop
CALL MessageBoxW        ;wait till ok pressed
JMP >L4                 ;and finish
L2:
PUSH 0
CALL GetModuleHandleW   ;get handle to this process in eax
;****************************** now create the dialog box
PUSH 0                  ;initialisation value
PUSH ADDR DlgProc       ;pointer to dialog procedure
PUSH 0                  ;this dialog has desktop as parent
PUSH ADDR DIALOG_TEMPLATE      ;template in the file itself
PUSH EAX                ;handle to this process
CALL DialogBoxIndirectParamW   ;this does not return until dialog closed
L4:
PUSH 0                  ;exit code zero
CALL ExitProcess
;
;******************************************************* DIALOG PROCEDURE
DlgProc FRAME hDlg,uMsg,wParam,lParam
USES EBX,EDI,ESI        ;safety only
MOV EAX,[uMsg]          ;get message
CMP EAX,110h            ;see if WM_INITDIALOG
JZ >.return             ;return eax=non-zero as required
CMP EAX,111h            ;see if WM_COMMAND
JNZ >.false             ;no
CMP W[wParam],2h        ;see if sysmenu was clicked
JNZ >.false             ;no
;*********************** yes so say goodbye in a MessageBox
PUSH 40h		;information and ok button
PUSH 'GoodbyeUnicode2'  ;title
PUSH ADDR VARIOUS_STRINGS	;main body text
PUSH [hDlg]		;owner (this dialog)
CALL MessageBoxW
;****************************** 
PUSH 1,[hDlg]
CALL EndDialog          ;end the dialog
.false
XOR EAX,EAX             ;return zero as required
.return
RET
ENDF
