---------------------------------------------------------
The Liberty Basic Newsletter - Issue #53 - OCT 99
       1999, Cliff Bros and Alyce Watson
             All Rights Reserved
---------------------------------------------------------
In this issue:

Hey, I didn't know that!

Manipulating the MainWindow
Copy Any File
Resize at Startup
Hide Controls with Locate
Change the Runtime Icon
Runtimes in Windows\System
Multiple Versions of DLL Error
Associate *.BAS with Liberty.exe
Password Unnecessary!
Getbmp Failure
Bitmap Colors
LOG Notice
---------------------------------------------------------
Manipulating the MainWindow

If you make a call to GetActiveWindow before any
windows are opened in your program, AND if you do
NOT have a 'NOMAINWIN' command, you can get the handle
of the mainwindow.  If you have a 'NOMAINWIN' command,
then of course, this will not work.

GetActiveWindow, when called before other windows are
opened, will return the window handle of the 
mainwindow.  You may then use the MoveWindow api call
to change the size and location of the mainwindow.
The following sample makes the mainwindow take up
the entire display area:

'Full size mainwin
'This routine will open the mainwindow
'the full size of the display:

open "user" for dll as #user

calldll #user, "GetActiveWindow",_
mainwinhandle as short     'returns handle of mainwin

calldll #user, "MoveWindow", _
mainwinhandle as word, _   'window handle
0 as short, _              'upperleft x
0 as short, _              'upperleft y
DisplayWidth as short, _   'width
DisplayHeight as short, _  'height
1 as word, _               'repaint
result as void             'no return

Close #user

[loop]
input avar$ 


It would actually be a better idea to allow the
Win95 taskbar to show.  Instead of making a call
to MoveWindow, make the call to ShowWindow and use
the flag _SW_SHOWMAXIMIZED as in the following
example:


'Maximize mainwin
'This routine will open the mainwindow
'full size but show the win95 taskbar

open "user" for dll as #user

calldll #user, "GetActiveWindow",_
mainwinhandle as short     'returns handle of mainwin

calldll #user, "ShowWindow",_
mainwinhandle as word,_          'mainwindow handle
_SW_SHOWMAXIMIZED as ushort,_    'flag for maximize
result As word

close #user

[loop]
input avar$

---------------------------------------------------------
Copy Any File

LB will allow you to open any kind of file, not just a
text file.  This feature allows you to manipulate binary
files as well.  You may open a file for INPUT and place 
the contents of the file into a string variable.  LB allows 
you to have huge strings.  The size limit is approximately 
two million characters.  After placing the input from the 
file into a string, you should close the file.  You then
open a file in the desired location for OUTPUT and write
the string to that file, then close it.  You may move
files such as wavs, bmps and exes this way.  Here is
a little example:

open "c:\sounds\waves\explode.wav" for input as #temp
    stream$=input$(#temp, lof(#temp))
close #temp

open "d:\wavs\games\boom.wav" for output as #save
    print #save, stream$ 
close #save
---------------------------------------------------------
Resize at Startup

LB1.42 allows you to trap a user's resizing of a window
of type-window.  The new dimensions of the client area
(workspace that doesn't include the tilebar, menubar,
or frame) are contained in the variables
WindowWidth and WindowHeight.  The command
print #window, "resizehandler [branch]"
tells the program which branch label to execute when the
user resizes the window.  Controls are then relocated 
and resized accordingly with the LOCATE statment.  See
new142.txt and resize.bas for more details.  (If your
resize routine doesn't seem to be working, remember
that you need to issue a REFRESH command to the
window for the change to take effect.)

HEY!
If you have a "resizehandler" command, the program will
perform a resize routine AT STARTUP.  In the little
example here, a texteditor control is placed on the
window with the TEXTEDITOR command before the window is
opened.  It is located in the center of the window, and
is only 10 pixels wide and 10 pixels high.  If you run
the code, you will see that the text editor actually
appears at spot 0,0, and fills the client area, because
the resizer changed the size and location at startup.

nomainwin
texteditor #1.t, 100, 100, 10, 10
open "Resize" for window as #1
print #1, "resizehandler [resizeit]"

[loop]
input aVar$

[resizeit]
w=WindowWidth
h=WindowHeight
print #1.t, "!locate 0 0 ";w;" ";h
print #1, "refresh"
goto [loop]
---------------------------------------------------------
Hide Controls with Locate

You may use API calls to hide controls, but you can do it
much more easily with the LB LOCATE statment.  Cut and
paste this little example into Liberty BASIC and run it.
When you click the button, it will disappear, because it
has been given a new width and height of 0 pixels.  If you
wanted to show the button again, you would issue a
command that gives a proper value for the width and
height of the control.  Click the Show It! button to
display the hidden button.

nomainwin
button #1.h, "Hide Me!",[hideme],UL,10,50,100,26
button #1.s, "Show It!",[showit],UL,10,80,100,26
open "Hide Control" for window as #1

[loop]
input aVar$

[hideme]
print #1.h, "!locate 10 50 0 0"
print #1, "refresh"
goto [loop]

[showit]
print #1.h, "!locate 10 50 100 26"
print #1, "refresh"
goto [loop]
---------------------------------------------------------
Change the Runtime Icon

You may change the icon contained in the runtime engine
for your programs.  The runtime engine will be a renamed
version of run.exe.  There is source code available at
the Liberty BASIC Network site that allows you to do this
easily, with no changes to your operating system.  If you
choose to change the runtime icon by using that feature
in the Liberty BASIC Editor's Setup menu, you must first
set your display resolution to 16 colors.  This will require
rebooting your system.  Change the runtime icon, and then
you may reset your display to the color resolution of your
choice.

No matter which method you use to change a runtime icon,
the icon itself must be in 16-color format.
---------------------------------------------------------
Runtimes in Windows\System

If you place the following runtime modules in your
Windows\System directory, you do not need copies of them
anywhere else on your system!  This can save a lot of hard
disk space, if you have a lot of Liberty BASIC programs
on you system.  Applications look for DLL's first in the 
Windows\System directory.

  VWVM11.DLL
  VWBAS11.DLL
  VWSIGNON.DLL
  VWSIGNON.BMP 
  VWFONT.DLL
  VWFLOAT.DLL
  VWABORT.DLL
  VWDLGS.DLL
---------------------------------------------------------
Multiple Versions of DLL Error

You may get a DLL call error for a suprising reason.
If you have an older version of a DLL in Windows\System 
and a newer version in your program's directory, your
program will use the older version of the DLL!  This is
because it looks first in the Windows\System directory for 
a DLL, even before it looks in the program's default directory.
Be sure to remove all old versions of a DLL, especially any
that are in Windows\System, before you try to use a newer
version.  This error can happen when the newer version of a
DLL contains a function that is not contained in the older
version.  When a program tries to call that function, you
will generate and error that crashes the program.
---------------------------------------------------------
Password Unnecessary!

If you have the latest version of Liberty BASIC, which is
version 1.42, you no longer need to place your password
in code before tokenizing.  Instead, you should register
your version by using the "Enter registration code"
function on the SETUP menu.  You will be prompted for your
user name and your password.  Once you have entered your 
runtime password, your name should appear on the Liberty
BASIC Editor's titlebar.  After performing this registration
function in the LB editor, your password need not be inserted
into code before tokenizing.  It is done automatically.
---------------------------------------------------------
Associate *.BAS with Liberty.exe

If you associate the extension BAS with Liberty.exe, then
clicking on a file with the BAS extension will cause
Liberty BASIC to run, and to load the file you have chosen.
You can associate a file type with an application in Windows
95+ by using Windows Explorer, and opening the VIEW menu.
Choose OPTIONS.  When the options dialog opens, click on the
File Types tab.  If BAS is already listed in the Types
listbox, click on it and choose EDIT.  Change the OPEN 
operation so that Liberty.exe is associated with the type
BAS.  If BAS is not contained in the listbox, click on the
New Type button and fill in the fields in the New Type
dialog box.  Click the NEW button.  You will be prompted
for the action, which should be entered as OPEN.  You can
then type in the path to Liberty.exe, or click the BROWSE
button to find it.  Once you have completed this operation,
you can click on any BAS file in Windows Explorer or My
Computer and it will run in Liberty BASIC.  You may even
create a shortcut to your often-used LB files and place
the shortcut on your desktop.  When the shortcut is clicked,
Liberty BASIC will run, with the file loaded.
---------------------------------------------------------
Getbmp Failure

The GETBMP command creates a bitmap in memory from the
coordinates you give to the command, and with the width
and height you specify.  You can then use DRAWBMP to
place this bitmap on another part of the window, or
to redraw this section of graphics.  Using this
command causes an error and program crash if the system
in use has a display resolution greater than 24-bit color.
Some video drivers allow for 32-bit color, so it is a
good idea to check for this in programs that use GETBMP.
You must either GetDC for the graphics window or graphicbox,
or CreateDC for the display.  Then use a call to
GetDeviceCaps, using the parameter _BITSPIXEL to retrieve
the display color resolution in use.  If the function
returns a value that is greater than 24, you should not
use GETBMP in the program.  Here are two examples:

'first example:
open "gdi" for dll as #gdi
  calldll #gdi, "CreateDC",_
  "DISPLAY" as ptr,_
  "" as ptr,_
  "" as ptr,_
  "" as ptr,_
  hDC as word

calldll #gdi, "GetDeviceCaps", _
  hDC as word, _
  _BITSPIXEL as word, _
  capReturn as word

calldll #gdi, "DeleteDC",_
  hDC as word,_
  results as void

close #gdi

  PRINT capReturn;
  Print "-bit color resolution."
  print
    if capReturn>24 then
        print "You cannot use GETBMP on this system."
    else
        print "You can use GETBMP on this system."
    end if
END

'second example:
nomainwin

open "Color Res" for graphics as #g
h=hwnd(#g)

open "gdi" for dll as #gdi
open "user" for dll as #user

calldll #user, "GetDC",h as word,hDC as word

calldll #gdi, "GetDeviceCaps", _
  hDC as word, _
  _BITSPIXEL as word, _
  capReturn as word

calldll #user, "ReleaseDC",_
  h as word,_
  hDC as word,_
  results as void

close #gdi
close #user

if capReturn<24 then
    print #g, "down;fill green"
    print #g, "GETBMP bname 12 3 50 25"
    print #g, "CLS"
    print #g, "DRAWBMP bname 50 70"
else
    print #g, "down;color green"
    print #g, "backcolor green"
    print #g, "place 50 70"
    print #g, "boxfilled 100 95"
end if

input a$
---------------------------------------------------------
Bitmap Colors

LB 1.42 will not load bitmaps whose format is greater than
256 colors.  This color limitation does not refer to the
number of distinct colors that actually appear in a bitmap,
but to the format of the bitmap file.  If you try to load
a bitmap that is formatted to more than 256 colors, the
program will crash.  Trap that possibility by opening
the file and determining the number of colors before
you attempt to load the bitmap.  Here's how:

filedialog "Open Bitmap", "*.bmp", picFile$
if picFile$ = "" then [inputLoop]
open picFile$ for input as #pic
pic$=input$(#pic,29)
close #pic
picDepth=asc(right$(pic$,1))
picCols=2^picDepth

if picCols > 256 then
    notice "Error, bitmap format is more than 256 colors."
    goto [loop]
else
    loadbmp "tempPicture", picFile$ 
end if
---------------------------------------------------------
LOG Notice

The LOG(x) function returns the NATURAL Log of x.  It does
NOT return the base 10 Log of x.

---------------------------------------------------------
Newsletter compiled and edited by: Brosco and Alyce.
Comments, requests or corrections: Hit 'REPLY' now!
mailto:brosco@orac.net.au or mailto:awatson@mail.wctc.net
---------------------------------------------------------