Making W4 remember window positions & sizes

By Al Savage

HOW TO: restore your desktop just the way you want it. DOS programs in windows, all DOS and CMD windows at individual sizes, etc.

If you're running W4+, first see if this "built-in" method works for you. This is from the README.TXT from WSeB's installation diskette:

 2.1.10 OS/2 Window Default Size and Position

In OS/2 Warp 4.0 and later versions, an OS/2 Window opens to a default size and position. If you run customized applications that require the window to open to a specific size and position, you can remove these defaults.

To remove the default window size and position:

1. Open an OS/2 command window.

2. Move the mouse pointer to the restore icon in the upper right corner of the window.

3. Press and hold the Shift key and right-click the restore icon.

4. Release the Shift key. 

It can't be the easy way, but here's how we're doing it: Move_it/Switchto/Console

I'm taking these notes to aid me Next Time!

I keep thinking that there must be an easier way, but I've not been able to find one, so I put these utils together to do the task. The problem: many of my boxen need to have several tasks started at every boot, and the windows take up real estate, and won't go where I want them automatically, or have to be manually resized. The tools I use to get this to happen are:


 * REXX/2, ships with OS/2
 * OS/2 CMD.EXE START, ships with OS/2
 * Console.exe, by Andrew Pavel Zabolotny, GPL freeware
 * WMoves.exe, by Benno Sauer, shareware, $24
 * Move_it.exe, by Benno Sauer, shareware, $24
 * Switchto.exe, by Roman Stangl, freeware

START has a number of parameters that can be used to start an app in a window or minimized, as well as full screen. Various session parameters can be utilized to allow the app to be started detached or with its own command processor.

Move_it.exe reads an ini file, and can reposition a list of running apps to your predifined format. It can't resize a window directly, though it comes with a utility, Fontset, that allows custom window font sizes.

WMoves.exe is a PM ini-file builder for Move_it.

Console.exe does what Move_it.exe does, but only one app at a time, and it has to be run IN each app's window, so it's less useful, but it can resize the window it's in. Handy to run before an app: start a windowed session, run Console.exe to resize it (and optionally set its position), then start the app. Move_it.exe can manage a whole list of window positions, so it's easier to allow Move_it.exe to handle ALL windows than to try to maintain individual windows via Console.exe.

Switchto.exe can put a predetermined window into the foreground, to take advantage of the greater priority boost that a foreground task enjoys.

In the following examples: All *.CMD files are located in x:\BELFRY Startup.cmd is shadowed in the OS/2 Startup folder. Apache.cmd starts up Apache/2, while waiting for network connections to finish. StartftpServer.cmd starts up ftpServer, by Peter Moylan.

Sample code for Startup.cmd
 /* Startup.cmd Date Created: 11-Mar-00 ALS Date Revised: 26-Mar-00 ALS

Starts up all normal bootup user tasks on this computer

/* Load utilities */ CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' CALL SysLoadFuncs

START "/WIN /MIN /C ""ZTBold"" /PGM C:\ZTB\ZTB /XT /ZP"

START "/N /B ""Vmodem by Ray Guinn"" C:\SIO\VMODEM.EXE" CALL SYSSLEEP 3

CALL DIRECTORY "C:\BELFRY"

START "/WIN /DOS /B NODE4.BAT" CALL SYSSLEEP 3

START "/WIN /DOS /B NODE5.BAT" CALL SYSSLEEP 3

START "/WIN /DOS /B NODE7.BAT"

/* Next line is for the REXX startup version. Do not use with CONSOLE.EXE. START "  /B ""ftpServer"" /PGM C:\BELFRY\StartftpServer.cmd" */

START "/WIN /B /C /PGM C:\BELFRY\StartftpServer.cmd"

START "/WIN /B /C ""Apache/2 WebServer"" /PGM C:\BELFRY\APACHE.CMD D:\APACHE D:\APACHE\SRC"

/* Give the CONSOLE.EXE sessions enough time to do their stuff before letting Move_It move them */ CALL SYSSLEEP 2

