MULTI-LEVEL VIRTUAL WINDOWS USER'S GUIDE Version 2.0 February 1, 1989 Conversion to Turbo C by Jordan Gallagher / Wisdom Research Copyright (C) 1989 Eagle Performance Software All Rights Reserved. _______ ____|__ | (tm) --| | |------------------- | ____|__ | Association of | | |_| Shareware |__| o | Professionals -----| | |--------------------- |___|___| MEMBER WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 T A B L E O F C O N T E N T S 1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . . 4 Features . . . . . . . . . . . . . . . . . . . . . . 4 Using the Manuals . . . . . . . . . . . . . . . . . . 4 Licensing . . . . . . . . . . . . . . . . . . . . . . 5 Customer Service . . . . . . . . . . . . . . . . . . 5 ASP . . . . . . . . . . . . . . . . . . . . . . . . . 6 2. GETTING STARTED . . . . . . . . . . . . . . . . . . . . 7 Distribution Files . . . . . . . . . . . . . . . . . 7 Demonstration . . . . . . . . . . . . . . . . . . . . 7 3. PROGRAMMING WINDOWS . . . . . . . . . . . . . . . . . . 8 Basic Programming . . . . . . . . . . . . . . . . . . 8 Window Definitions . . . . . . . . . . . . . . . . . 10 Basic Routines . . . . . . . . . . . . . . . . . . . 10 makewindow Parameters . . . . . . . . . . . . . . . . 11 Window Modes . . . . . . . . . . . . . . . . . . . . 12 Defaults . . . . . . . . . . . . . . . . . . . . . 12 setwindowmodes . . . . . . . . . . . . . . . . . . 13 List of Modes . . . . . . . . . . . . . . . . . . . 13 Shadows . . . . . . . . . . . . . . . . . . . . . . 13 ZOOMMODE . . . . . . . . . . . . . . . . . . . . . 13 RELMODE . . . . . . . . . . . . . . . . . . . . . . 13 PERMMODE . . . . . . . . . . . . . . . . . . . . . 14 SEETHRUMODE . . . . . . . . . . . . . . . . . . . . 15 HIDDENMODE . . . . . . . . . . . . . . . . . . . . 15 VIRTUALMODE . . . . . . . . . . . . . . . . . . . . 16 Cursor Modes . . . . . . . . . . . . . . . . . . . . 17 4. WRITING TO WINDOWS . . . . . . . . . . . . . . . . . . 19 Direct Writing . . . . . . . . . . . . . . . . . . . 19 Cursor and EOS Positioning . . . . . . . . . . . . . 19 Clearing . . . . . . . . . . . . . . . . . . . . . . 20 Scrolling . . . . . . . . . . . . . . . . . . . . . . 21 Line Drawing . . . . . . . . . . . . . . . . . . . . 22 Custom Routines . . . . . . . . . . . . . . . . . . . 23 5. VIRTUAL WINDOWS . . . . . . . . . . . . . . . . . . . . 25 Application . . . . . . . . . . . . . . . . . . . . . 25 Programming . . . . . . . . . . . . . . . . . . . . . 25 6. WINDOW MANAGEMENT . . . . . . . . . . . . . . . . . . . 29 Access Methods . . . . . . . . . . . . . . . . . . . 29 Display Control . . . . . . . . . . . . . . . . . . . 29 Write Control . . . . . . . . . . . . . . . . . . . . 30 Window Modes and Flags . . . . . . . . . . . . . . . 31 High Speed Screen Design . . . . . . . . . . . . . . 31 Multiple Video Pages . . . . . . . . . . . . . . . . 32 Multi-tasking Environments . . . . . . . . . . . . . 32 2 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 7. DATA MANAGEMENT . . . . . . . . . . . . . . . . . . . . 34 Data Allocation . . . . . . . . . . . . . . . . . . . 34 Structure Handling . . . . . . . . . . . . . . . . . 34 8. OTHER MODULES . . . . . . . . . . . . . . . . . . . . . 37 GOOF Module . . . . . . . . . . . . . . . . . . . . . 37 Utility modules . . . . . . . . . . . . . . . . . . . 37 9. COMPILING THE SOURCE CODE . . . . . . . . . . . . . . . 38 APPENDIX A: Application Products . . . . . . . . . . . . . 39 APPENDIX B: Credits . . . . . . . . . . . . . . . . . . . 41 3 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 1. I N T R O D U C T I O N FEATURES Welcome to WNDWC multi-level virtual windows! You have just obtained a copy of the highest performance window utilities available today for Turbo C 2.0 (TC2) and Turbo Assembler. Both novice and professional programmers will appreciate these simple and very powerful utilities that give you full window control and management in all text modes. Here are some of the features you will discover: . Uses the powerful direct screen writing routines of QWIKC20. . Up to 254 fixed or virtual windows can be on the screen at one time. . Extremely high-speed virtual screens in RAM. . Virtual windows are fully updated even if covered! . Virtual windows have virtual titles. . Fully supported hidden windows saved in RAM. . Fully supports all video pages. . Adjustable-rate moving, resizing, and scrolling. . All windows can be randomly accessed. . 28 window-relative writing routines. . 15 different border styles with shadows. . Full line drawing functions. . Full cursor mode control for each window. . Writes in all text modes and column modes. | . Writes direct to multi-tasking video buffers (MTVB). . Only 13k bytes of code if all 69 utilities are used. . Used in all other Eagle products. WNDWC is a very high performance window library with high speed and tight code. All types of windows, including fixed or virtual, hidden or shown, work compatibly in the same package. With WNDWC, you can choose the abso- lute writing routines of QWIKC, the window-relative writing routines of WNDWC, or even customize your own. USING THE MANUALS Disk Based Guides - The manuals for WNDWC are on disk so that you can conveniently scan for the topic you are seeking. You can do this with any list or search utility with a search function. You can also make a printed copy. If you have not already printed this manual, refer to the READ.ME file for instructions. At the present time, no bound manuals are being offered with registration. User's Guide - This manual, the one you are reading now, assumes that as a programmer you are already familiar with Turbo C 2.0, and that you have a working knowledge of your disk operating system (DOS). It also assumes that you are familiar with QWIKC screen utilities in QWIKC20.ARC. This Chapter 1, Introduction Page 4 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 manual will provide the basic instructions for creating and managing multi-level windows. You can even copy examples from this file direct to the Turbo C editor for testing. Reference Guide - This manual describes in detail all functions and variables used in WNDWC. It is alphabetically arranged for easy access in a format similar to the TC2 manual. Use this manual when you have become familiar with the basic principles in the User's guide. LICENSING Registration - These routines and the documentation have been released for distribution as Shareware. You have been given the chance to sample the full capability of WNDWC without risk! If you find that WNDWC is a valuable tool, then you are expected to register. You will find a reasonable licensing schedule found in LICENSE.ARC to meet private or commercial needs. When registering, be sure to specify the version for Turbo C (such as 2.0) you wish to receive. Source Code - All registered users will receive source code when the signed license agreement is returned with the registration. In order to link the WNDWC routines with your program, the WNDWC source code must be compiled and put into a library (.LIB) file. This is not done for you, since you may have certain compiler options you wish to use. See Appendix X for information on compiling the source code. CUSTOMER SERVICE If you have questions, comments, or suggestions, the Eagle can be contacted by four means - (1) CompuServe, (2) telephone, (3) The Eagle BBS, or (4) mail. CompuServe - The most dependable way to contact the Eagle is through CompuServe. Jordan Gallagher has written the TC2 version of WNDWC. He can be contacted on the Borland Forum by typing GO BPROGB from the CompuServe main menu. You will enter the forum for Turbo C. You can contact Jordan with his PPN number of 73557,2342. Messages can also be left through EasyPlex. Telephone - Jordan can also be reached by phone at (214) 539-7855 on weekdays and Saturday from 9:00 a.m. to 8:00 p.m CST. The Eagle BBS - You can also contact us on our 24-hour BBS at (214) 539-9878, 1200/2400 N81. Mail - For registration or problems, please write: Eagle Performance Software TC/TP products P.O. Box 292786 Lewisville, TX 75029-2786 We also provide identical Turbo Pascal products! Chapter 1, Introduction Page 5 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 In your written request for resolving problems, be sure to include: . A 5 1/4 inch diskette of compilable source code of the problem. . The Eagle product and version number. . The computer make and model. . The type of video card, video monitor and keyboard. ASP WNDWC is a Shareware program conforming to the standards of the Association of Shareware Professionals (ASP). You can get more information about ASP by writing to: Association of Shareware Professionals P.O. Box 5786 Bellevue, WA 98006. | This program is produced by a member of the Association of Shareware | Professionals (ASP). ASP wants to make sure that the shareware principle | works for you. If you are unable to resolve a shareware-related problem | with an ASP member by contacting the member directly, ASP may be able to | help. The ASP Ombudsman can help you resolve a dispute or problem with an | ASP member, but does not provide technical support for member's products. | Please write to: | | ASP Ombudsman | P.O. Box 5786 | Bellevue,WA 98006 | | or send a CompuServe message via EasyPlex to ASP Ombudsman 7007,3536. Chapter 1, Introduction Page 6 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 2. G E T T I N G S T A R T E D This section will acquaint you with the files on the distribution disk and show you a couple of demonstrations to quickly see what WNDWC can accomplish. DISTRIBUTION FILES In this version, WNDWC20.ARC contains: READ .ME : Note of printing instructions for manual. KEYBC20 .LIB: Keyboard library for WNDWMGR.C demo. GOOF .C : Module to display errors. QWIKC20S.LIB: Library for quick screen writing. WC20VAR .C : This file is the actual source code which lists all of the variables used in WNDWC. WNDWC20S.LIB: This library has the full power of all of its capabilities. Note: WNDWC20S.LIB was compiled with the current settings for MAXWINDOW, MAXVIRTUALWINDOW, MAXPAGEUSED, and windownames, as defined in WNDWC20.H. In order to make any changes in the data requirements, the complete source code will be required. WNDWC20 .DOC: This document - a user's guide to WNDWC. WNDWREF .DOC: WNDWC Reference Guide document covering each routine and variable in detail. WNDWDEMO.C : Demo of WNDWC and QWIKC which shows screen design performance. WNDWMGR .C : Demo of full window management. LICENSE .ARC: ARC file containing license agreement and ordering details. DEMONSTRATION To get the feeling of the speed and features of WNDWC, let's run the demonstration programs that came with the utilities. Do the following steps: 1. From Turbo C, set your memory model size to "Small". 2. Build and run the project file WNDWDEMO.PRJ to get a feel for screen design performance and speed. | 3. If you are running programs in a multi-tasking | environment, instruct the environment that you are NOT | writing direct to the screen. Also set text pages to 2. 4. Build and run the project file WNDWMGR.PRJ to get a feel for true virtual windows and window management. (Note: You may need to exit the Turbo C environment and run WNDWMGR.EXE from DOS.) Press Alt-1 to access the bottom window. With Scroll Lock on, it can be moved, resized and scrolled. Chapter 2, Getting Started Page 7 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 3. P R O G R A M M I N G W I N D O W S This sections will get you familiar with the basics of window programming by starting with very basic windows and then taking you step-by-step through the variety of options and modes that are available. BASIC PROGRAMMING Project File - All example programs in this manual assume that QWIKC20S.LIB is in the project file, and that your memory model size is set to "Small". Your first project file may look like this: mywndw1 qwikc20s.lib Exiting the Examples - There is a getch() command at the end of most of the example programs. This gives you time to look at the output. After running the example, simply press a key to return to Turbo C. First Program - Let's write a short program to see how simple it is to write with WNDWC. While in the TC editor, enter the following code: EXAMPLE 1: Your first window ---------------------------------------------------------------------- #include #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); /* Initialize and clear window */ makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, AWINDOW ); wwritec( 7, "Making windows is easy!" ); getch(); } Save the file and make sure that Turbo C is configured for the Small model. Create a project file for it, then compile the project and run the program. You can then see these results: . The base window is cleared with black on light gray attributes. . The window is placed at absolute row 5, column 20 . The window size is 15 rows high and 40 columns wide. . The window text color is white on a blue background. . The window border color is cyan on a blue background. . The border is the single line width style. . The window name is AWINDOW. . The message was centered on window-relative row 7. Row/Col vs. X/Y - You probably noticed that the row parameter is first and the column parameter is second. Since WNDWC is entirely for text modes, it Chapter 3, Programming Windows Page 8 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 is more intuitive to specify the row first and the column second just like any word processor. The X/Y scheme is better suited for graphics. Attributes - Notice that our example uses the macro BLUE_BG. WNDWC uses QWIKC which provides eight convenient background color constants to use along with Turbo C's 16 foreground colors in CONIO.H. The same names are used, but the "_BG" suffix is added: BLACK_BG RED_BG BLUE_BG MAGENTA_BG GREEN_BG BROWN_BG CYAN_BG LIGHTGRAY_BG These allow WNDWC to make the most of Turbo C's macros. By simply adding the foreground and background macros together, the compiler saves the result as a single word. And, by simply reading the makewindow statement, what you see is what you get (WYSIWYG). Protected Underlay - That first program was pretty simple, wasn't it? Several things happened that you probably didn't notice. The area under the window, called the underlay, was actually saved. Later on when the window is no longer needed, it can be removed by restoring the underlay. This makes it just like a sheet of paper on a desk. Let's add some statements to show if the underlay is really protected. In addition, let's add a little more pizzazz to the window by adding a shadow, zoom effect, and a title: EXAMPLE 2: Protected underlay ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); wwritec( 12, "Base Window" ); setwindowmodes( ZOOMMODE+SHADOWRIGHT ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, AWINDOW ); titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " My First Window " ); wwritec( 7, "Making windows is easy!" ); delay(2000); removewindow(); /* Remove the window and restore underlay. */ getch(); } Did you see that the message "Base Window" was still there? In fact the entire underlay was protected because it was saved in the heap while we were writing on the CRT. In addition: . The window modes controlled the shadow and zoom effect. . The title is placed on the top border, left justified, with yellow on blue attributes. . The "Base Window" message was centered on window-relative row 12. Chapter 3, Programming Windows Page 9 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Basic Principles - Was that simple enough for you? Well, you'll be glad to know that you have already tried all the basic principles to making windows. And the rest is just that easy. But you haven't seen anything yet. WINDOW DEFINITIONS Window - Just what is a window anyway? It's an area reserved on the screen as a frame of reference to write text. Right on the screen, the power of this program allows you to move, rearrange, hide, move, and resize, without losing any data. View - In virtual windows, this window text area is also called the view. More about virtual windows is explained later. Border - The border is the lines surrounding the window or view to clearly separate the window contents from other areas of the CRT. However, a window does not require a border. Title - Conveniently, a window can be titled on the border - either the top or the bottom. The title area extends the full length of the window not including the two vertical borders. The title is written at a border- relative location. If a window does not have a border, then the title area is just the top or bottom row of the window text area. Cursor - Each window has its own cursor location and mode (shape). Shadow - To give a window that off-the-screen appearance, a shadow can be added onto the outer edge of the window or window border. Generally Speaking - Throughout this document, the word "window" will loosely refer to all of the above parts as the full window. It should be understood that all writing to the windows uses coordinates relative to the upper left corner of the window text area which is (1,1) exclusive of the border. BASIC ROUTINES Basic Routines - There are five basic functions that are fundamental to creating multi-level windows: initwindow - Initializes static data and pointers for the program. Also calls qinit. setwindowmodes - Determines what types of windows are made. makewindow - Creates the window. titlewindow - Places titles on the window. removewindow - Removes window from CRT and memory. initwindow - First, before any window functions are used, initwindow should be executed to initialize all global data for the entire program. It only needs to be done once. Chapter 3, Programming Windows Page 10 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 void initwindow( int wattr, int clearscr, char cursorok ); The initial base window has no border and wattr is the window attribute. You can optionally clear the window by passing clearscr as 1. The function initializes over 50 variables. For details, you can examine the source code. MAKEWINDOW PARAMETERS Declaration - The makewindow function actually makes the window on the screen. Let's take a look at its declaration: void makewindow( char row, char col, char rows, char cols, int wattr, int battr, int brdrsel, int windowname ); The function's parameters control location, size, attributes, border style, and window name. Notice that the size is expressed as rows/cols rather than another (row2,col2) coordinate. This makes it very easy to change the location without having to recalculate the size. | Self-Centering Window - There is a very simple method to self-center a | window on a screen - simply set the appropriate Row and/or Col parameter to | 0. If Row is 0, the window will be centered to the current height of the | screen. Likewise, if Col is 0, it will be centered horizontally. So | there's no need to calculate sizes! This also works for RELMODE which will | be discussed later. Attributes - wattr and battr are the attributes for the window text area and border, respectively. The attributes that are recognized are the same ones used in QWIKC - even SAMEATTR is supported. Border Styles - There are 15 different border styles that can be used for the border, including two custom borders and even no border at all. Here is the list of border macros from WNDWC20.H: NO_BORDER - No border at all. Just the text area. BLANK_BORDER - Blank character on all sides. SINGLE_BORDER - Single lines on all sides. DOUBLE_BORDER - Double lines on all sides. HDOUBLE_BORDER - Horizontal double lines. Single vertical lines. VDOUBLE_BORDER - Vertical double lines. Single horizontal lines. SOLID_BORDER - Solid box character on all sides. EVEN_SOLID_BORDER - Vertical solid box. Horizontal half box. THIN_SOLID_BORDER_1 - Half box on all sides. Squeezed horizontally. THIN_SOLID_BORDER_2 - Half box on all sides. Squeezed vertically. LHATCH_BORDER - Light hatch character on all sides. MHATCH_BORDER - Medium hatch character on all sides. HHATCH_BORDER - Heavy hatch character on all sides. USER_BORDER_1 - User defined border. USER_BORDER_2 - User defined border. All of the borders except the user borders are reserved for use in future Eagle products. USER_BORDER_1 and USER_BORDER_2 may be customized to your needs. Each border has 15 different parts for the line drawing set Chapter 3, Programming Windows Page 11 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 including tees and interior lines. Tip: Hatch Borders - Since MDA and VGA both use a 9x16 character cell size, the hatch characters (ASCII 176, 177, 178) are only 8x16 in a 9x16 cell. This unfortunately produces a horizontal gap between the characters not seen on the CGA. Be aware of the effect. Window Name - The name of each window should be different in order to uniquely identify the window for window management. But since our simple test program only displayed the window momentarily, the window name is not significant and did not need to be unique. So, the generic name AWINDOW was used. The name WINDOW0 is used to identify the initial base window which is the full CRT screen. WINDOW MODES Defaults - Without needing to specify anything, the window is created with several defaults. Let's see what they are: . Fixed size and placed absolute to the CRT. . Shown on the CRT. . The underlay is saved. . No shadow or zoom effect. . No virtual screen. . Cursor is turned on with the default cursor mode. . Window is cleared. . Moving and accessing is permitted. Well, if these are all defaults, then that means they can be changed. And they can. We've already found out how to add shadow and zoom. Let's try changing some others and see what happens. Type in and compile the following program: EXAMPLE 3: Different modes and a hidden window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); setwindowmodes( HIDDENMODE | ZOOMMODE | CURSOROFFMODE ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); wwritec( 12, "Where is it?" ); writetohidden( WINDOW1 ); /* Write to the hidden window. */ titlewindow( BOTTOM, RIGHT, YELLOW+BLUE_BG, " My Second Window " ); wwritec( 3, "Here it is ..." ); wbrdrh( 7 ); /* Add an extra horizontal border. */ wwritec( 10, "It was hidden!" ); delay( 2000 ); showwindow( WINDOW1 ); /* Put it back on the screen. */ delay( 2500 ); Chapter 3, Programming Windows Page 12 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 removewindow(); getch(); } When you run it, the window is immediately created. But instead we see the message "Where is it?". And to answer that question, the window was created in RAM instead of on the CRT. In addition, the code also wrote messages direct to the hidden window. The window remains hidden until it is called which we did with showwindow. Afterward, we removed it from memory with removewindow. I'll bet you didn't know that you have already done some writing to a virtual screen. That's right - the hidden window was a virtual screen! Pretty easy, huh? And it was done by simply setting a mode. setwindowmodes - This function can be used any time prior to makewindow. It only needs to be done once since the value is retained in windowmodes until changed again. List of Modes - Did you notice the zoom effect this time and that the cursor was turned off? Let's take a look at all the available modes: Mode Constant Description ------------- ----------------------------------------------- SHADOWLEFT Shadow on the left side SHADOWRIGHT Shadow on the right side ZOOMMODE Zoom effect on make, show and accesswindow CURSOROFFMODE Leaves cursor off for window RELMODE Window-relative frame of reference, no underlay PERMMODE Can't be moved or removed, no underlay SEETHRUMODE Doesn't clear screen inside window HIDDENMODE Create window as hidden VIRTUALMODE Create virtual window and screen NOHIDEMODE Ignores request to hide window NOACCESSMODE Ignores request to access window NOMOVEMODE Ignores request to move/resize window We've already seen what the first four can do. Let's check to see what the others can do. SHADOWLEFT/SHADOWRIGHT - When placed on the CRT, the window gets a shadow on either the left or right side as well as the bottom. For good human factors, it is recommended that the shadow only be used for the top window for clarity. Shadows are fully supported at any level for serial-access windows. (However, for random-access, the shadows are permitted, but if a window is pulled out from under it, the corners will not be updated at that moment.) Tip: Place windows with shadows correctly to prevent wrap-around. ZOOMMODE - When a window is created, shown, or accessed on the CRT with this mode, it produces a zoom effect. It is conveniently suppressed for hidden windows. RELMODE - This is the simplest of all modes. It enables you to set up a window within a window. It simply overwrites the window, but produces a handy window-relative frame of reference to draw borders, write text or whatever. It's a worry-free mode. To get out of RELMODE, you can simply Chapter 3, Programming Windows Page 13 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 switch to another window, or you can return to the parent window with removewindow. RELMODE is only temporary and no stats are saved. Let's modify the last example and try this out: EXAMPLE 4: RELMODE window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); setwindowmodes( HIDDENMODE | ZOOMMODE | CURSOROFFMODE ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); wwritec( 12, "Where is it?" ); writetohidden( WINDOW1 ); /* Write to the hidden window. */ titlewindow( BOTTOM, RIGHT, YELLOW+BLUE_BG, " My Second Window " ); setwindowmodes( RELMODE ); makewindow( 3, 4, 3, 32, SAMEATTR, SAMEATTR, HDOUBLE_BORDER, AWINDOW ); titlewindow( TOP, CENTER, SAMEATTR, " My Answer: " ); wwritec( 1, "Here it is ..." ); delay( 2000 ); showwindow( WINDOW1 ); /* Put it back on the screen. */ wwritec( 10, "It was hidden!" ); getch(); } Notice that the (row,col) location was relative to the parent window, WINDOW1. Even the title as well as the text was placed in RELMODE. Once the window was shown, the window coordinates and modes were restored to the parent window. The message appeared correctly on row 10 of the parent window. Notice also that we didn't bother to use removewindow since we were finished and wanted to take a closer look at what we created. PERMMODE - When creating your initial screen for a program, the underlay probably does not need to be saved. This mode enables you to create windows without saving the underlay so the screen is simply overwritten - perfect for initial screens by increasing speed and saving memory. All the window stats are still saved for future use. Keep in mind two rules for this mode. First, all PERMMODE windows must be the first ones created. And second, use discretion when accessing the window to make sure it is not covered by another window before writing to it. Let's try an example: EXAMPLE 5: PERMMODE window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 0, 0 ); /* No need to clear screen */ Chapter 3, Programming Windows Page 14 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 setwindowmodes( PERMMODE ); makewindow( 1, 1, 12, 80, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " Input Window " ); makewindow( 13, 1, 13, 80, WHITE+GREEN_BG, GREEN_BG, HDOUBLE_BORDER, WINDOW2 ); titlewindow( TOP, LEFT, YELLOW+GREEN_BG, " Output Window " ); wwrite( 1, 1, "Output data." ); accesswindow( WINDOW1 ); wwrite( 1, 1, "Input data." ); getch(); } Since we were designing the initial screen, the clearscr parameter in initwindow was set to 0. Did you notice that writing back to WINDOW1 was no problem? You've just had your first shot at window management! accesswindow will let you write to any window by name. But if removewindow is used on PERMMODE windows, the window record is simply dropped from the stack and the screen appears unaltered. SEETHRUMODE - If there is a portion of the current screen that needs to be captured to become a part of the window itself, this mode creates the border but simply skips clearing contents the window. This is done only when the window is first created. EXAMPLE 6: SEETHRUMODE window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); wwritec( 12, "My message" ); setwindowmodes( SEETHRUMODE ); delay( 1000 ); makewindow( 10, 26, 5, 30, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, AWINDOW ); titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " Captured Text " ); delay( 2500 ); removewindow(); getch(); } When running this program, it appears that a border was just placed over the message "My message". But in fact, it's really a part of the new top window. So, if the window is moved, the contents move as well. HIDDENMODE - In example 3, we plunged right into making hidden windows and it was easy, too. As it was explained, the hidden window is actually a virtual window in the heap to which you can write at any time. Since virtual screen writing is so very quick, you can even design full screens in an instant and then display them on the CRT. Once a window is shown, it can always be hidden again with hidewindow. This is explained further in Chapter 3, Programming Windows Page 15 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Section 6 under Window Management. VIRTUALMODE - This mode is very simple but powerful and enables you to create a virtual window. A virtual screen is kept in RAM, but we can view any portion of it on the CRT. As you would hope, it's still quite simple: EXAMPLE 7: VIRTUALMODE window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); setwindowmodes( VIRTUALMODE ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); writetovirtual( WINDOW1 ); titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " Virtual Window " ); wwrite( 1, 1, "Upper left corner" ); wwritec( 7, "This message is centered on the screen" ); vupdatewindow(); /* Update the complete window on the CRT. */ writetocrt(); /* Return to writing on the CRT. */ getch(); } vupdatewindow is the workhorse for virtual windows. It copied a portion of the virtual screen, the virtual titles, and the cursor location back on the CRT. You probably noticed that the long message seemed to be cut off. But actually we are only looking at a portion of an 80x25 virtual screen. So the message was indeed centered. You can write direct to the virtual screen and view any portion you want. We have just sampled some of the most powerful features of WNDWC with very little effort. Restrictive Modes - NOHIDEMODE, NOACCESSMODE, and NOMOVEMODE are modes that restrict window management. These modes are covered in the Window Management section. Back to Defaults - What about getting back to the default modes after they have been changed? Just use setwindowmodes(0). Combinations - Just about any combination of modes can put together. Just sum them together in the setwindowmodes function. However, there are some combinations that will not be valid. In fact, the function corrects your mistakes. Here's a list of the modes showing invalid combinations: Set Mode Invalid Combination With Correction ------------- --------------------------- ------------------- SHADOWLEFT SHADOWRIGHT SHADOWRIGHT SHADOWRIGHT SHADOWLEFT SHADOWRIGHT ZOOMMODE SEETHRUMODE Ignores ZOOMMODE RELMODE HIDDEN, VIRTUAL or PERMMODE RELMODE PERMMODE HIDDENMODE PERMMODE RELMODE RELMODE Chapter 3, Programming Windows Page 16 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 SEETHRUMODE ZOOMMODE Ignores ZOOMMODE HIDDENMODE RELMODE or PERMMODE RELMODE or PERMMODE VIRTUALMODE RELMODE RELMODE CURSOR MODES Every Window - WNDWC fully supports the cursor mode control of QWIKC. In fact, every window has its own cursor mode. The setting is controlled by setcursordefault. Here's how it works: EXAMPLE 8: Cursor modes in each window ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); setcursordefault( cursor_block ); makewindow( 9, 30, 15, 40, WHITE+BROWN_BG, BROWN_BG, EVEN_SOLID_BORDER, WINDOW2 ); wwrite( 1, 1, "Upper left corner" ); gotoeos(); delay( 2000 ); removewindow(); delay( 2000 ); removewindow(); } When you ran this code, you noticed that top window had a block cursor. When the window was removed, the cursor mode was restored to new top window as an underline. Just like setwindowmodes, the value is saved in cursordefault until changed. Initialization - When WNDWC is used, some initialization code tests the start up cursor mode. On MDA cards, it corrects the improper CGA default. In addition, if the cursor is hidden, WNDWC forces the cursor to an underline, but the original cursor is still in cursor_initial. Initial Window - initwindow sets cursor_default to the current cursor mode which is used for all subsequent windows and WINDOW0. If you even want WINDOW0 to have a different cursor mode and default, simply use setcursor before calling initwindow, and pass cursorok as 1 to initwindow. Mutiple PERMMODE Windows - If you have several PERMMODE windows, to get the cursor to appear correctly in one of the windows, you must use accesswindow when there are only PERMMODE windows left on the screen. To update any virtual PERMMODE window, you must also use accesswindow rather than using writetovirtual before vupdatewindow. CURSOROFFMODE - So, what's the difference between using Chapter 3, Programming Windows Page 17 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 setwindowmodes(CURSOROFFMODE) or setcursordefault( cursor_off )? For technical reasons, in virtual windows, the cursor could be turned on and off. If the setting of cursor_off is used, then the cursor could be turned on having an overbar cursor (0x0000). It's easier to use CURSOROFFMODE. Chapter 3, Programming Windows Page 18 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 4. W R I T I N G T O W I N D O W S WNDWC has several window-relative routines designed to write in the windows, including direct writing, cursor and EOS positioning, clearing, scrolling, and line drawing. They work in all types of windows, including hidden and virtual. To do this, the routines access the top window record (tws or topwndwstat) that keeps information about the current window. For a breakdown on the window structure, see Data Structure in WNDWREF.DOC. Each of these groups of routines are discussed below. DIRECT WRITING Window Relative - Rather than using qwrite to write to windows, three routines are provided to use window-relative coordinates. You have already used two of them. The attribute used is the window attribute tws.wndwattr. void wwrite ( char row, char col, char *astr ); void wwritec ( char row, char *astr ); void wwrite_sub ( char row, char col, int arraylength, char *astr ); wwritec centers the string within the window while wwrite_sub is for arrays or substrings. These routines simply call the QWIKC routines using tws for a window-relative write. QWIKC Support - You will be pleased to know that QWIKC is fully integrated and supported in WNDWC like your favorite use of SAMEATTR and the EOS marker. Wherever an attribute is needed, SAMEATTR can be used. And all the window-relative writing routines support the EOS. For example, to chain after a wwrite statement, just do the following: wwrite( 1, 2, "My message" ); qwriteeos( SAMEATTR, " is here" ); This would write the message "My message is here" on window-relative row 1, column 2, also indicated as (1,2), with the current window attribute. Changing Attributes - Suppose you do not want to use the current window attribute. How can it be altered? The qwriteeos example above is one way. But since the original window attribute is saved in tws.origattr, it can be changed temporarily by doing the following: tws.wndwattr = newattr; /* Assign new attribute */ wwrite( 1, 1, "New Attribute" ); tws.wndwattr = tws.origattr; /* Restore window attribute */ CURSOR AND EOS POSITIONING WNDWC has eight routines to locate and move either the cursor or the EOS marker relative to the current window. Cursor Location - Just like wherer/wherec, the following functions return the current cursor location: Chapter 4, Writing to Windows Page 19 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 wwherer - Window-relative row. wwherec - Window-relative column. Cursor Movement - Similar to gotorc and gotoeos, the following functions move the cursor: wgotorc - Move to window-relative row and column. wgotoeos - Move cursor to match EOS marker location. So, what's the difference between gotoeos and wgotoeos? The latter does two more operations - (1) the cursor location is saved in tws, and (2) the cursor mode is tested in virtual windows to be turned on or off. To be consistent in windows, it is easier to use wgotoeos. EOS Location - Similar to eosr and eosc, the following functions return the current EOS location: weosr - Window-relative row. weosc - Window-relative column. EOS Movement - Similar to eostorc and qeosln, the following functions move the EOS marker: weostorc - Move EOS to window-relative row and column. weosln - Move EOS to column 1 of the next row with a possible scroll if past the last window row. CLEARING WNDWC provides seven window-relative routines for clearing portions of the window including lines, titles, fields, and even the full window with the window attribute tws.wndwattr. SAMEATTR becomes very handy when complex attribute fields have already been designed into the window. wclrscr - Clears entire window. wclrtitle - Clears entire title given TOP or BOTTOM. wclrline - Clears an entire row. wclreol - Clears a row to end-of-line given a (row,col). wclreos - Clears a row from EOS to EOL. wclrfield - Clears a field given a (row,col). wclrfieldeos - Clears a field at EOS. Each of these functions place the EOS marker at the beginning of the cleared area for convenient chaining. (wclrtitle does not alter EOS.) The latter four functions also provide an optional attribute change. Here are some examples with a variety of ways to enter data using many of the above window-relative routines: EXAMPLE 9: Window-relative writing routines ---------------------------------------------------------------------- #include #include #include "wndwc20.h" Chapter 4, Writing to Windows Page 20 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 char *s1,*s2,*s3,s4[80]; int r1,r2; char ch; void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); makewindow( 5, 20, 15, 40, WHITE+BLUE_BG, CYAN+BLUE_BG, SINGLE_BORDER, WINDOW1 ); s1 = " a:\\long\\long\\filename"; s2 = " a:\\shorter\\filename"; s3 = " error message"; r1 = 1; r2 = 14330; wwrite ( 2, 2, "File name: " ); wclreos ( LIGHTGRAY_BG ); /* Clear first field */ qwriteeos ( SAMEATTR, s1 ); /* Put in file name */ wwrite ( 3, 2, "Status" ); wclrfield ( 3, 13, 20, LIGHTGRAY_BG ); /* Clear second field */ qwriteeos ( SAMEATTR, s3 ); /* Put in status message */ wwrite ( 4, 2, "Quantity: " ); wclrfieldeos( 20, LIGHTGRAY_BG ); /* Clear third field */ sprintf( s4, "%19d", r1 ); /* Put in formatted data */ qwriteeos( SAMEATTR, s4 ); eostorcrel( 0, -1 ); /* Shift EOS back one space */ wgotoeos(); titlewindow( BOTTOM, CENTER, YELLOW+BLUE_BG+BLINK, " Press any key " ); while(getch() == 0); wclrtitle( BOTTOM ); tws.wndwattr = SAMEATTR; /* Keeps field attributes intact */ wwrite ( 2, 13, s2 ); wclreos ( SAMEATTR ); /* Clears remainder of long filename */ wclreol ( 3, 13, SAMEATTR ); /* Clears beyond field, But A OK! */ sprintf ( s4, "%19d", r2 ); wwrite ( 4, 13, s4 ); /* Overwrites new data */ tws.wndwattr = tws.origattr; /* Restore window attribute */ getch(); } When running this example, the window will display the formatted data in their fields. Press a key as requested, and the fields will be updated with new data. Notice that the fields are only overwritten and not cleared first. This produces the best human factors by appearing flawless. SCROLLING Some operations may require scrolling all or just portions of a window. WNDWC has four routines to do this, and like all other WNDWC routines, they operate in all windows and video pages at the highest speed without flicker or snow. Full Window - To scroll the entire window, two routines scroll the window Chapter 4, Writing to Windows Page 21 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 up or down. You may also want to consider the conditional scroll of weosln: wscrollup - Scrolls window up. wscrolldown - Scrolls window down. Partial Window - Just like Turbo C's insline and delline, these two routines insert and delete lines by specifying the row. wdelline - Deletes the specified row scrolling the remainder up. winsline - Inserts the specified row scrolling the remainder down. LINE DRAWING The border alone is not sufficient for the design of many windows that need to be partitioned in a logical manner. WNDWC has six functions to completely partition any window - three are for extending the border and three are for a separate line drawing set for inside the window. Border Drawing - The following functions can easily add an extra partition to the window by using the current border style (tws.wsbrdr) and the border attribute (tws.brdrattr): wbrdrh - draws a horizontal partition at the given row complete with tees. wbrdrv - draws a vertical partition at the given columns complete with tees. wbrdrpart - places a single border part at the given row and column usually used for a cross or tee. Line Drawing - When a window is created, the line drawing set (tws.wsline) is the same as the border style (tws.wsbrdr) but can freely be changed. The following functions can easily add an extra line within the window by using the line drawing set and the current window attribute (tws.wndwattr): wlineh - draws just a horizontal line at the given (row,col) repeated for a number of columns. wlinev - draws just a vertical line at the given (row,col) repeated for a number of columns. wlinepart - places a single line part at the given row and column usually used for a cross or tee. Acronyms - To make it easy to remember each individual part of a border or line set, each part has its own acronym. For example, BORDER_TL means the Top Left border part. Here are the parts in their relative positions and their definitions: Relative Position The first letter of the border acronym mean: ------------------ T = top B = bottom TL TH TT TH TR V = vertical H = horizontal LV VL RV L = left R = right LT HL CL HL RT C = cross LV VL RV The second letter is the same except for: BL BH BT BH BR T = tee L = line Chapter 4, Writing to Windows Page 22 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Example - Let's see if we can try some screen design with these routines in this example: EXAMPLE 10: Screen design ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); makewindow( 5, 19, 17, 41, GREEN_BG, WHITE+GREEN_BG, VDOUBLE_BORDER, WINDOW1 ); tws.wsline = SINGLE_BORDER; /* Don't want VDOUBLE_BORDER */ wlineh ( 4, 1, tws.wcols ); /* Use wcols for full window width */ wlineh ( 12, 1, tws.wcols ); wbrdrh ( 8 ); wbrdrv ( 20 ); wbrdrpart( 8, 20, BRDR_CL ); /* For the Cross Line */ getch(); } When you see this executed, it is apparent that the borders are connected with tees. Notice that the line set uses the window attribute. I'll bet you didn't know screen design could be this easy! Why use compressed screens? CUSTOM ROUTINES You can make your own custom routines to be window-relative by using the current window record. This topic will get you familiar with the window coordinates and guide you through an example. Coordinates - The top (or active) window record has two sets of coordinates - one set includes the border and the other excludes it. Here are the field identifiers for the ones including the border: wsrow - Row of the top border. wscol - Column of the left border. wsrows - Number of rows from border to border. wscols - Number of columns from border to border. wsrow2 - Row of the bottom border. wscol2 - Column of the right border. The "ws" acronym means wndwstat which was used to create the window. But usually you would want the coordinate for the text window exclusive of the border ("w" acronym). Here are those field identifiers: wrow - Top row of the window. wcol - Left column of the window. wrows - Number of rows in the window. Chapter 4, Writing to Windows Page 23 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 wcols - Number of columns in the window. wrow2 - Bottom row of the window. wcol2 - Right column of the window. For example, to access the top row of the window, use tws.wrow. This uses the same amount of code as a simple variable. Example - You may have noticed that there is no wfill function included in WNDWC. That's because it's so simple to customize your own. Let's try to write one: void wfill( char row, char col, char rows, char cols, char ch ) { qfill( tws.wrow+row-1, tws.wcol+col-1, rows, cols, tws.wndwattr, ch ); } You can do the same to all your routines and they can work in any displayed or hidden window, or even virtual screens. Chapter 4, Writing to Windows Page 24 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 5. V I R T U A L W I N D O W S Now that you have a good idea of what windows can do, virtual windows will add a greater magnitude of power and flexibility to your windows with no more effort than what has already been covered. This section shows the practical applications and how to program them. APPLICATION This topic will help you decide when virtual windows can meet the needs of your programming application. More Power - The default mode for making windows is a fixed-size window with all of the text displayed. But what if you want variable sized windows or want to write to windows that are not displayed or even covered? Virtual windows to the rescue! They handle this automatically. Definition - What is a virtual window anyway? There are two parts to a virtual window - the screen and the view. The screen part is written in RAM while the view is seen on the CRT. So, we can write to the screen at any time and show only a portion to the CRT as required! Advantages - Since QWIKC has already developed low-level tools for virtual screens, WNDWC uses them to create quick virtual windows. Here are the advantages: . Variable row-by-column screen size up to 64k. . Extremely high speed in RAM. . Number of screens only limited by memory. . Can update windows even if they are overlapped, covered, or hidden. . The view can be resized without losing text. . The screen allows wraparound. . Can access any screen at any time. If your application has operations in one window that affects others, then virtual windows are essential. An example of this is the Turbo Debugger environment where operations in the CPU window affect items in the source code and watch windows. PROGRAMMING Remember, we already did some virtual window programming back in Example 7 and there wasn't anything to it. Now, in this section, you will learn additionally how to make, write, update, view, and resize a virtual window. Compiling - To add the virtual window code when compiling, the macro ADDVIRTUAL must be defined. The distributed library, QWIKC20S.LIB, has the virtual window code included. If you have the source code, the macro is found in WNDWC20.H. To eliminate the code when virtual windows are not needed, simply comment out the statement "#define ADDVIRTUAL". Creating - All we have to do to make a virtual window is use VIRTUALMODE Chapter 5, Virtual Windows Page 25 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 in the setwindowmodes function. The default size for screen is the current screen dimensions as set by initwindow. But suppose a different size is needed. How can that be changed? setvirtualsize controls the screen size. Here's an example: EXAMPLE 11: Virtual window sizing ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); setwindowmodes( VIRTUALMODE ); setvirtualsize( 20, 100 ); /* 20 rows by 100 columns */ makewindow( 5, 20, 15, 40, LIGHTCYAN+BLUE_BG, WHITE+BLUE_BG, SINGLE_BORDER, WINDOW1 ); writetovirtual( WINDOW1 ); /* Now write to the virtual screen */ qfill(1,1,crt_rows,crt_cols,SAMEATTR,'?'); /* Fill screen w/data */ titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " Virtual Window " ); wwrite( 4, 8, " >" ); /* Let's get our bearings. */ qwriteeos( tws.wndwattr+BLINK, "+" ); qwriteeos( SAMEATTR, "<- Row 4, Column 10 " ); vupdatewindow(); /* Update the complete window on the CRT. */ delay (4000); /* Make sure we see where the cursor is. */ removewindow(); getch(); } Notice that we chose a 20x100 screen, but what is seen on the CRT is only 15x40 which is set by makewindow. So, makewindow sets the view size while setvirtualsize sets the screen size. Writing to the Screen - Since there are two areas to write on a virtual window, the view and the screen, WNDWC must be told where you intend to place text. Right after this makewindow function, it is assumed we are going to continue to write on the CRT. But the primary place to write is the virtual screen. writetovirtual selects that screen. All subsequent functions will write to it - all QWIKC routines, WNDWC routines, and even titlewindow and makewindow. It is treated just like any other screen. The exception of course is the cursor routines which must be handled by WNDWC routines only. RELMODE - If you do write to the virtual screen and use makewindow, the mode is forced into RELMODE. Otherwise, the window would be nested and WNDWC could not support it. Memory - What does the screen actually look like in memory? It is saved in the heap in the same way as a CRT video screen. Technically, the far pointer qscrptr points to the location of the screen which is a contiguous array of character/attribute words. The last two rows past the screen are reserved for the virtual titles which are seen on the CRT view when updated. Chapter 5, Virtual Windows Page 26 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Writing to the View - It is possible to write direct to the view on the CRT if desired. To get back and write to the top view, use writetocrt and do your writing. But the next time this window is updated with vupdatewindow or the like, the view will be overwritten with the contents of the virtual screen. Updating - At some time, we would probably like to see the screen and we can do this with any of five updating functions. The main workhorse is vupdatewindow which has been demonstrated several times. This function is so carefree it doesn't even matter when you use it. It updates the virtual window of the current name (tws.wsname) no matter where it is - on top, covered, overlayed, and even hidden from the CRT! The routine actually hunts for it and updates it. To show how it can do this, let's modify the last example: EXAMPLE 12: Updating covered windows automatically ---------------------------------------------------------------------- #include #include #include "wndwc20.h" void main() { initwindow( LIGHTGRAY_BG, 1, 0 ); setwindowmodes( VIRTUALMODE ); setvirtualsize( 20, 100 ); /* 20 rows by 100 columns */ makewindow( 5, 20, 15, 40, LIGHTCYAN+BLUE_BG, WHITE+BLUE_BG, SINGLE_BORDER, WINDOW1 ); setwindowmodes( 0 ); /* Back to default modes. */ makewindow( 7, 30, 16, 18, WHITE+GREEN_BG, GREEN_BG, DOUBLE_BORDER, WINDOW2 ); delay( 2000 ); /* Make sure we see where the cursor is. */ writetovirtual( WINDOW1 ); /* Now write to the virtual screen */ qfill(1,1,crt_rows,crt_cols,SAMEATTR,'?'); /* Fill screen w/data */ titlewindow( TOP, LEFT, YELLOW+BLUE_BG, " Virtual Window " ); wwrite( 4, 8, " >" ); /* Let's get our bearings. */ qwriteeos( tws.wndwattr+BLINK, "+" ); qwriteeos( SAMEATTR, "<- Row 4, Column 10 " ); vviewrc( 4, 10 ); vupdatewindow(); /* Update the complete window on the CRT. */ delay( 1000 ); removewindow(); delay( 2000 ); /* Make sure we see where the cursor is. */ removewindow(); getch(); } With the delay inserted, it gives you time to clearly see that the covered virtual window was updated even though it was covered by another window. But that's not all. When the window was removed, you could see that it was fully updated even under the part that was covered! That's the power of virtual windows. Updating Routines - There are four other updating functions that can be chosen other than vupdatewindow: Chapter 5, Virtual Windows Page 27 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 vupdateview - Updates just the window contents. vupdatetitles - Updates just the titles. vupdatecursor - Updates new cursor position. vupdaterows - Updates selected rows on top view, but full view if covered. vupdatewindow actually executes the first three. But they are also available as separate routines for more detailed work. When the view is on top of the CRT or hidden, the routines are extremely quick. vupdaterows is especially quick for items like data entry to the virtual screen. If the windows are covered, the functions have to do more work. Then vupdatewindow takes about the same time as either vupdatetitles and vupdateview, so vupdatewindow might as well be used. vupdatecursor is almost a trivial routine in any case. Viewing - In this example, you may have noticed that the view was shifted a bit compared to Example 11, and that the cursor was no longer in view. It was shifted by the viewing routine vviewrc. In fact, we could view any part of the screen. Three routines can adjust the reference point of view of the upper left corner: vviewrc - Changes to a given (row,col). vviewrcrel - Shifts a number of rows and columns, positive or negative. vscrollview - Shifts a number of rows and columns, and updates just the view and accepts mouse stepped input. The first two only change the coordinates in the virtual window record, while vscrollview updates the view as well. vviewrcrel is actually a subroutine of vscrollview. All routines check for bounds and will keep the view within screen limits. Resizing - If the virtual window is the top view, two routines can resize it by shifting the lower right hand border: vresizewindow - Shifts a number of rows and columns, and updates the entire window. Accepts both row and column parameters which permit mouse stepped input. vzoomwindow - Toggles window between full size and current size. Zooming up, the window is centered on the screen and the view is at (1,1). Zooming down, it returns to the same size and location, but the view remains at (1,1). Both routines force writing to the CRT upon exit. They also completely update the window since the view and cursor may be shifted. The titles are also smoothly updated. The zoom can be toggled back and forth as long as it hasn't changed size or hasn't zoomed up another window. Chapter 5, Virtual Windows Page 28 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 6. W I N D O W M A N A G E M E N T Some of the previous examples have already touched on the principles of window management. Now this section provides the full scope of management to access windows for display or writing, including multiple video pages. ACCESS METHODS The are two basic methods for accessing windows: serial access and random access; WNDWC does them both. Serial Access - This is a simple method of stacking windows over each other and then removing them in reverse order. Any writing is always done on the top window displayed on the CRT. The only two functions used are makewindow and removewindow. For simple menu systems, serial access may be all that is needed. The advantages are: . Uses less code. . No gaps in heap memory. . Only one place to write. But the disadvantages are many. Once a window is removed, it is lost from memory and must be recreated. This can cause a significant amount of shuffle to access other windows. Serial access is a subset of random access. Random Access - More and more applications require access to any window at any time without losing the data. WNDWC was designed to handle this automatically at very high speed. The advantages to random access are: . Free access to any window. . Windows are created only once. . Virtual windows can be updated even if covered. . Ease of programming. Any window can be randomly accessed, including fixed, virtual and hidden windows. It's as simple as that. Try running the window management demo WNDWMGR.C again and see how you can hide, show, and access any window. The instructions are on the screen. DISPLAY CONTROL Three functions select the window to be displayed as the top window: accesswindow - Accesses the window by name whether hidden or covered. hidewindow - Hides the top window. showwindow - Shows a window given its name. accesswindow hunts for the named window and, if it is hidden, it will also be shown. showwindow is actually a subroutine of accesswindow. Any window (except PERMMODE) can be hidden and shown; they do not have to be created with HIDDENMODE which hides it at the start. Chapter 6, Window Management Page 29 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 EOS - When using hide/showwindow, the EOS is reset to (1,1) to prevent unexpected results. However, if the window is currently displayed on the CRT and accesswindow is used, the EOS is restored to its previous value. removewindow - This function could be considered a form of display control, but remember that when a window is removed, it is gone forever, including any virtual screen. movewindow - This function shifts the top window around on the CRT by a given number of rows and columns allowing mouse stepped control. A window can be limited in movement by setting the values in the structure called "margins" (see QWIKREF.DOC). The bounds are conveniently checked, so the window will always stays within limits. In the WNDWMGR.C demo, you can see the status line on row 25 is never overlapped by movewindow. Although WINDOW0 is a permanent one, we could easily write to the status line at any time by using accesswindow(WINDOW0). Changing Borders - For human factors, it is often helpful to have a border be emphasized when it becomes the new top window. Two high speed functions handle this well: changeborder - Changes the top window to the new given border style. restoreborder - Restores the original border created with makewindow. Both of these functions work only on the top window, and they can either be fixed or virtual. They replace all border parts including tees and also leave all titles untouched. WRITE CONTROL Three functions select where the writing functions will write: writetohidden - Writes to the named hidden window. writetovirtual - Writes to the named virtual screen. writetocrt - Writes to the current top window on the CRT. writetohidden - A hidden window is saved with the border intact, but is stripped of any shadow. It is easier to use the window-relative writing routines because of the optional border rather than using QWIKC which can still be used. Any shadow is reconstructed by showwindow. writetovirtual - A virtual screen can freely use either WNDWC or QWIKC routines since it never has a border. If you want to write directly to the virtual screen after it has just been created, sometimes it's easier to use writetovirtual(tws.wsname) provided HIDDENMODE was not used as well. writetocrt - All routines continue to write to their destination until changed. This routine will get you back to writing on the CRT. Some functions are forced back to the CRT after their operation. Here are those exceptions: accesswindow vresizewindow movewindow hidewindow vzoomwindow showwindow changeborder Chapter 6, Window Management Page 30 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 removewindow restoreborder REMEMBER: Use writetocrt to get back to the CRT. If you forget, the text will of course be in an unexpected window. makewindow - This function does NOT force a change in the write destination. If you are writing to a hidden window or a virtual screen, the resulting window created by makewindow is forced into RELMODE. However, the windowmodes setting is not affected. WINDOW MODES AND FLAGS Additional window modes are available to restrict window operations or to detect the window destination status. Each mode has a corresponding boolean flag. Restrictive Modes - In some applications, you may want to restrict what the end user can change for the windows. Before the window is created with makewindow, use these modes in a call to setwindowmodes. The flags can be used for testing. Set Mode Set Flag Description ------------ ------------ -------------------------------------------- nohidemode nohideflag Ignores hidewindow operation. noaccessmode noaccessflag Ignores accesswindow operation. nomovemode nomoveflag Ignores movewindow/vresizewindow operations. Destination Modes - These modes are just for your information and are handled automatically by WNDWC. These identify the write destination of the window. You can use the flags for testing, but the modes are ignored by setwindowmodes: Set Mode Set Flag Description ------------- ------------- ------------------------------ tocrtmode tocrtflag Writing to the CRT. tohiddenmode tohiddenflag Writing to the hidden window. tovirtualmode tovirtualflag Writing to the virtual screen. HIGH SPEED SCREEN DESIGN By using hidden or virtual windows, WNDWC enables you to make screen design several magnitudes faster than you ever thought possible. Comparing Speeds - Let's compare three speeds - (1) Turbo C's direct video, (2) QWIKC/WNDWC writing to CRT, and (3) QWIKC/WNDWC writing to RAM. The following chart is striking. ---- QWIKC/WNDWC ---- Video Card Turbo C To CRT To RAM ---------- ------- ------ ---------- CGA 100% 225% 1600-4100% All others 100% 750% 900-1700% Chapter 6, Window Management Page 31 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Design Strategy - So how can you get these fantastic speeds? The simplest way was shown in Example 3 by creating hidden windows. You may wish to make a habit of creating your windows with HIDDENMODE and then immediately show them with showwindow. Virtual window code is not even required for hidden windows. Of course, the alternative is to go ahead and use virtual windows. Either way, you can actually see the increase in performance in your programs. Code Savings - Many application programs use disk-based screens that are called from the disk when required. QWIKC and WNDWC require such little code to create a full screen design, that you will actually save code and disk space by using these routines - not to mention the increase in speed! MULTIPLE VIDEO PAGES Most color video cards have the capacity for multiple video pages. If your application can benefit from extra pages, WNDWC handles all the data records with simplicity. Compiling - To add in the multiple video page code when compiling, you must define the macro MULTIPAGE. The distributed library, WNDWC20S.LIB, has the multi-page code included. If you have the source code, the macro is found at the top of WNDWC20.H. To eliminate the code when these pages are not needed, simply comment out the "#define MULTIPAGE" statement. Changing Pages - To change video pages, use one of the following functions: writetopage - Directs all QWIKC and WNDWC routines to write to the given page number, but still view the current page. writeandviewpage - Directs all QWIKC and WNDWC routines to write and to view the given page number. Separate Records - Each video page has its own set of window records that are completely separate including the level indexes and top window stats. So when pages are swapped, everything is just where it was left - even the cursor mode and EOS. However, the virtual screen records use the same array in the heap, but, to keep them separate, they do not share records. | MULTI-TASKING ENVIRONMENTS | | WNDWC is perfectly suited for working in multi-tasking environments. In | order for your program to advantage of the speed and flexiblity of virtual | video buffers (MTVB) used with any environment, there is only one variable | that needs to be set: | | prefer_multitask = 1; | | Place this before initwindow, and WNDWC will use the MTVB if available. | All routines will then be set to write directly to this buffer. If | inmultask is 1, then WNDWC is using the MTVB. directvideo is set to 0 by | WNDWC and you must likewise instruct the environment that the program is | capable of writing to the MTVB by telling it that is does not write direct Chapter 6, Window Management Page 32 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 | to the screen. WNDWC is extremely fast and proves itself well in | environments! | | Multiple Pages - Please remember that many multi-tasking environments do | not support more than one page. Be sure the ones you are designing around | do support full page control. WNDWC prevents the use of multiple pages | while using the MTVB by altering maxvalidpage in the initpages function. | If you have one that behaves properly and you have the source code to WNDW, | you can enable multiple page writing by modifying initpages. Chapter 6, Window Management Page 33 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 7. D A T A M A N A G E M E N T Almost all of the data is handled automatically by WNDWC. This section is provided for those who are interested in the details of data management and the inner workings of WNDWC. The only required reading is Data Allocation. Otherwise, you can skip this section. DATA ALLOCATION This topic will provide you enough knowledge to budget the number of data records needed for your program using the macros MAXWINDOW, MAXVIRTUALWINDOW, and MAXPAGEUSED. Data Structure - For a detailed description of the data structure, you can refer to Data Structure in Section 3 of WNDWREF.DOC. To be able to adjust the data structure, you must have the source code. If not, the sizes have been preassigned. MAXWINDOW - Each window on the CRT, displayed or hidden, requires one index of the window statistics array (wndwstat), which is static data. The initial window, WINDOW0, is always at wndwstat[0]. The size of the array of structures (wndwstat) is defined by MAXWINDOW as the highest number of windows, hidden and displayed, that are on the CRT at any one time on any one video page. For example, if page 0 has a maximum of 10 windows and page 1 has 6, set MAXWINDOW equal to 10. MAXVIRTUALWINDOW - Each virtual window has two window structures - one is in wndwstat for the view and the other is in virtualstat for the virtual screen which is dynamic data. The first virtual screen is saved in virtualstat[0] since it is zero based. The array of records is sized by MAXVIRTUALWINDOW as the highest total number of active virtual windows. For example, if page 0 has 4 virtual windows and page 1 also has 4, set MAXVIRTUALWINDOW equal to 7 (not 8). MAXPAGEUSED - This is the highest page number that will be used in a multiple video page program. If you are only using page 0, which is usually the case, you should go ahead and comment out the definition of the macro MULTIPAGE and not bother with MAXPAGEUSED. Each page saves its own wndwstats and indexes in one structure called pagestat in an array in dynamic memory. MAXPAGEUSED and maxpage are compared and the lesser of the two will size the pagestat array. Program Development - When you first start developing a program, make it easy on yourself and inflate the values of these macros to provide enough freedom without having to recompile. In your final program, you can trim them down and retest. STRUCTURE HANDLING If you are wondering where your wndwstat structure is being saved, the following will show you how it is managed. Chapter 7, Data Mangement Page 34 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Displayed Stack - Each window as it is displayed on the CRT has its corresponding window structure saved in wndwstat starting from the bottom of the array and stacked upward. The base window, WINDOW0, which is permanent, is saved in wndwstat[0]. The first window displayed is saved in wndwstat[1], the second in wndwstat[2], and so on. The top window is in wndwstat[li] where li is the top Level Index. Hidden Stack - Hidden windows have their structure moved from wndwstat[li] to the top of wndwstat starting from the top of the array stacked downward. As you can imagine, the hidden stack is simply inverted to the displayed stack. So, when a window is hidden, it is placed starting at wndwstat[MAXWINDOW]. The last hidden window saved is at wndwstat[hli]. hli is the Hidden Level Index. Conversely, when a window is shown, it is removed from the hidden stack and replaced in wndwstat[li]. Random Access - Anytime a window is randomly accessed, the structure is pulled out from the middle of the stack. The stack is then dropped to fill the gap. virtualstat - The structures for the virtual screens are kept in dynamic memory in an array called virtualstat and are not shuffled like the window structures. If a window is virtual, the index to the virtual screen is wndwstat[?].vi. topwndwstat - The current window stats are always maintained in the global structure topwndwstat (tws). When working with the current window, always use topwndwstat (tws) in lieu of wndwstat or virtualstat. topvirtualstat - Just like tws, a copy of the current virtual screen structures from virtualstat is maintained in the global structure topvirtualstat (tvs). RELMODE Structures - RELMODE windows only have the structure temporarily placed in tws and are not saved in the stack. They are overwritten with any change of windows. PERMMODE Structures - PERMMODE windows have a copy of their structures placed in tws (and tvs if virtual), but the stack is not shuffled and there are no gaps. All PERMMODE structures must be the first ones in the stack. The highest index of permanent windows is maintained in pli, the Permanent Level Index. Saving structures - Again, WNDWC handles this automatically, tws and tvs are saved in their appropriate wndwstat or virtualstat. Remember, when writing to virtual screens, tws and tvs are reversed. It may be helpful to think of tvs then as the Top View Stat on the CRT. Finding structures - Since the structures are shuffled, just how do you find the structure you want? Given the window name, getlevelindex returns the index in wndwstat for the window structure. Page Structures - When swapping pages, WNDWC swaps the entire wndwstat array, top window structures, indexes, margins, cursor mode and window modes for each page. Chapter 7, Data Mangement Page 35 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 Heap - Virtual screens and hidden windows are saved in the far heap. To calculate your heap requirement, please refer to Appendix A in WNDWREF.DOC. For your own program, you can also use the heapok function to test for coreleft. If there is insufficient heap space, then heapok will terminate the program using the GOOF module. Stack - The WNDWC modules were compiled with stack checking turned off, and the stack size left at Turbo C's default value, which is 4K. Less than 2k of stack space is used in any function. Chapter 7, Data Mangement Page 36 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 8. O T H E R M O D U L E S Besides the actual WNDWC code, we have included a few other modules as part of the WNDWC package. The GOOF module handles programming errors. The other modules, as described below, have some high speed screamin' routines to add zing into many of the window operations. These utility modules are part of the WNDWC library (.LIB) file, and you can use them in your programs. See WNDWREF.DOC for information on using the utility functions. GOOF MODULE All programmers make mistakes, right? So, what happens when you try to make more windows than there are indices available? Since WNDWC is so powerful and can even write in RAM, there is a good possibility that your mistake may not even show up on the screen. How do you know if anything has gone wrong? The GOOF module was made especially for handling errors. Displaying Errors - When an error is found in your program, the function showgoof is called and the program is terminated. The CRT will display an error message in a flashing window. There are eight fatal errors that are listed in APPENDIX B in WNDWREF.DOC to identify problems before they happen. Please refer to it for the error messages and their solutions. Flexibility - You can edit GOOF for use in your own applications. After customizing the module, use the TLIB command to replace it in the appropriate WNDWC library. Then when the library is linked with your program, your new GOOF module can be called. The error message numbers 1-50 are reserved. So, for your own applications, it is suggested that you start with number 51. If you have thoroughly tested your program, some of the messages can be eliminated. UTILITY MODULES To help make WNDWC into a fast library, some move and swap functions were placed in the WNDWC library. If you wish, you may link the object files for them into programs of your own which do not already use the WNDWC library. move16/movewords - Since WNDWC needs the highest speed move functions, two routines were developed. move16 - Replacement for memcpy or memmove, but twice as fast using 16-bit transfers, movewords - Faster than move16, but destination cannot overlap source[0]. Chapter 8, Other Modules Page 37 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 9. C O M P I L I N G T H E S O U R C E C O D E If you have registered for the source code, it's likely that you will want to compile it using various model sizes and compiler options. We have made this process easy. Set up your options in the TC environment, save them in a .TC file, and convert it to TURBOC.CFG using TCCONFIG. Then you can use the MAKEWNDW.BAT file provided to compile. When running it, you must specify the letter for the model you wish to use. For instance, to compile the source using the Compact Model, type: makewndw c Note: Turbo Assembler, MASM 4.0, or a compatible assembler must be accessible via the DOS path in order for MAKEWNDW.BAT to work. The MAKEWNDW.BAT file compiles the WNDWC modules, then adds them to the library (.LIB) file for the model you requested. For instance, if you specified the Medium Model, the modules would be placed in WNDWC20M.LIB. The optimum settings for compiling WNDWC are as follows: Floating point: None Test stack overflow: Off Line numbers: Off OBJ debug information: Off Optimize for: Speed The following settings are mandatory: Model: Small-Huge (Tiny not supported) Calling convention: C Standard stack frame: On Identifier length: 32 (or above) Chapter 9, Compiling the Source Code Page 38 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 A P P E N D I X A : A P P L I C A T I O N P R O D U C T S Eagle Performance Software has developed identical products for both Turbo C and Turbo Pascal. Our pledge is to provide you quality products with unparalleled performance and ease of use. All registered users receive the complete source code when a signed license agreement is returned. QWIK QWIK - For direct screen video, QWIK is the highest performance screen writing tools available today for all text modes in any video configuration. QWIK provides capabilities far beyond those in the unit/library that comes with your compiler. Here are some of the features: - Writes on all IBM compatible computers, displays and adapters including MDA, CGA, EGA, MCGA, VGA, 8514/A, Hercules and 3270 PC. - Superior video detection routine. - Eliminates snow and flicker. - Writes directly to the screen in absolute rather than relative coordinates. - Writes in all text modes and column modes. - Writes on all video pages. - Writes on virtual screens in RAM. - Writes text and attribute, text only, or attribute only. - Reads strings, characters and attributes. - Uses End-Of-String (EOS) marker for quick string chaining. - Provides standardized cursor shapes for all adapters. - Enhanced cursor movement. - Compatible with DESQview and similar multitasking environments. - Over 650% faster than standard direct screen writing. - Only 2.7k bytes of code if all 43 utilities are used. - Optimized by the compiler/linker and drops unused code. - Used in all other Eagle products. - Excellent documentation like this document. Here are the product versions: File name CIS Name Compiler Release date ----------- ---------- -------- ------------ QWIK42B.ARC QWIK42.ARC TP4(TP5) 10-01-88 QWIK5X.ARC QWIK5X.ARC TP5(TP4) 12-20-88 QWIKC20A.ARC QWKC20.ARC TC2 12-03-88 WNDW - Here are the current product versions of WNDW: File name CIS Name Compiler Release date ----------- ---------- -------- ------------ WNDW42.ARC WNDW42.ARC TP4(TP5) 10-15-88 WNDW5XA.ARC WNDW5X.ARC TP5(TP4) 12-20-88 WNDWC20.ARC WNDC20.ARC TC2 02-01-89 Appendix A: Application Products Page 39 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 PULL PULL - For multi-level pull-down menus, PULL is fully featured and fully configurable. Includes execute, single, and multiple choice menus, unlimited nested submenus, data entry windows, help windows, directory windows, message system, and fully completed interfaces. Some of the features are: - Uses QWIK and WNDW. - Work window(s) and complete interface for menus - Pull-down menus with 3 menu modes and 7 line modes - Pull-down file directory - Highlighted command letters - Unlimited levels of submenus - Unlimited data entry windows for 9 types of data - Data entry for the work window(s) Free field entry with either fixed column or flexible column length. Full editing capability including insert cursor mode Full field selection with cursor keys Automatic NumLock for numerical data entry Right or left justification for data entry output Error messages for invalid data entries Error messages for data entries out of range - Automatic sizes and locations for menus. - Operation by cursor keys or command keys - Pull/Pop between work window and nested submenu(s) - Programmable control of pull and pop sequences - Context-sensitive help - Message lines for prompts and processing - Full working shell for user development - Excellent documentation like this document. Here are the product versions: File name CIS Name Compiler Release date ----------- ---------- -------- ------------ PULL42.ARC PULL42.ARC TP4(TP5) 01-03-89 PULL5XA.ARC PULL5X.ARC TP5(TP4) 01-06-89 PULLC20.ARC PULC20.ARC TC2 TBA ON-LINE SERVICES CompuServe - All updated files and later versions can be found on the CompuServe Borland Forums (GO BPROGA for TP and GO BPROGB for TC) or the IBM Programming Forum (GO IBMPRO). The Eagle BBS - You can also get the latest files on our 24-hour BBS at (214) 539-9878, 1200/2400 N81. Appendix A: Application Products Page 40 WNDWC Multi-level Virtual Windows User's Guide, Version 2.0 A P P E N D I X B : C R E D I T S Fundamental Ideas - The initial concepts of serial-access windows were developed by Michael Burton in his copy of WINDO.INC, ver 2.4. The concepts were used by written permission. Special Effects - Special effects concepts were graciously suggested by Rick Fothergill. Copyright (c) 1989 by James H. LeMay for Eagle Performance Software. All Rights Reserved. Protected by the United States Copyright Laws. Conversion to Turbo C by Jordan Gallagher / Wisdom Research Appendix B: Credits Page 41