_wrapon() Prevents Text Mode Text Window from Scrolling

ID: Q66774

5.10 6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00

MS-DOS                      | OS/2       | WINDOWS
kbprg kbcode

The information in this article applies to:

SUMMARY

In an application developed with Microsoft C that uses text mode, a text window filled with characters scrolls when the user places a character into the last position in the lower-right corner of the window. To prevent the window from scrolling in this situation, use the _wrapon() function.

MORE INFORMATION

Functions that display text, such as _outtext(), are designed with the assumption that the current cursor position is one character beyond the last output position. Therefore, when the cursor is on, it blinks just beyond the most recently displayed character.

When the application enables text wrap and writes a character to the last position in a line, the cursor blinks in the first position of the next line. On the last line of a window in text mode, this behavior causes the window to scroll. In graphics mode, or when the application uses _outgtext(), this does not occur.

To work around this behavior, use the _wrapon() function to turn off text wrap when the application draws the final character in the window. The _wrapon() function accepts either of two wrap conditions: _GWRAPOFF or _GRAPON.

The code example below demonstrates this condition and addressing it with the _wrapon() function.

Sample Code

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <graph.h>
#include <conio.h>
#include <string.h>

void main(void)
{
   int i, response;
   char ch[11];

   _clearscreen(_GCLEARSCREEN);

   printf("\n\nDo you want text wrap on? (y/n)");
   response = getch();
   if (_toupper(response) == 'Y')
      _wrapon(_GWRAPON);
   else
      _wrapon(_GWRAPOFF);

   // Label screen grid for easy reference

   _clearscreen(_GCLEARSCREEN);
   _outtext("123456789");
   for (i = 2; i <= 9; i++)
   {
      _settextposition(i, 1);
      _outtext(itoa(i, ch, 10));
   }

   // Set a text window and fill all but last line

   _settextwindow(3, 3, 9, 9);
   for (i = 1; i <= 6; i++)
   {
      _settextposition(i, 1);
      memset(ch, i + '0', 10);
      _outmem(ch, 7);
   }

   // Fill last line, all but last character

   _settextposition(i, 1);
   memset(ch, i + '0', 10);
   _outmem(ch, 6);
   getch();

   // Fill last character in window -- the entire window will scroll
   //   if text wrap was specified

   _outmem(ch, 1);
   getch();
   _clearscreen(_GCLEARSCREEN);
}

Note: This sample program uses the _outmem() function, which is not available in the C version 5.1 or Microsoft QuickC version 2.0 run- time libraries. To build this program with either of these compilers, you must rewrite the code to remove the _outmem() function.

Additional reference words: kbinf 5.00 5.10 6.00 6.00a 6.00ax 7.00 1.00 KBCategory: kbprg kbcode KBSubcategory: CRTIss GraphicsIss Keywords : kb16bitonly

Last Reviewed: July 18, 1997