START "/WIN /B /C ""Move_It"" /PGM C:\WMOVES\MOVE_IT C:\WMOVES\1.WMO"

/* SWITCHTO.EXE switches, to the foreground, a process which can be listed on the  Window List. Process name MUST be spelled correctly! */

SWITCHTO.EXE """Apache/2 WebServer"""

EXIT

Sample code for Apache.cmd

/* APACHE.CMD                   */ /* Creation date: 06-Sep-99 ALS */ /* Revision date: 26-Mar-00 ALS */ /* Procedure to delay the startup of Apache until logon to the server and mapping of shared resources has occurred. This is necessary for two reasons: OS/2 logon and resource mapping requires about 40 seconds on a test box, and Apache/2 v1.3.6 will shut down immediately if it cannot find the content directory. */

/* Input: Name of Apache/2 'root' directory; Name of Apache/2 daemon exe directory; (optionally) Name of Apache/2 daemon file

/* Dependencies: C:\CONSOLE\CONSOLE.EXE to resize the client window. (but it will still start Apache/2 OK, if CONSOLE.EXE is not found)

/*****************************************   vars definitions ApacheRootDir    =  Name of Apache/2 'root' directory ApacheExeFileLoc =  Name of Apache/2 daemon exe directory ApacheExeFileName = Name of Apache/2 deamon exe ConsoleExeFileLoc = Name of CONSOLE.EXE exe directory ConsoleExeFileName = Name of CONSOLE.EXE name ConsoleWidth      = Width of resized CMD window, in pixels ConsoleHeight     = Height of resized CMD window, in pixels arg.1 arg.2 arg.3      Command line input parameters row column     Cursor positioning vars Counter    Attempts at changing drive/directory counter var CurDir     holds temporary return value to compare current directory with reset directory attempt(s) rc         generic return code var MaxCount   Maximum number of retry attempts

/* Global variables */ MaxCount = 360 /* three minumtes default */ ConsoleExeFileLoc = "C:\CONSOLE" ConsoleExeFileName = "CONSOLE.EXE" ConsoleWidth = 550 ConsoleHeight = 175

/* Load utilities */ CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' CALL SysLoadFuncs

Main: /* parse the command line arguments */ PARSE ARG arg.1 arg.2 arg.3 IF (ARG = 0) THEN CALL Usage "(ALL of them!)" ELSE IF (LENGTH(arg.1) < 1) THEN CALL Usage 1 ELSE IF (LENGTH(arg.2) < 1) THEN CALL Usage 2 ELSE IF (LENGTH(arg.3) < 1) THEN ApacheExeFileName = 'httpd.exe' ELSE ApacheExeFileName = arg.3 ApacheRootDir = arg.1 ApacheExeFileLoc = arg.2

