Liberty Basic is develeopped by Carl Gundel
Original Newsletter compiled by Alyce Watson and Brosco
Translation to HTML: Raymond Roumeas

The Liberty Basic Newsletter - Issue #74 - JUN 2000

© 2000, Side by Side Software

http://alyce.50megs.com/sss/

All Rights Reserved


In this issue:

  1. Add subs to branch label finder in editor
  2. Comboboxes
  3. Write a code library
  4. Access code library in open source editor
  5. Launch email client and browser URL
  6. ShellExecute
  7. WinExec
  8. FindExecutable
  9. Documentation

In future issues:


"I never looked at the consequences of missing a big shot... when you think about the consequences you always think of a negative result."

- Michael Jordan

1 - ADD SUBS TO BRANCH LABEL FINDER

Now that Liberty BASIC 2 allows us to have SUBs as well as FUNCTIONS, we should add the ability to find them within code contained in the open source editor. We are already checking lines of code for the "[" character that defines a branch label, and for the word, "FUNCTION" which defines the start of a function routine. All we need to do is add a check for lines that begin with the word, "SUB".

if lower$(left$(trim$(line$),8))="sub" then
    branch$(bx)=trim$(line$)
    bx=bx+1
end if


2 - COMBOBOXES

Liberty BASIC 2 now gives us the ability to place any text string, either a literal or variable, into the textbox portion of a combobox. Previously, we could only display an item from the combobox array in this field. Here is the syntax; don't forget to start the string with a "!" character:

print #main.combo, "!Display some text!"

OR

text$ = "Display some text!"
print #main.combo, "!";text$

A user can type into the text field of a combobox and it is now possible to retrieve this user input with a "contents?" command:

print #main.combo, "contents?"
input #main.combo, text$
notice text$


MORE ABOUT COMBOBOXES

If a combobox has the input focus, keystrokes are entered into the textfield. As characters are entered, the combobox list will scroll to locate the entry that matches the string entered, alphabetically. This feature makes comboboxes superior to listboxes for some applications. To take advantage of this, we will change the listbox in the Branch Label search window of the open source editor to a combobox.

    combobox #2.branch, branch$(, [branch],10, 10, 300,380

To take advantage of the scrolling ability, the combobox must be in the dropped-down position. This is actually quite easy to do. It requires that we retrieve the Windows handle of the combobx so that we can call the SendMessage function:

