Les Bell and Associates Pty Ltd
PO Box 173, Frenchs Forest, NSW 1640 Australia
Tel: +61 2 9451 1144 Fax: +61 2 9451 1122


Using REXX to Repair and Control the Desktop

The Workplace Shell is extremely powerful and and customisable, and this is at once a blessing and a curse. It means that support staff can present the user with a customised desktop which is oriented towards their tasks, but it also means that the user can completely rearrange things at best, or delete important objects at worst. We need ways to work around these problems.

Utilities like DeskMan/2 allow the ad-hoc manipulation of objects to change their settings and styles. However, this technique is tedious when a lot of repair work has to be done, or when extensively customising desktops for a number of user machines.

The real pro power technique is to create program reference objects for your OS/2 and DOS apps by using a small REXX program which can set all the appropriate keyname-value pairs in the object's setup string. You want either the SysCreateObject() or the SysSetObjectData() functions. Here's the skinny:

The SysCreateObject() function syntax is:


rc = SysCreateObject(class, title, location, setup_string, options)

The class is the workplace shell class for the object you are creating (as a text string). Useful classes include:

The title is just any string you want as the title for the object.

The location is the object ID of the place where you want your object created. Most useful is "<WP_DESKTOP>", but there are others. If you want to know the good ones, take a look inside the \OS2\INI.RC file - they're all the things in angle braces <>. Most objects created as you use the Workplace Shell have numeric object ID's which are difficult to find out, but folders you create yourself (see below) can be given symbolic ID's. Also objects on disk - that is, which are subclasses of WPDataFile - can be referred to by their pathname, e.g. "C:\Desktop\MyFolder\DATABASE.DBF".

Now, the interesting part - the setup string. All kinds of things can go in here. It's a long string, that takes the form of "key=value;key=value;key=value". Here are the possible key-value pairs for the WPProgram class (i.e. program reference objects):

Object Setup Strings
Keyname Value Description
ASSOCFILTER filters Sets the filename filter for files associated with this program. Multiple filters are separated by commas.
ASSOCTYPE type Sets the types of files associated with this program. Multiple types are separated by commas.
EXENAME filename Sets the name of the program.
MAXIMIZED YES The program window is maximized upon startup.
NO The program window is restored to normal upon startup. This is the default setting.
MINIMIZED YES The program window is mimized upon startup.
NO The program window is restored to normal upon startup. This is the default setting.
PROGTYPE FULLSCREEN Sets the session type to OS/2 full-screen mode.
PM Sets the session type to PM.
PROG_30_STD Sets the session type to standard compatibility full screen mode.
PROG_31_ENH Sets the session type to enhanced compatibility full screen mode.
PROG_31_ ENHSEAMLESSCOMMON Sets the session type to WIN-OS/2 window in the WIN-OS/2 enhanced compatibility common session.
PROG_31_ ENHSEAMLESSVDM Sets the session type to WIN-OS/2 window in a separate session enhanced compatibility mode.
PROG_31_STD Sets the session type to standard compatibility full screen mode.
PROG_31_STD SEAMLESSCOMMON Sets the session type to WIN-OS/2 window in the WIN-OS/2 standard compatibility common session.
PROG_31_STD SEAMLESSVDM Sets the session type to WIN-OS/2 window in a separate session standard compatibility mode.
SEPARATEWIN Sets the session type to WIN-OS/2 window running in a separate VDM.
VDM Sets the session type to DOS full screen.
WIN Sets the session type to WIN-OS/2 full screen.
WINDOWABLEVIO Sets the session type to OS/2 windowed.
WINDOWEDVDM Sets the session type to DOS windowed.
WINDOWEDWIN Sets the session type to WIN-OS/2 window.
NOAUTOCLOSE YES Leave the window open when the program terminates.
NO Closes the window when the program terminates. This is the default setting.
PARAMETERS params Sets the parameters list, which may include substitution characters.
SET xxx=vvv xxx is an environment variable. vvv sets the value of the environment variable. This is also used to specify DOS settings on DOS and Windows programs. Each variable/value pair must be separated by a NULL (\0), and the entire string must be terminated by two NULLs (\0\0). For example: DOSDEVICE=value\0env=value\0\0.
STARTUPDIR pathname Sets the working directory.

Example:


setup_string="PROGTYPE=VDM;EXENAME=C:\EDIT.EXE;
                  ASSOCFILTER=*.DOC,*.TXT;ASSOCTYPE=Plain Text;
                  SET DOS_DEVICE=1.SYS,2.SYS;
                  SET PATH=C:\FRED"

