:Start of UniFontDemo
![]() | ![]() |
|---|
If you are viewing this script in your browser you can save it as a VDS 5.x source file (*.dsc) to run it.
#
# DragonSphere Software's Home Page
#
# All Source Files for this demo
#
#
# This is an example that shows how to create the
# Label Control Forms 2.0 object from the FM20.dll and place it on a VDS Dialog
# This example also shows how to use the ^S Variant type to handle
# Unicode strings. To do this you need a way to read the bytes of a wide
# character string into a variable. In this example we will use the GadgetX
# mem command/function to read into a memory buffer the bytes from the Unicode
# encoded file provided by Hooligan from VDS World. The name of the file is
# JapaneseReady.txt and has a string of Unicode text with both Japanese glif characters
# and ASCII glif characters.
#
# Warning: working with Unicode strings is not for the faint of heart.
# A good knownledge of working with memory buffers is needed
# Remember little end first and that VDS cannot directly translate a Null character
#
Title Unicode Font Demo
If @Greater(@Name(@SYSINFO(DSVER)),4)
# Load GadgetX.dll
External GadgetX.dll,@SysInfo(DSVER)
# GadgetX Commands
#DEFINE COMMAND,GADGETX,DEFINE,OLE,SET,MEM
# GadgetX Functions
#DEFINE FUNCTION,GADGETX,OLE,GET,MEM,SPACE,ADDROF,GETLASTERROR
Else
Warn This Example uses VDS 5 or above syntax.
Stop
End
OPTION ERRORTRAP,ONERROR
# The following line is required
Ole Init
# The following line is optional
# it is here for debugging your script
# Ole Exceptions,SHOW
# Define a Object for the FontDisp object
Define Variable,Object,Font
# Create our dialog with the Label control.
%%classname = #UniFontDemo
DIALOG CREATE,Unicode Font Demo,-1,0,560,212,CLASS UniFontDemo
REM *** Modified by Dialog Designer on 12/11/2006 - 22:16 ***
# Place the Label Control on the VDS Dialog
GadgetX Add,Ole,Label,%%classname,30,30,510,25,Forms.Label.1
DIALOG ADD,BUTTON,BUTTON1,178,135,64,24,Ok
DIALOG ADD,BUTTON,BUTTON2,178,345,64,24,Cancel
DIALOG SHOW
#
# Enable the Label control
Ole Set,Label,"Enabled = ^B",True
#
# Get the Label controls Font object
Set Font,@Ole(Get,Label,^o,Font)
#
# Set the font SimSun-18030
Ole Set,Font,"Name = ^B",SimSun-18030
#
# Set the size to a point size of 12
Ole Set,Font,"Size = ^E",12
#
# Set the forground color
Ole Set,Label,"ForeColor = ^d",BLUE
#
# Apply the new font to the Label object
Ole SetRef,Label,"Font = ^o",@Get(Font)
#
# Open the JapaneseReady.txt file with BINFILE OPEN in READ mode
BINFILE OPEN,1,@Path(%0)JapaneseReady.txt,READ
#
# Define a GadgetX String variable to hold the Japanese text.
Define Variable,String,Buffer
# Note: Initialize the string variable 2 bytes larger than the file size.
# The extra 2 bytes mark the end of the Unicode String
# and are double null characters @chr(0)@chr(0)
Set Buffer,@space(@BinFile(SIZE,1))@chr(0)@chr(0)
#
# Save the memory address of the String variable to a temp
# VDS variable that will be iterated.
%B = @AddrOf(Buffer)
#
# Loop until we reach the end of the file
while @not(@binfile(EOF,1))
# Read the first byte
%h = @trim(@binfile(read,1,HEX,1))
# Read the second byte
%l = @trim(@binfile(read,1,HEX,1))
# swap the bytes
%w = $%l%h
# Write both bytes to the GadgetX String variable as a WORD variable type
mem write,%B,WORD,%w
# Move the memory pointer 2 bytes ahead
%B = @sum(%B,2)
wend
# Pass the GadgetX String variable memory address of the
# Unicode string to the Caption method to set the text to the Label control
Ole Set,Label,"Caption = ^S",@AddrOf(Buffer)
# Set word wrap so the text will wrap to the controls given size not breaking words.
Ole Set,Label,"WordWrap = ^B",True
# Autosize the control. Note: I autosized it after the text is applied
Ole Set,Label,"AutoSize = ^B",True
# Close the JapaneseReady.txt File
BINFILE CLOSE,1
:evloop
Repeat
wait event
%E = @event()
If %E
GoSub %E
End
Until @Equal(%E,CLOSE)@Equal(%E,BUTTON2BUTTON)
Exit
:BUTTON1BUTTON
Info Now do something speaking Japanese
Exit
:BUTTON2BUTTON
:CLOSE
# The lines below are required to be called
# before your script exits
If @Get(Label)
# Remove the object from the Dialog
Ole Remove,Label,%%classname
# Free the Object variable
Ole Free,Object,Label
End
# The following line is optional
# it is here for debugging your script
# Ole Exceptions,HIDE
# The following line is required to be
# the very last executed line in your script
Ole UnInit
Exit
:ONERROR
%%GadgetXError = @GetLastError()
While %%GadgetXError
Info %%GadgetXError@CR()
%%GadgetXError = @GetLastError()
Wend
Info Runtime error @error(E) at line @error(N)
OPTION ERRORTRAP,
Exit
© Copyright DragonSphere Software 2000-2005
Terms and Conditions