f67 Subj : Re: platforms To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Sat Dec 06 2003 06:05 pm Because DOS did not do very much, DOS programs often would bypass DOS and go directly to the firmware or to the hardware. That is what you are doing in the code you show. Win32 does not allow application programs to go to the hardware. It is a multitasking environment and the screen is a shared resource. Direct screen manipulation alters what other programs also use. Look at the functions in CONIO.H. The function gettext does what I understand you to be trying to do. Note that gettext also does it in a program for the DOS platform. As for a demo of how to do it, the code below might be close. I've just typed it in and not run it through the compiler so look for typos. For instance, I am not sure if the order of the char and attribute in the structure named Cell is reversed. ---------------------- #include #include #include #include typedef struct /* data for one char cell */ { char c; unsigned char attr; } Cell; char GetLetter(void) /* generate a random char */ { char c = rand(); if (!isalnum(c)) c = (c % 26) + 'a'; return c; } unsigned char GetAttr(void) /* generate a random color */ { unsigned char b1; unsigned char b2; b1 = rand() % 0x0F; b2 = rand() % 7; return (b2 << 4) | b1; } void FillScreen(void) /* fill screen with colored gibberish */ { int x; int y; int len = random(8); /* word length */ for (y = 0; y < 25; ++y) { for (x = 0; x < 80; ++x) { if (--len == 0) { len = random(8); putch(' '); } else { textcolor(GetAttr()); putch(GetLetter()); } } } } int GetAKey(void) /* read a key without echoing to the screen */ { int k = getch(); if (k == 0) /* if a special key */ { k = getch() << 8; } return k; } int main() { Cell screen_data[80][25]; randomize(); /* init random number generator */ FillScreen(); gettext(1, 1, 80, 25, screen_data); cprintf("Press a key to clear the screen"); GetAKey(); textcolor(LIGHTGRAY); textbackground(BLACK); clrscr(); cprintf("Press a key to restore the screen"); GetAKey(); puttext(1, 1, 80, 25, screen_data); cprintf("Press a key to end the program\r\n"); GetAKey(); return 0; } ---------------------- If what is in CONIO.H isn't enough for you then you would have to use the Win32 API but it is a bit more complex. If you decide to do that, look in the Win32 help file (win32.hlp) for these things: COORD SetConsoleCursorPosition GetConsoleScreenBufferInfo SetConsoleScreenBufferInfo .. Ed > Rob C. wrote in message > news:3fd250d1$1@newsgroups.borland.com... > > This is a problem that’s little hard to explain. I don’t know if > you remember my situation, but some months back I had a need to > save to a file the text and colors of a particular x/y position > that where currently on the screen. The savetextattriubute > function wouldn’t serve my purposes. So you or someone there > custom-wrote me a function that would do it. The function is > listed below. > > And this function works great! I use it all the time. > > It works great, that is, in BC++ DOS platform. (but DOS is > obsolete) When I compile it in Win32, console mode, (which as I > understand it is similar to the DOS platform) it gives me a > whole host of errors (listed below). And it’s just the > savescreen(); function. If I remove it, all my other functions > work fine. . 0