Saving console's output buffer
-
I would appreciate any information someone might have on how to save the console's output buffer so that I can have another screen temporarily display it's contents and then restore the former contents as though nothing happened. I would prefer any code or class references to be ANSI (Dev c++ compatible) but I will take any kind of suggestions anyone can offer. Thank you greatly!
sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
-
I would appreciate any information someone might have on how to save the console's output buffer so that I can have another screen temporarily display it's contents and then restore the former contents as though nothing happened. I would prefer any code or class references to be ANSI (Dev c++ compatible) but I will take any kind of suggestions anyone can offer. Thank you greatly!
sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
-
Thanks for the idea. I am hesitant to go that route for a few reasons, though. I was hoping that it would be possible to accomplish without using
windows.h
and other such things - hoping for pure console-type code. Aside from that, though, I haven't used handles or child processes or a few other things in that code before, and it's very daunting to look at it and challenging to understand it. Would you have any other ideas or a link to some reading material that might help me understand all that a little better? Also: I noticed the use ofprintf()
in that code. Is it possible to use streams (cout
andcin
) or at leastgetch()
and such with that code? I appreciate your time and knowlege.
sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
-
Thanks for the idea. I am hesitant to go that route for a few reasons, though. I was hoping that it would be possible to accomplish without using
windows.h
and other such things - hoping for pure console-type code. Aside from that, though, I haven't used handles or child processes or a few other things in that code before, and it's very daunting to look at it and challenging to understand it. Would you have any other ideas or a link to some reading material that might help me understand all that a little better? Also: I noticed the use ofprintf()
in that code. Is it possible to use streams (cout
andcin
) or at leastgetch()
and such with that code? I appreciate your time and knowlege.
sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
I might have been a bit premature in my reply. Looking at both of your posts, I don't have a firm grasp of what it is that you are trying to do. Do you have one console application that needs to start another? The use of
CreateProcess()
does not necessarily mean the application has a GUI. You can use it in a console application (to start another console application or a GUI application).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
I might have been a bit premature in my reply. Looking at both of your posts, I don't have a firm grasp of what it is that you are trying to do. Do you have one console application that needs to start another? The use of
CreateProcess()
does not necessarily mean the application has a GUI. You can use it in a console application (to start another console application or a GUI application).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
I am not attempting to start another application or window or process, unless that is the only way to accomplish my goal. My goal is to basically have a splash screen or menu or notification box or anything, pop up in the middle of an application, getting a response from the user, and then disappearing, leaving the former output intact. This is an ideal situation - I know it must be possible, because I have seen it in several DOS applications. I assume that they were written in c++ or that this function can be emulated or reproduced in c++ in some way. It is not necessary to the function of the program, but looks a lot nicer than clearing the screen or buffer. Also, I think it must be easier to save and restore the buffer (that is, whatever may be displayed on the console screen at the time) than it would be to figure out whatever may be displayed and restoring it manually. I don't want to open another window or start another program, I want to more or less simulate what windows shows with menus or dialog boxes (except extremely simplified) in a single console/DOS window or from the command prompt. sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
-
I am not attempting to start another application or window or process, unless that is the only way to accomplish my goal. My goal is to basically have a splash screen or menu or notification box or anything, pop up in the middle of an application, getting a response from the user, and then disappearing, leaving the former output intact. This is an ideal situation - I know it must be possible, because I have seen it in several DOS applications. I assume that they were written in c++ or that this function can be emulated or reproduced in c++ in some way. It is not necessary to the function of the program, but looks a lot nicer than clearing the screen or buffer. Also, I think it must be easier to save and restore the buffer (that is, whatever may be displayed on the console screen at the time) than it would be to figure out whatever may be displayed and restoring it manually. I don't want to open another window or start another program, I want to more or less simulate what windows shows with menus or dialog boxes (except extremely simplified) in a single console/DOS window or from the command prompt. sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.
If what I'm thinking of is what you are after, I'm going way back in my brain to retrieve it. If this "splash screen" is part of the console window, as opposed to a GUI splash screen, you need to read 4,000 bytes from memory address 0xb8000000. That is the starting address of the video display. Something like:
char far *pDisplay = (char far *) 0xb8000000;
char sBuffer[4000];// save contents of screen
char far *pTemp = pDisplay;
for (int x = 0; x < sizeof(sBuffer); x += 2)
{
= *pTemp++; // character
sBuffer[x+1] = *pTemp++; // attribute
}// write new stuff to screen
// restore screen
for (x = 0; x < sizeof(sBuffer); x += 2)
{
*pTemp++ = sBuffer[x]; // character
*pTemp++ = sBuffer[x+1]; // attribute
}Am I way off track here?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
If what I'm thinking of is what you are after, I'm going way back in my brain to retrieve it. If this "splash screen" is part of the console window, as opposed to a GUI splash screen, you need to read 4,000 bytes from memory address 0xb8000000. That is the starting address of the video display. Something like:
char far *pDisplay = (char far *) 0xb8000000;
char sBuffer[4000];// save contents of screen
char far *pTemp = pDisplay;
for (int x = 0; x < sizeof(sBuffer); x += 2)
{
= *pTemp++; // character
sBuffer[x+1] = *pTemp++; // attribute
}// write new stuff to screen
// restore screen
for (x = 0; x < sizeof(sBuffer); x += 2)
{
*pTemp++ = sBuffer[x]; // character
*pTemp++ = sBuffer[x+1]; // attribute
}Am I way off track here?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
Sorry I took so long to respond. This looks like basically what I'm after, assuming I can figure it out (and the memory address is correct) - It'll take me a bit to figure it out. Thanks for your help; I hope I get it working - we'll see. I appreciate your time.
sincerely, Brett Peirce - PolerBear To err is human; To forgive: divine.