hBranch=hwnd(#2.branch)

The message we want to send to the combobox is _CB_SHOWDROPDOWN, whose decimal value is equal to 1039. Windows constants that begin with "CB" are combobox messages. The "repaint" parameter must be 1, or the change will not be displayed and the combobox will not appear in the dropped-down position.

    calldll #user, "SendMessage",_
        hBranch as word,_   'handle of combobox
        _CB_SHOWDROPDOWN as word, _ 'message to send
        1 as word,_         'repaint flag=yes
        0 as long,_         'always 0
        re as long

Or, with decimal value for message:

    calldll #user, "SendMessage",_
        hBranch as word,_   'handle of combobox
        1039 as word, _     'message to send
        1 as word,_         'repaint flag=yes
        0 as long,_         'always 0
        re as long


3 - WRITE A CODE LIBRARY

We will use a FUNCTION that Cameron Arnott has written to begin a code library. He has provided a very useful LB version of the Windows function that retrieves the color of a system attribute, such as the button color, titlebar color, and so on. He returns the color in LB syntax, getting the respective RED, GREEN, and BLUE color values from the long integer color value that is returned by the API call to GetSysColor.

We'll use this function to start a text file that contains a library of functions, which can be used with the open source editor. We must check if the library file exists before attempting to create it. If the file already exists, we don't need to create it. A file opened for output has its previous contents erased, so we also need to guard against opening an existing file and removing the data!

[make.lib]'if library file exists, do not continue this routine!
    if FileExist(DefaultDir$,"\codelibr.txt")>0 then RETURN

If the file does not exist, we open it for output:

    open "codelibr.txt" for output as #clib

We print lines to the text file with the PRINT command. We must NOT put a semicolon after our print commands, or we will lose the carriage returns that define the lines. Here is the function as Cameron wrote it, being printed to the created text file:

    print #clib, ">function GetSysColor$(Item)"
    print #clib, "'"
    print #clib, "'Cameron Arnott"
    print #clib, "'blue_steel@globalfreeway.com.au"
    print #clib, "'"
    print #clib, "' Gets the system color for the Windows area referred to by"
    print #clib, "' nIndex.  It returns the color value of that area.  Handy"
    print #clib, "' for setting the system colors back at the end of a program"
    print #clib, "' in which you have changed them."
    print #clib, "'  We use the Windows constants eg: COLOR_MENU,"
    print #clib, "' but of course LB requires that Windows constants"
    print #clib, "' be preceeded by an underscore character IE: _COLOR_MENU"
    print #clib, "'"
    print #clib, "'["
    print #clib, "variable$ = GetSysColor$(Item)"
    print #clib, "']"
    print #clib, "'{"
    print #clib, "function GetSysColor$(Item)"
    print #clib, "'"
    print #clib, "' WHERE Item is one of the following"
    print #clib, "' Windows Constant _COLOR_SCROLLBAR = 0"
    print #clib, "' Windows Constant _COLOR_BACKGROUND = 1"
    print #clib, "' Windows Constant _COLOR_ACTIVECAPTION = 2"
    print #clib, "' Windows Constant _COLOR_INACTIVECAPTION = 3"
    print #clib, "' Windows Constant _COLOR_MENU = 4"
    print #clib, "' Windows Constant _COLOR_WINDOW = 5"
    print #clib, "' Windows Constant _COLOR_WINDOWFRAME = 6"
    print #clib, "' Windows Constant _COLOR_MENUTEXT = 7"
    print #clib, "' Windows Constant _COLOR_WINDOWTEXT = 8"
    print #clib, "' Windows Constant _COLOR_CAPTIONTEXT = 9"
    print #clib, "' Windows Constant _COLOR_ACTIVEBORDER = 10"
    print #clib, "' Windows Constant _COLOR_INACTIVEBORDER  = 11"
    print #clib, "' Windows Constant _COLOR_APPWORKSPACE  = 12"
    print #clib, "' Windows Constant _COLOR_HIGHLIGHT = 13"
    print #clib, "' Windows Constant _COLOR_HIGHLIGHTTEXT = 14"
    print #clib, "' Windows Constant _COLOR_BTNFACE = 15"
    print #clib, "' Windows Constant _COLOR_BTNSHADOW = 16"
    print #clib, "' Windows Constant _COLOR_GRAYTEXT = 17"
    print #clib, "' Windows Constant _COLOR_BTNTEXT = 18"
    print #clib, "' Windows Constant _COLOR_ENDCOLORS = _COLOR_BTNTEXT"
    print #clib, "'"
    print #clib, "    open "+chr$(34)+"user"+chr$(34)+" for dll as #user"
    print #clib, "        calldll #user, "+chr$(34)+"GetSysColor"+chr$(34)+",_"
    print #clib, "        Item as word,_"
    print #clib, "        ItemColor as long"
    print #clib, "    close #user"
    print #clib, ""
    print #clib, "' ** RETRIEVE VALUES FOR red, green, blue"
    print #clib, "    blue  = int(ItemColor / (256 * 256))"
    print #clib, "    green = int((ItemColor - blue *256*256) / 256)"
    print #clib, "    red   = ItemColor - blue *256 * 256 - green * 256"
    print #clib, ""
    print #clib, "    GetSysColor$="+chr$(34)+"color
"+chr$(34)+";red;"+chr$(34)+" "+chr$(34)+";green;"+chr$(34)+" "+chr$(34)+
";blue"
    print #clib, ""
    print #clib, "end function"
    print #clib, "'"
    print #clib, "'}"
    close #clib
    RETURN

 

WATCH OUT!

The PRINT command recognizes the beginning and end of a literal string of text by the double quote mark character. We can't print a double quote mark character as such into the text file. We can do it if we substitute the ASCII value for the double quote mark, which is CHR$(34).

print #clib, "    open "+chr$(34)+"user"+chr$(34)+" for dll as #user"
print #clib, "        calldll #user,  "+chr$(34)+"GetSysColor"+chr$(34)+",_"
 


4 - ACCESS THE CODE LIBRARY IN THE OPEN SOURCE EDITOR

To access the code library from within the open source editor, we'll first need to check for its existence and create it if it doesn't exist, as we've discussed above.

[code.library]
    gosub [make.lib]
 

Once we know that the file either existed previously, or was created, we can open it and read the data. We'll need an array to hold the snippet titles so that they can be accessed from a combobox, so we'll DIM the array "code$".

    dim code$(100)

We'll need a routine that is similar to the one that scans program code for branch labels, functions and subs. We'll evaluate each line of text as it is input, and if it begins with the marker that Cameron set up, the "'>" characters, we'll add that line to the array of snippet titles. We'll set up an index variable, called "codeindex" to keep track of the array index that is to be filled with each succeeding snippet title.

    codeindex=0
    open "codelibr.txt" for input as #code
    while eof(#code)=0
    line input #code, codeline$ 
        if left$(trim$(codeline$),2)="'>" then
            code$(codeindex)=codeline$
            codeindex=codeindex+1
        end if
    wend
    close #code

Now that the snippet titles are contained in an array, we can open a dialog window to access the code library. We'll want a combobox of titles to choose from, a button to copy the code to the clipboard, and another one to cancel the operation. We'll certainly want a texteditor to display the snippet!

    WindowWidth=400:WindowHeight=450
    combobox #lib.c, code$(,[code.choice],10, 10, 250,400
    button #lib.copy, "Copy",[copy.lib],UL,10,50,100,30
    button #lib.cancel, "Cancel",[quit.lib],UL,150,50,100,30
    texteditor #lib.text, 10, 90, 370,300
    open "Code Library" for dialog as #lib

It is always a good idea to trap the close event of a window. It is also more professional to have comboboxes display a default item. We'll tell the combobox to display the item whose index number is "1".

    print #lib, "trapclose [quit.lib]"
    print #lib.c, "selectindex 1"

The actual code snippet to match a snippet title should be displayed in the texteditor. We'll do this by getting the snippet title from the combobox, and searching the text file for a matching line, that signals the beginning of the chosen snippet.

[code.choice]
    print #lib.c, "selection?"
    input #lib.c, codeChoice$

We have the snippet title in the variable "codeChoice$". We can open the text file and look at each line until we find a match. Once we find the snippet we are searching for, we'll clear the texteditor, then start printing the lines input from the file into the texteditor. We do this with WHILE/WEND, continuing until we've reached the end of the snippet.

We'll set up a flag called "endmarker" that will be given a value of 1 when we've reached the characters, "'}" that Cameron has set up to indicate the end of a code snippet. When we discover the "'}", we'll set the end marker to 1 so that we can jump out of the WHILE/WEND loop.

    open "codelibr.txt" for input as #code
    print #lib.text, "!cls"
    endmarker=0
 
    while eof(#code)=0 and endmarker=0
        line input #code, codeline$ 
        if trim$(codeline$)=codeChoice$ then
            print #lib.text, codeline$
            while endmarker=0
            line input #code, codeline$
            print #lib.text, codeline$
            if left$(trim$(codeline$),2)="'}" then endmarker=1
            wend
        end if
    wend
    close #code

The texteditor now displays the selected snippet from the code library file. We should set the origin of the texteditor to be "1 1" so that the beginning of the snippet appears at the top of the texteditor.

    print #lib.text, "!origin 1 1";

When the COPY button is clicked, the user wants to copy the selected snippet to the clipboard to paste into his code. We can select everything in the texteditor with the "!selectall" command. Once all text is selected, we can copy it to the clipboard easily with the "!copy" command.

"!copy" will copy any selected text to the clipboard, where it will remain until overwritten by new data.

[copy.lib]
    print #lib.text, "!selectall"
    print #lib.text, "!copy"
    notice "Snippet has been copied to clipboard."

Once the snippet is copied to the clipboard, we close the window and return to the editor's main input loop:

[quit.lib]
    close #lib
    goto [loop]
 


5 - LAUNCH EMAIL CLIENT AND BROWSER W/URL

We'll take advantage of LB2's new CALL SUB ability to implement launching a browser with a specified URL, and launching the user's email client in the open source editor. This routine will require the API call to ShellExecute. The function requires a valid window handle as its first parameter. This call also requires the name of the file that is to be run.

This will be either the URL we want (http:??), or the email client (mailto:??). The operation to perform must be specified. We want "open".

The other possibility for this parameter is "print", which we've used in the printer routine in the open source editor. For use here, the directory and parameter specifications are null or "". We also need to specify the way the window will be displayed. It may be hidden, minimized, etc. We want it to display in its normal way, so we'll use _SW_SHOWNORMAL. Windows constants that begin with "SW" are Show Window constants.

sub RunThis RunFile$, hWindow
    RunFile$=RunFile$+chr$(0)
    lpOperation$ = "open" + chr$(0)
    lpParameters$ = "" + chr$(0)
    lpDirectory$ = "" + chr$(0)
    nShowCmd = _SW_SHOWNORMAL
 
    open "shell.dll" for dll as #shell
    calldll #shell, "ShellExecute", _
        hWindow as word, _          'parent window
        lpOperation$ as ptr, _      'open or print
        RunFile$ as ptr, _          'file name
        lpParameters$ as ptr, _     'null
        lpDirectory$ as ptr, _      'default directory
        nShowCmd as short, _        'show window flag
        result as word
    close #shell
    if result <= 32 then notice "Error, Address Failure!"
    end sub

To run a user's default web browser, and have it open at the Liberty BASIC homepage, we pass two parameters to our RunThis SUB. We first list the URL for the website, then the window handle.

CALL RunThis "http://www.libertybasic.com/" ,h

Launching the default email client is also possible. The simple syntax for the FILE parameter is "mailto:name@address.com". If you've written any HTML, you will recognize the "mailto" tag that signals activation of the email client. It is possible to fill the subject header line also, by appending "?Subject=Subject Header" to the FILE parameter. To write an email to Carl Gundel regarding Liberty BASIC, here is the parameter:

CALL RunThis "mailto:carlg@libertybasic.com?Subject=Liberty BASIC" ,h


6 - SHELLEXECUTE

We've used the ShellExecute call in two different ways in the open source editor. Let's talk about using this powerful call in detail now.

 

HUNGARIAN NOTATION

Hungarian notation is a way of expressing parameters so that the TYPE is clear in the documentation. LB includes AS TYPE in its api calling syntax, but C does not. Many references, like the win31sdk helpfile are in C syntax, so it is helpful to understand Hungarian notation. A parameter name preceded by "lp" is a "long pointer", which is passed AS PTR in LB. A parameter name preceded by "n" is passed AS SHORT in LB. "n" signals "INTEGER". If you see the notation "lpsz", this stands for "long pointer string zero". This signals a long integer pointer (PTR in LB) to a string which is ZERO terminated. We add a zero terminator by adding chr$(0) to a string in LB.


SHELLEXECUTE IN LIBERTY BASIC

Here is the generic Liberty BASIC syntax:

open "shell.dll" for dll as #shell
 
calldll #shell, "ShellExecute", _
hWindow as word, _          'parent window
lpszOperation$ as ptr, _    'open or print
lpszFile$ as ptr, _         'file name - exe name
lpszParameters$ as ptr, _   'parameters to pass for exe file
lpszDirectory$ as ptr, _    'default directory
nShowCmd as short, _        'show window flag
result as word              'instance handle of module
 
close #shell

Parameters explained in detail:

--hWindow as word, _          'parent window

You must have a valid window handle here. If you do not open a program window, you can get the handle of the mainwindow with a call to GetActiveWindow, like this:

open "user" for dll as #user
CallDLL #user, "GetActiveWindow",hActiveWin as word
close #user

You can then use "hActiveWin" as the window handle in the ShellExecute function.

--lpszOperation$ as ptr, _    'open or print

The operation will be "open" or "print". If this parameter is left null "" then "open" is the default. This parameter is ignored if the file name is an executable. It should be passed as a null-terminated string:

lpszOperation$="open"+chr$(0)
 
 
--lpszFile$ as ptr, _         'file name - exe name

If this parameter is an executable file, it will be run using the parameters passed in the next function parameter for this call. If it is any other type of file, Windows will try to find the executable associated with this type of file. In the open source editor, we use a filename with a TXT extension and an operation parameter of "print" so that the user's default text editor will print the file we specify. We've also just added the ability to activate the default browser, by passing a file name that begins with "http://". We activate the default email client with a file name that begins with "mailto". If we had an operation parameter of "print" and a file with the extension "bmp" then ShellExecute would find the default bitmap editor and ask it to print a hard copy of the bitmap specified. Here is a small, sample program that will open and print a text file:

'*********************************************************
filedialog "Open text file...","*.txt",file$ 
if file$="" then end
 
open "user" for dll as #user
CallDLL #user, "GetActiveWindow",hWindow as short
close #user
 
lpFile$=file$+chr$(0)
lpOperation$ = "print" + chr$(0)
lpParameters$ = "" + chr$(0)
lpDirectory$ = "" + chr$(0)
nShowCmd = _SW_SHOWNORMAL
 
open "shell.dll" for dll as #shell
calldll #shell, "ShellExecute", _
    hWindow as word, _         'parent window
    lpOperation$ as ptr, _     'open or print
    lpFile$ as ptr, _          'file name
    lpParameters$ as ptr, _    'parameters for executable
    lpDirectory$ as ptr, _     'default directory
    nShowCmd as short, _       'show window flag
    result as word
close #shell
'*********************************************************

If we passed a filename of "explorer.exe", the ShellExecute function would run Windows Explorer using the command line parameters passed in the next function parameter. We could issue the LB command to "run" to achieve a similar result:

run "explorer.exe "+DefaultDir$

 

--lpszParameters$ as ptr, _   'parameters to pass for exe file

This argument in the ShellExecute function is only used if the file specified is an executable, or *.EXE file. The following snippet asks the user to choose a BASIC source code file, and then opens Notepad fullscreen with the file loaded. In this case, the source code file is passed in the parameter field rather than in the file field, because "notepad.exe" is filling the file field position.

'*********************************************************
filedialog "Open BAS file...","*.bas",file$ 
if file$="" then end
 
open "user" for dll as #user
CallDLL #user, "GetActiveWindow",hWindow as short
close #user
 
lpFile$="notepad.exe"+chr$(0)
lpOperation$ = "open" + chr$(0)
lpParameters$ = file$ + chr$(0)
lpDirectory$ = "" + chr$(0)
nShowCmd = _SW_SHOWMAXIMIZED
 
open "shell.dll" for dll as #shell
calldll #shell, "ShellExecute", _
    hWindow as word, _         'parent window
    lpOperation$ as ptr, _     'open or print
    lpFile$ as ptr, _          'file name
    lpParameters$ as ptr, _    'parameters for executable
    lpDirectory$ as ptr, _     'default directory
    nShowCmd as short, _       'show window flag
    result as word
close #shell
'*********************************************************

Here is another example that runs an executable file, with the paramater field in use. This is a Win95+ example, which runs Windows Explorer. If the parameter field is filled with the DefaultDir$, Explorer will open in the current directory. If the parameter field is left null, Explorer will open in the root directory of the current drive. For me, this is C:/. It isn't well known, but Windows File Manager can be accessed by Win95+ as well as by Win3.1. The lpFile$ parameter would then be:

lpFile$="winfile.exe"+chr$(0)
 
'*********************************************************
open "user" for dll as #user
CallDLL #user, "GetActiveWindow",hWindow as short
close #user
 
lpFile$="explorer.exe"+chr$(0)
lpOperation$ = "open" + chr$(0)
lpParameters$ = DefaultDir$ + chr$(0)
lpDirectory$ = "" + chr$(0)
nShowCmd = _SW_SHOW
 
open "shell.dll" for dll as #shell
calldll #shell, "ShellExecute", _
    hWindow as word, _         'parent window
    lpOperation$ as ptr, _     'open or print
    lpFile$ as ptr, _          'file name
    lpParameters$ as ptr, _    'parameters for executable
    lpDirectory$ as ptr, _     'default directory
    nShowCmd as short, _       'show window flag
    result as word
close #shell
 
'*********************************************************

 

--lpszDirectory$ as ptr, _    'default directory

If the directory information is contained in the file name field or the parameter field, this field can be left null. It can be filled with a directory, if needed, such as DefaultDir$+chr$(0).

 

--nShowCmd as short, _        'show window flag

This parameter tells Windows how to display the window: size, active/inactive, &etc. See the documentation at the end of this article for a list of possible ShowWindow flags.

 

We can use LB's RUN command to accomplish some of the same things that can be done with the API function ShellExecute. Here is another example, that shows a bitmap in PaintBrush. Calling PaintBrush in Win95+ will cause MS Paint to open.

 

filedialog "Open Bitmap","*.bmp",file$
if file$="" then end
run "pbrush.exe "+file$, SHOWMINIMIZED
'HIDE
'SHOWNORMAL  (this is the default)
'SHOWMINIMIZED
'SHOWMAXIMIZED
'SHOWNOACTIVE
'SHOW
'MINIMIZE
'SHOWMINNOACTIVE
'SHOWNA
'RESTORE


7 - WINEXEC

 

Liberty BASIC's RUN command is actually a clone of the WinExec command. This command does not require as many parameters as ShellExecute, so it is easier to make. It does not require a window handle to work. It is not as flexible, or powerful, however. This function is part of the KERNEL DLL.

The syntax:

open "kernel.dll" for dll as #kernel
 
calldll #kernel, "WinExec", _
    lpFile$ as ptr, _    'file name w/ parameters
    nShowCmd as short, _ 'show window flag
    result as word
 
close #kernel

The file name "lpFile$" should contain the name of the executable file to run, along with any parameters, such as files to be loaded into the executable, or command line switches. The nShowCmd parameter is used in the same way here as in ShellExecute. Here is a little program that allows a user to open a text file and display it in Notepad. There are two ways shown, the Windows API version, then the Liberty BASIC version. You can see that it is much easier to do with LB commands, and it requires less code.

 

'Win API version:
filedialog "Open text file...","*.txt",file$
if file$="" then end
 
lpFile$="Notepad.exe "+file$+chr$(0)
nShowCmd=_SW_SHOWNA
 
open "kernel.dll" for dll as #kernel
calldll #kernel, "WinExec", _
lpFile$ as ptr, _ 'file name w/ parameters
nShowCmd as short, _ 'show window flag
result as word
close #kernel

 

'Liberty BASIC version:
filedialog "Open text file...","*.txt",file$
if file$="" then end
 
RUN "notepad.exe "+file$, SW_SHOWNA


8 - FINDEXECUTABLE

This function is part of Shell.dll. It returns the user's default application that is associated with the specified file type. It requires a null-terminated string containing the filename for which you want to find the application, and another null-terminated string containing the directory. This can be null, or "". It also requires a buffer for the function to return the name of the associated executable. In LB2, it is very important to set this up as a string variable that is long enough to hold information returned by the function. It can be a string of blank spaces:

lpszResult$=space$(255)+chr$(0)

Here is the syntax:

open "shell" for dll as #shell
calldll #shell, "FindExecutable",_
lpszFile$ as PTR,_ 'file name to execute
lpszDir$ as PTR,_ 'default directory
lpszResult$ as PTR,_ 'buffer to hold executable name
result as short '>=32 if successful
close #shell

The result will be 32 or greater if the function succeeds in finding an associated application. If the call succeeds, the name of the executable will be contained in the buffer, lpszResult$. The left$ part of the string, up to to a null marker, chr$(0) will be the path/filename of the program. This function has limited usefullness with Liberty BASIC. It returns the application in Win95+ long path/filename format, so the return may not work with Liberty BASIC's RUN command, or in the WinExec function mentioned earlier. Here is a small, sample program to illustrate the usage for this function.

[again]
filedialog "Choose file...","*.*",file$
if file$="" then end
 
lpszFile$=file$+chr$(0)
lpszDir$=""+chr$(0)
lpszResult$=space$(255)+chr$(0)
 
open "shell" for dll as #shell
 
calldll #shell, "FindExecutable",_
lpszFile$ as PTR,_ 'file name to execute
lpszDir$ as PTR,_ 'default directory
lpszResult$ as PTR,_ 'buffer to hold executable name
result as short '>=32 if successful
 
close #shell
 
if result>=32 then
print "Application is:"
print left$(lpszResult$,instr(lpszResult$,chr$(0))-1)
 
else
print "Error! No application returned for this file."
end if
 
input "Press enter to check another file.";answer$
print
goto [again]


9 - DOCUMENTATION FOR SHELLEXECUTE, WINEXEC AND FINDEXECUTABLE IN C FORMAT

 

ShellExecute (3.1)

#include shellapi.h
 
HINSTANCE ShellExecute(hwnd, lpszOp, lpszFile, lpszParams, lpszDir, fsShowCmd)
 
HWND hwnd; /* handle of parent window */
LPCSTR lpszOp; /* address of string for operation to perform */
LPCSTR lpszFile; /* address of string for filename */
LPCSTR lpszParams;/* address of string for executable-file parameters */
LPCSTR lpszDir; /* address of string for default directory */
int fsShowCmd; /* whether file is shown when opened */

The ShellExecute function opens or prints the specified file.

Parameter Description

hwnd Identifies the parent window. This window receives any message boxes an application produces (for example, for error reporting).

lpszOp Points to a null-terminated string specifying the operation to perform. This string can be "open" or "print". If this parameter is NULL, "open" is the default value.

lpszFile Points to a null-terminated string specifying the file to open.

lpszParams Points to a null-terminated string specifying parameters passed to the application when the lpszFile parameter specifies an executable file. If lpszFile points to a string specifying a document file, this parameter is NULL.

lpszDir Points to a null-terminated string specifying the default directory.

fsShowCmd Specifies whether the application window is to be shown when the application is opened. This parameter can be one of the following values:

Value Meaning

SW_HIDE Hides the window and passes activation to another window.

SW_MINIMIZE Minimizes the specified window and activates the top-level window in the system's list.

SW_RESTORE Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as SW_SHOWNORMAL).

SW_SHOW Activates a window and displays it in its current size and position.

SW_SHOWMAXIMIZED Activates a window and displays it as a maximized window.

SW_SHOWMINIMIZED Activates a window and displays it as an icon.

SW_SHOWMINNOACTIVE Displays a window as an icon. The window that is currently active remains active.

SW_SHOWNA Displays a window in its current state. The window that is currently active remains active.

SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The window that is currently active remains active.

SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as SW_RESTORE).

 

Returns

The return value is the instance handle of the application that was opened or printed, if the function is successful. (This handle could also be the handle of a DDE server application.) A return value less than or equal to 32 specifies an error. The possible error values are listed in the following Comments section.

 

Errors

The ShellExecute function returns the value 31 if there is no association for the specified file type or if there is no association for the specified action within the file type. The other possible error values are as follows:

 

Value Meaning

0 System was out of memory, executable file was corrupt, or relocations were invalid.

2 File was not found.

3 Path was not found.

5 Attempt was made to dynamically link to a task, or there was a sharing or network-protection error.

6 Library required separate data segments for each task.

8 There was insufficient memory to start the application.

10 Windows version was incorrect.

11 Executable file was invalid. Either it was not a Windows application or there was an error in the .EXE image.

12 Application was designed for a different operating system.

13 Application was designed for MS-DOS 4.0.

14 Type of executable file was unknown.

15 Attempt was made to load a real-mode application (developed for an earlier version of Windows).

16 Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only.

19 Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded.

20 Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt.

21 Application requires Microsoft Windows 32-bit extensions.

 

Comments

The file specified by the lpszFile parameter can be a document file or an executable file. If it is a document file, this function opens or prints it, depending on the value of the lpszOp parameter. If it is an executable file, this function opens it, even if the string "print" is pointed to by lpszOp.

 

WinExec (3.0)
UINT WinExec(lpszCmdLine, fuCmdShow)
 
LPCSTR lpszCmdLine; /* address of command line */
UINT fuCmdShow; /* window state of new app. */

The WinExec function runs the specified application.

 

Parameter Description

lpszCmdLine Points to a null-terminated Windows character string that contains the command line (filename plus optional parameters) for the application to be run. If the string does not contain a path, Windows searches the directories in this order:

 

1 The current directory.

2 The Windows directory (the directory containing WIN.COM); the GetWindowsDirectory function retrieves the path of this directory.

3 The Windows system directory (the directory containing such system files as GDI.EXE); the GetSystemDirectory function retrieves the path of this directory.

4 The directory containing the executable file for the current task; the GetModuleFileName function retrieves the path of this directory.

5 The directories listed in the PATH environment variable.

6 The directories mapped in a network.

 

fuCmdShow Specifies how a Windows application window is to be shown. See the description of the ShowWindow function for a list of the acceptable values for the fuCmdShow parameter. For a non-Windows application, the program-information file (PIF), if any, for the application determines the window state.

 

Returns

The return value identifies the instance of the loaded module, if the function is successful. Otherwise, the return value is an error value less than 32.

 

Errors

The error value may be one of the following:

 

Value Meaning

0 System was out of memory, executable file was corrupt, or relocations were invalid.

2 File was not found.

3 Path was not found.

5 Attempt was made to dynamically link to a task, or there was a sharing or network-protection error.

6 Library required separate data segments for each task.

8 There was insufficient memory to start the application.

10 Windows version was incorrect.

11 Executable file was invalid. Either it was not a Windows application or there was an error in the .EXE image.

12 Application was designed for a different operating system.

13 Application was designed for MS-DOS 4.0.

14 Type of executable file was unknown.

15 Attempt was made to load a real-mode application (developed for an earlier version of Windows).

16 Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only.

19 Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded.

20 Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt.

21 Application requires Microsoft Windows 32-bit extensions.

 


FindExecutable (3.1)

 
#include shellapi.h
 
HINSTANCE FindExecutable(lpszFile, lpszDir, lpszResult)
 
LPCSTR lpszFile; /* address of string for filename */
LPCSTR lpszDir; /* address of string for default directory */
LPSTR lpszResult; /* address of string for executable file on return */

The FindExecutable function finds and retrieves the executable filename that is associated with a specified filename.

 

Parameter Description

lpszFile Points to a null-terminated string specifying a filename. This can be a document or executable file.

lpszDir Points to a null-terminated string specifying the drive letter and path for the default directory.

lpszResult Points to a buffer that receives the name of an executable file when the function returns. This null-terminated string specifies the application that is started when the Open command is chosen from the File menu in File Manager.

 

Returns

The return value is greater than 32 if the function is successful. If the return value is less than or equal to 32, it specifies an error code.

 

Errors

The FindExecutable function returns 31 if there is no association for the specified file type. The other possible error values are as follows:

 

Value Meaning

0 System was out of memory, executable file was corrupt, or relocations were invalid.

2 File was not found.

3 Path was not found.

5 Attempt was made to dynamically link to a task, or there was a sharing or network-protection error.

6 Library required separate data segments for each task.

8 There was insufficient memory to start the application.

10 Windows version was incorrect.

11 Executable file was invalid. Either it was not a Windows application or there was an error in the .EXE image.

12 Application was designed for a different operating system.

13 Application was designed for MS-DOS 4.0.

14 Type of executable file was unknown.

15 Attempt was made to load a real-mode application (developed for an earlier version of Windows).

16 Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only.

19 Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded.

20 Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt.

21 Application requires Microsoft Windows 32-bit extensions.

 

Comments

The filename specified in the lpszFile parameter is associated with an executable file when an association has been registered between that file's filename extension and an executable file in the registration database. An application that produces files with a given filename extension typically associates the extension with an executable file when the application is installed.


Side by Side Software offers a Book for Liberty BASIC, which is available in electronic form on a CDROM. For details: http://alyce.50megs.com/sss/cd.htm
Comments, requests or corrections: Hit 'REPLY' now! Dean Hodgson -- mailto:Hodgson.Dean@saugov.sa.gov.au Alyce Watson -- mailto:awatson@wctc.net