Lastly, the options: well, usually that's just "r" to replace any existing object, but it could be "f" to fail if the object already exists or "u" to update any existing object.

For more details, look up SysCreateObject in the REXX online help (VIEW C:\OS2\BOOK\REXX.INF).

Bear in mind that if you launch a Presentation Manager application, it may well contain logic that reads its previous window location and size from wherever it stored it (OS2.INI) when it last shut down, and this will override MAXIMIZED=TRUE. Or it might size itself to be 3/4 of the desktop - that's quite common. However, especially in the first case, you probably don't have a problem with it starting too small.

Here's a sample program fragment, taken from the INSTALL.CMD I wrote to go on the course diskette from the course I'm teaching this week:

--------------%< Cut here %<------------------------

/* REXX Script to install "OS/2 Support" Folder */
'@echo off'
if arg(1,'O') then do
  say "Usage: Install d:"
  exit
end
PARSE UPPER ARG dest

/* The following two lines are necessary for the SysCreateObject() function to be accessible */
call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call SysLoadFuncs
rc = SysMkDir(dest'\OS2MAINT')
if rc \= 0 & rc \= 5 then do
  say "Error creating \OS2MAINT directory"
  say "rc = "rc
  exit
end

dest        /* Changes to the target drive */
'cd \os2MAINT'
/* Unzip and copy the various files from A: */
'copy a:unzip.exe'
'unzip a:fenx2'
'unzip a:inimt20d'
'unzip a:hpfopt'
'unzip a:pmmine'
'unzip a:txtfiles'
'unzip a:asteroid'
'copy a:*.cmd'
'copy a:*.zip'

/* Create the "OS/2 Support" folder */
rc = SysCreateObject("WPFolder", "OS/2 Support", "", "OBJECTID = ; OPEN=ICON", "r")

rc = SysCreateObject("WPProgram", "IniMaint", "", "EXENAME="dest"\OS2MAINT\INIMAINT.EXE; PROGTYPE=PM;STARTUPDIR="dest"\OS2MAINT", "r")

rc = SysCreateObject("WPProgram", "File Phoenix", "", "EXENAME="dest"\OS2MAINT\PHOENIX2.EXE;PROGTYPE=PM;STARTUPDIR="dest"\OS2MAINT", "r")

rc = SysCreateObject("WPProgram", "PM Mines", "", "EXENAME="dest"\OS2MAINT\PMMINE.EXE;PROGTYPE=PM;STARTUPDIR="dest"\OS2MAINT", "r")

rc = SysCreateObject("WPProgram", "AlarmPro", "", "EXENAME="dest"\OS2MAINT\ALRMPRO.EXE; PROGTYPE=PM;STARTUPDIR="dest"\OS2MAINT", "r")

--------------%< Cut here %<------------------------

OK, with a little hacking and insertion of the correct parameters in the SysCreateObject() function calls, you should be able to create program reference objects that behave the way you want - though see the code fragment at the end of this file first.

Now to SysSetObjectData(). If you've already created the object, and know its ID, then you can change the setup string using this function call. The syntax is:

Syntax: result = SysSetObjectData(name, setup) name The object name. This can be specified as an object ID (for example ) or as a fully specified file name. setup A WinCreateObject setup string. result The return code from WinSetObjectData. This will return 1 (TRUE) if the object was updated and 0 (FALSE) if the object was not updated. Purpose: Change the settings of an existing object. It can also be used to open an instance of an object. Examples: /* Code */ if SysSetObjectData("MyProgram","NOMOVE=YES") Then Say "Myprogram object settings have been updated."

In this example, the object style is being changed, obviously in an attempt to 'user-proof' the program reference object. Other useful strings for Workplace Shell objects generally (i.e. these are supported by the base class, WPObject) are:

Object Style Strings
Keyname Value Description
CCVIEW DEFAULT The default value of the current system view setting is used when the user selects open.
YES This sets the object's multiple concurrent view behaviour, so that new views of this object are created every time the user selects open.
NO Opened view of this object resurfaces when the user selects open.
DEFAULTVIEW SETTINGS This sets the default open view to Settings view.
id This sets the default open view to the id of a user-added view (0 - 9).
DEFAULT This sets the default open view to the object's class default view, as returned by wpclsQueryDefaultView. This is the default value.
HELPLIBRARY filename This sets the help library.
HELPPANEL id This sets the object's default help panel for object-specific help. This is equivalent to calling wpSetDefaultHelp.
HIDEBUTTON YES Views of this object have a hide button as opposed to a minimize button.
NO Views of this object have a minimize button as opposed to a hide button.