/* convert any forward slashes to backslash */ ApacheRootDir = TRANSLATE(ApacheRootDir,'\','/') ApacheExeFileLoc = TRANSLATE(ApacheExeFileLoc,'\','/')

/* remove trailing backslash */ IF (SUBSTR(ApacheExeFileLoc,LENGTH(ApacheExeFileLoc),1)='\') THEN ApacheExeFileLoc = SUBSTR(ApacheExeFileLoc,1,LENGTH(ApacheExeFileLoc)-1)

/* move cursor one line down, so the following text is not obscured by the, "OS/2     Ctrl+Esc = Window List       Type HELP = help" line later */

/* resize window */ CurDir = DIRECTORY(ConsoleExeFileLoc) IF (TRANSLATE(CurDir) = TRANSLATE(ConsoleExeFileLoc)) THEN /* if it was, then check that the target file exists */ DO       rc = SysFileTree(ConsoleExeFileName,Found,FO,,) IF ( Found.0 <> 0) THEN /* file found, run Console */ ConsoleExeFileLoc"\"ConsoleExeFileName" -p,,"ConsoleWidth","ConsoleHeight" -oa" ELSE /* error: file not found */ DO           SAY SAY "Directory """||ConsoleExeFileLoc||""" was found successfully, but the " SAY "file, """||ConsoleExeFileName||""", was not found." RETURN END /* ELSE */ END /* IF (Found.0 <> 0) */ ELSE /* Directory not found */ SAY "Directory """||ConsoleExeFileLoc||""" was not found."

SAY /* place explanatory text */ CALL CHAROUT STDOUT,"Attempting to find "|| ApacheExeFileLoc || "\" || ApacheExeFileName SAY CALL CHAROUT STDOUT,"Attempt No. 1" PARSE VALUE SysCurPos WITH Row Column Column = Column -1 Counter = 1 CurDir = DIRECTORY DO WHILE (CurDir <> ApacheExeFileLoc) IF (Counter = MaxCount) THEN CALL Exit1 CurDir = DIRECTORY(ApacheExeFileLoc) /* check to see if the drive/directory was successfully changed to */ IF (TRANSLATE(CurDir) = TRANSLATE(ApacheExeFileLoc)) THEN /* if it was, then check that the target file exists */ DO       rc = SysFileTree(ApacheExeFileName,Found,FO,,) IF ( Found.0 <> 0) THEN /* file found, move along */ LEAVE ELSE /* error: file not found */ DO           SAY SAY "Directory """||ApacheExeFileLoc||""" was found successfully, but the " SAY "file, """||ApacheExeFileName||""", was not found." RETURN END /* ELSE */ END /* IF (Found.0 <> 0) */ call SysSleep 1 CALL SysCurPos Row, Column CALL CHAROUT STDOUT, Counter Counter = Counter + 1 End /* DO WHILE (CurDir <> ApacheExeFileLoc) */

/* start the program */ SAY SAY SAY "Starting program on "||DATE||" "TIME /* START "/N "||"""Apache/2 v2.0 beta, WebServer"" /PGM "||ApacheExeFileLoc||"\"ApacheExeFileName||" -d "||ApacheRootDir ApacheExeFileLoc||"\"ApacheExeFileName||" -d "||ApacheRootDir EXIT

Usage: PROCEDURE SAY "Error: argument "ARG(1)" missing." SAY SAY "Usage: APACHE rootdir fileloc [filename]" SAY "where" SAY "rootdir = the Apache/2 program ""root"" directory" SAY "fileloc = the directory where the Apache/2 daemon resides (typically named"  SAY "          httpd.exe)" SAY SAY "(optionally, if the Apache/2 daemon is not ""httpd.exe"")" SAY "filename = file name of the Apache/2 daemon." SAY "          The filename extension is required." SAY SAY "Example: APACHE d:\Apache d:\apache\bin webserver.exe" EXIT /* end Usage: and end program */

Exit1: PROCEDURE SAY SAY "Maximum number of retries has occurred . . . exiting." SAY EXIT /* end Exit1: and end program */ 

Sample code for StartftpServer.cmd
 rem ********************************** rem STARTftpServer.cmd rem Created: 26-Mar-00 ALS rem Starts up ftpServer with notes in the title bar on how to properly shut it down rem rem This version is for use with CONSOLE.EXE, which will properly size rem a CMD.EXE window. rem **********************************

rem For some reason, Warp4 w/LS installed over it, requires that I CD to \console and *then* rem run CONSOLE.EXE. Console will run but will not do anything, if run on a pathed command line.

cd \console CONSOLE.EXE -p,,610,135 -t"ftpServer: Press 'G' for Gradual shutdown, 'Q' for Quick" c:\ftpserver\ftpd.exe

rem EXIT is needed to close this window. exit 

Revision History
Install List Revision History:

30May2013 30Apr2013 02-Sep-01 26-Mar-00
 * Corrected email link to WMoves etc. x2.
 * Fixed up HTML to validate properly; no content change.
 * Added note to top about the "stock" method to have W4 remember window sizes & positions.
 * Converted (somewhat) to my standard CSS.
 * Initial release