I. Window Routines ChangeAttr FillW SetViewP CloseW InitW SetViewW CloseLastW Int3 SwapAttr CGA OpenW Scrollx DebugW ReadScreen GScroll8 DefBorder SaveW II. Print routines Printt PrintW Lokate Prnt PrntW Kolor PrintMain III. Notes Arrays Files Segments Attributes Lockups TR,LC,BR,RC Declare.Bas System requirements =========================================================================== If you will, let me know how successful this program has been. James A. Paisley 10690 Allen Rd NW Washington C.H.,Oh 43160 Name _________________________________________ Address __________________________________________ __________________________________________ I have version________2.0__Jan 1989_______________ Enclose $2 if you want the source code. I would appreciate having someone supply the code to convert single- and double-precision numbers to asc strings or long integers so I could print them. Jan 89 =========================================================================== I. Window Routines =========================================================================== ChangeAttr (attr) Changes all the attributes on the screen to a given value. =========================================================================== CloseW (segment,TR,LC,BR,RC) Closes a window opened by either SaveW or OpenW. The window may be moved or copied to a new location on the screen by changing the coordinates. =========================================================================== CloseLastW () Closes the most recently opened window. The coordinates and segment of the last ten windows are saved on a revolving stack so it may be called up to ten times. CloseW will bump the last one off the stack. OpenW and SaveW add one to the stack (even if the segment is 0) Example: redim b(1000): CALL SaveW(VARSEG(b(1)), 1, 1, 24, 80) call OpenW(2,&h30,0,1,40,10,60) call CloseLastW call CloseLastW =========================================================================== CGA () Changes the video segment to B800h for use with the color graphics adapter. This is the default value. =========================================================================== DebugW () Prints information about the current values for QB4Windows parameters. =========================================================================== DefBorder(x$) Allows the user to define a new border. X$ is a string of nine characters for the top left corner top row top right corner left side middle bottom left corner bottom line bottom right corner DefBorder may also be used to fill an area of the screen with a character. For example, to fill the entire screen with periods: Call DefBorder (".........") call OpenW(4,attribute,0,1,1,25,80) =========================================================================== FillW ( n , varptr(a$(L) ) Fills a window with strings from an array. The coordinates used are those of the window most recently opened with OpenW or SaveW. The first n characters of each string are skipped, so increasing n has the effect of scrolling to the left. Increasing L has the effect of scrolling up. Example: call OpenW(2,7,0,2,20,10,40) redim a$(500) [ assign strings to a$() ] n=0:L=1 call FillW(n,varptr(a$(L)) The sub FILL in WDemo.bas demonstrates using FillW to view a file and the main menu uses it to fill a menu box. This will not work with an array of fixed length strings. =========================================================================== InitW (RR%, CC%) Resets all the parameters for windows to their default values. This should be called at the beginning of a program. If the program is halted and run again, the defaults may be incorrect. This call passes the integer variables RR and CC so that Lokate, Prnt and PrntW can find them. The call to InitW is included in Declare.Bas. =========================================================================== int3 () calls interrupt 3 =========================================================================== MonoChrome Changes the video segment to B000h for use with the monochrome adapter. =========================================================================== OpenW (border, attribute, segment, TR, LC, BR, RC) Saves the window like SaveW. In addition, the area in the window is blanked and a border drawn around it. The values for border are: 0 no border 1 single line 2 double line 3 double line at top and bottom, single line on sides 4 User defined (by Call DefBorder) No border is used if the box has less than 3 lines or columns If the segment passed is 0 the data is not saved and you do not have to dimension an array. This is used to draw a box, set up coordinates for FillW and erase the window. Example: call OpenW(2,7,0,2,20,10,40) The sub Machine in WDemo.bas demonstrates using OpenW to draw a black rectangle. =========================================================================== ReadScreen (a$, row, column) Reads text from the screen into a string variable. The first character is at (row,column) and the number read equals the length of the string. Usage: a$ = SPACE$(n) : call ReadScreen (a$, row, column) =========================================================================== SaveW (segment, TR, LC, BR, RC) Saves the contents of the screen inside the window defined by Toprow,left column,bottom row and right column into a dynamic numeric array. The coordinates of the window are pushed onto the stack for CloseLastW. The display on the screen is not altered. The contents of the window may be restored by calling CloseLastW or CloseW. If 0 is passed as the segment, the contents of the window are not saved, although the data for the window is still pushed onto a stack. This is used to set up the coordinates of a window for FillW or Printx. Example to define a window but not save it: call SaveW(0,1,1,24,80) : PrintW a$, 7, 1, 1 An example to save the entire screen: Rem $DYNAMIC REDIM a%(2000):' sets aside 4000 bytes of memory call SaveW (VARSEG(a%(1)),1,1,25,80) =========================================================================== SetViewPage (page) Defines the active page. Page is a number from 0 to 3. The default value is 0. Typical usage is: SCREEN , , page,page : SetViewPage page =========================================================================== SetViewW Defines the active portion of the screen. Similar to Basic's VIEW PRINT [topline TO bottomline] statement except that columns is also a parameter. All the routines in QB4Windows operate within these boundaries except ChangeAttr and SwapAttr. Use it to lock out the top or bottom line when that line is used for a menu. The default values are 1,1,25,80 for all 4 pages. =========================================================================== SwapAttr () Swaps the foreground and background attributes for all the characters on the screen, stripping off any blinking bits. =========================================================================== ScrollU ( attribute, lines, tr, lc, br, rc) ScrollU,ScrollD,ScrollL,ScrollR scroll the window up,down,left or right. The information scrolled off the screen is lost, the lines or columns scrolled onto the screen are blanked using the specified attribute. example ScrollD(7,2,1,1,25,80):'scrolls the entire screen down two lines, 'top 2 lines are blanked with attribute 7 If the number of lines or columns to scroll is greater than the number in the window, the entire window is blanked. =========================================================================== GScrollL8 (TR, LC, BR, RC) Scrolls left 8 pixels in graphics mode (screen 1 and screen 2). tr and br are numbers from 0 to 199 lc and rc are from 0 to 639 and are rounded down to the nearest multiple of 8. there is no error checking, wierd values could make it hang not thoroughly tested =========================================================================== II. Print Routines =========================================================================== Printt a$,attribute, Row,Column print a string at row,column within the boundaries of SetViewPage PrintW a$,attr,Row,col print a string at row,column within the boundaries of the currently active window (the window most recently defined by OpenW or SaveW). Row and Col 1,1 is the top left corner of the screen. However, since these are automatically adjusted to fit within the window, if you call PrintW with row and col equal to 1, they will be changed to the top left corner of the window. If row and column are integer variables, after the call they will be changed to point to the next character after the string printed. Use this to print one string after another: Printt "The total is ",7, r%, c% : Print total:'prints total at 1,14 Also use it to make the cursor visible: Printt "Hello", 7, r%, c% : Locate r%, c%,1 If row and col are integer variables, they may have any name. If they are called RR and CC they may be defined by Lokate. Example: Lokate 5,10 Printt a$, 7, RR, CC If you don't care what r and c are after the call, they may be whole numbers, expressions or constants. They may not be single precision numbers or any variable other than an integer. Example: Printt "hello", 7, 1, 1 PrintW "hello", 7, r% + 1, 4 * 8 =========================================================================== Prnt A$ PrntW A$ Same as Printt and PrintW, except that the attribute is passed by Kolor and the string is printed at RR, CC. After the call RR and CC are changed to the next space after the string. These two expressions do the same thing: Lokate x, y : Prnt a$ : Locate RR, CC Locate x, y : Print a$; QBasic uses DOS interrupt 10h to set the cursor when LOCATE is called, but does not read the cursor location when PRINT is called, so it is not easy for QB4Windows to move the cursor. So I have used RR and NN to pass the coordinates back and forth. =========================================================================== Lokate x, y This sets the values of RR and CC. RR and CC are defined as common shared integers in Declare.bas. This is the same as saying RR = x: CC = y. =========================================================================== Kolor foreground, background Sets the color for Prnt and PrntW =========================================================================== CR$ If a string printed with Printt, PrintW, Prnt or PrntW is appended with a chr$(13) a carriage return\linefeed is executed. The line will be erased to the end and the cursor drops to the beginning of the next line, scrolling if necessary. This is equivalent to PRINT a$. Example: CR$ = Chr$(13): Lokate 1,1 Printt "Hello" + cr$, 7, RR, CC : Locate RR, CC, 1 'The cursor will be at 2, 1 =========================================================================== EOL$ Appending the string with chr$(10) is the same as chr$(13) except that scrolling is suppressed. Use this to print on the last line of the screen and erase to the end of the line without causing the screen to scroll. RR will go out of bounds instead. Example: Lokate 25,1 : EOL$ = chr$(10) Prnt "Hello" + EOL$ 'prints "Hello" and 75 blank spaces 'Now RR=26 and CC=1, so you may not use LOCATE RR, CC Prnt "Goodby" 'since RR is > 25, now the screen scrolls up and Goodby ' is printed at 25, 1 =========================================================================== Prnt and Printx are not much faster than Basic, but don't have some of its quirks. For example, Locate 24,79:Print "abc"; :' will scroll the top 24 lines and print at 24,1 Locate 25,79:Print "abc"; :' will also scroll the first 24 lines and print at 24,1 a$="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" :' 41 or more char locate 1,1:Print a$;a$; :'the second a$ will print at 2,1 =========================================================================== PrintMain a$, attr, row, col, TR, LC, BR, RC This is the main print routine with all the paramaters. III. Notes =========================================================================== Arrays ================================================================= | THE ARRAY MUST BE DYNAMIC. Use the $DYNAMIC metacommand at the | | beginning of the program or sub in which the dim or redim | | statement occurs. You may also force the array to be dynamic | | by using variables for the dimensions. This is most important | | when creating .exe files because they default to static arrays. | | The editor\compiler defaults to dynamic. | | Example: $dynamic | | n=200:redim array%(n) | | Call OpenW(2,7, varseg(array(1)), r,c,rr,cc) | | Putting 'REM $DYNAMIC' at the beginning of a program does NOT | | carry over to subs so put it in each SUB or FUNCTION. Using a | | variable for the array dimensions [ ex. dim a(x) instead of | | dim a(400) ] will also force the array to be dynamically | | allocated. | ================================================================= It doesn't matter if you pass the segment of array(1) or array(0) since they both have the same segment. =========================================================================== Attributes I have a mono monitor and for normal text use COLOR 7,0 and an attribute of 7. For inverse text I use COLOR 0,7 and an attribute of &h70. Basic: Windows equivilent: Color 7,0 Attr% = &h7 Normal Color 15,0 Attr% = &hF Bright Color 0,7 Attr% = &h70 Reverse | |__background ||_____Forground Color |_______foreground |_________Background Color =========================================================================== Declare.Bas There are three parts to Declare.bas 1) A quick reference for all of these calls. Use Alt-V, L (View menu, List included lines) to see this file. It will be listed just after the $INCLUDE statement. 2) All the delcare statements for QB4Windows. Most of these include BYVAL declarations, allowing numbers to be expressed in just about any form and automatically converted to integers. 3) Two statements: COMMON SHARED RR AS INTEGER, CC AS INTEGER InitW RR, CC Since Lokate and Prnt need the addresses of RR and CC, these are declared as global variables, then passed via InitW. The statement REM $INCLUDE:'Declare.bas' should be included in every module of a program. =========================================================================== Files included: MakeLib.bat creates the .QLB and .LIB files from object files This is already done, included in case you want to link other object files to QB4Win10.obj Demo.bat runs the demo program QB4.bat invokes QuickBasic with the window library The /b in Demo.bat and QB4.bat specifies monochrome monitor, you may want to delete it if you have color. ReadMe short note WDemo.bas demo. This includes the module WDemo2.bas, so if you load it from the file menu, use 'Open File' instead of 'Load File'. Requires three files:WDemo.bas, WDemo2.bas, and WDemo.MAK Declare.bas An include file containing a quick reference, declare statements, and two program statements to initialize QB4windows. W.doc documentation MyLib.QLB,MyLib.LIB library files containing the windows program. To use the windows you must invoke QB with the /L Mylib option. QB4Win20.obj QuickBasic Windows Version 2.0 object file. =========================================================================== LOCK UPS If your computer locks up or loses data, check the following: Saved to an array that was too small. Passed the wrong segment. Used a static array. Did not include the proper DECLARE SUBs. I suggest you copy them from this file to any program that uses them. Did not pass a value BYVAL and as an integer. The DECLARE statements will convert any kind of number to an integer, pass it as a value, and check for the correct number of arguments. For example, Call OpenW(b,&h70,varseg(x(1)),a%,b!,c, 79.64) works even though the numbers are not all integers. Remember, it is up to YOU to protect valuable data and programs. =========================================================================== =========================================================================== Segments To provide memory to store the data under a window, dimension a numeric array. The segment of that array is passed to OpenW and SaveW and the data under the window is copied to the memory reserved for the array. Each character on the screen takes 2 bytes (1 for text, 1 for attribute). The maximum required is 4000 bytes. Redim a!(1000) or a%(2000) will provide 4000 bytes. To be exact, lines = BR - TR + 1 Cols = RC - LC + 1 redim a%( lines * cols ) =========================================================================== TR, LC,BR,RC, RR,CC TopRow and LeftColumn define the top left corner of a window, BottomRow and RightColumn define the bottom right corner. When a call is made using window coordinates, Qb4Windw first checks these arguments. If TR or BR are less than the top of the screen as defined by SetViewW, they are increased. If too large they are decreased. Same for Columns. Then if BR is less than TR, they are swapped. Thus no fatal errors are possible. If the row for Printt or Lokate is less than the top line it is moved to the top line. If column is less than the left column it is moved over to the first column If the column is greater than the right column, RR and CC are moved to the start of the next line. If RR is greater than the last line, the window is scrolled up a line and RR and CC are set to the beginning of the last line. Examples: Lokate 0,0:PrntW a$ ;prints at the top left of the window Lokate 26,1:Prnt a$ ;Scroll, print at 25,1 ============================================================================== System Requirements: IBM PC CGA (color graphics adapter) QuickBasic Version 4 80 column text mode ===========================================================================