The default is the current system Button appearance for windows setting. This cannot be specified here.

ICONFILE filename This sets the object's icon. This is equivalent to calling wpSetIconData.
ICONPOS x,y This sets the object's initial icon position in a folder. The x and y values represent the position in the object's folder in percentage coordinates.
ICONRESOURCE id,module This sets the object's icon. This is equivalent to calling wpSetIconData. The 'id' is the icon resource ID in the dynamic link library (DLL) 'module'.
MINWIN HIDE Views of this object hide when their minimize button is selected.
VIEWER Views of this object minimize to the minimized window viewer when their minimize button is selected.
DESKTOP Views of this object minimize to the desktop when their minimize button is selected.

The default is the current Minimize button setting. This cannot be specified here.

NOCOPY YES This sets the object's no copy property, so that the object cannot be copied. This is equivalent to calling wpSetStyle with a style of OBJSTYLE_NOCOPY.
NO This resets the object's no copy property, so that the object can be copied. This is the default value.
NODELETE YES This sets the object's no delete property, so that the object cannot be deleted.
NO This resets the object's no delete property, so that the object can be deleted. This is the default value.
NODRAG YES This sets the object's no drag property, so that the object cannot be dragged.
No This resets the object's no drag property, so that the object can be dragged. This is the default value.
NODROP YES This sets the object's no drop property, so that no other object can be dropped on it.
NO This resets the object's no drop property, so that another object can be dropped on it. This is the default value.
NOLINK YES This sets the object's no link property, so that the object cannot be linked (shadowed).
NO This resets the object's no link property, so that the object can be shadowed. This is the default value.
NOMOVE YES This sets the object's no move property, so that the object cannot be moved.
NO This resets the object's no move property, so that the object can be moved. This is the default value.
NOPRINT YES This sets the object's no print property, so that the object cannot be printed.
NO This resets the object's no print property, so that the object can be printed. This is the default value.
NORENAME YES This sets the object's no rename property, so that the object cannot be renamed.
NO This resets the object's no rename property, so that the object can be renamed. This is the default value.
NOSETTINGS YES This sets the object's no settings property, so that the object settings cannot be opened.
NO This resets the object's no settings property, so that the object settings can be opened. This is the default value.
NOSHADOW YES This sets the object's no shadow property, so that the object cannot be shadowed.
NO This resets the object's no shadow property, so that the object can be shadowed. This is the default value.
NOTVISIBLE YES This sets the object's not visible property, so that the object cannot be made visible.
NO This resets the object's not visible property, so that the object can be made visible. This is the default value.
OBJECTID <name> This sets a persistent ID for the object. The OBJECTID stays with the object even if it is moved or renamed. The object pointer or handle can be retrieved view wpclsQueryObject or WinQueryObject respectively. An OBJECTID is any unique string preceded with a "<" and terminated with a ">".
OPEN SETTINGS This opens the Settings view when an object is created or when WinSetObjectData is called.
DEFAULT This opens the default view when an object is created or when WinSetObjectData is called.
TEMPLATE YES This sets the object's template property.
NO This resets the object's template property. This is the default value.
TITLE title This sets the object's title.

Example

  pszSetupString="TITLE=MYObject;ICONFILE=myobj.ico;HELPPANEL=132;
                 TEMPLATE=YES;NODELETE=NO"

Notice that using this technique - either SysCreateObject() or SysSetObjectData() - you can make icons non-deletable, non-printable, non-visible(!) and generally user-proof.

OK, the rest is up to you. Here's a skeleton REXX program to create an object that will start maximised - you can gussy this one up considerably:

----------%<-----%<------ Cut Here -----------%<-----%<-------------

/* REXX program to create a program reference object */
call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call SysLoadFuncs

title="Insert your title here"
location=""
setup="EXENAME=c:\somewher\myprog.exe;PROGTYPE=WINDOWABLEVIO;STARTUPDIR=C:\OS2;MAXIMISED=YES"

rc = SysCreateObject("WPProgram", title, location, setup, "r")

----------%<-----%<------ Cut Here -----------%<-----%<-------------

If you need to know the setup strings for any other classes (e.g. WPFolder, which allows you to set the various views, backgrounds, etc.) you will need the Warp Toolkit, which is most easily and cheaply obtained from the Developers Connection CD-ROMs.


Copyright © 1995 Les Bell and Associates Pty Ltd

Les Bell
lesbell@lesbell.com.au