The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: omdown on June 02, 2005, 01:56:13 AM

Title: Backing up a screen buffer?
Post by: omdown on June 02, 2005, 01:56:13 AM
Does anyone have any idea how to back up and restore a screen buffer?  I'm so lost on this, first I thought I would need to copy and paste the entire thing into a text file by reading each character and its attribute and copying it there, but that didn't seem like it was going to work out very well, and now I'm just lost.  I can't even figure out where to start with this.  If anyone could point me in the right direction it would be greatly appreciated.
Title: Re: Backing up a screen buffer?
Post by: MichaelW on June 02, 2005, 06:48:03 AM
Is this for a Windows Console app, or a DOS app?
Title: Re: Backing up a screen buffer?
Post by: Jeff on June 02, 2005, 09:08:19 AM
i would think it would be a safe bet to say its a windows console app.

if so, i suppose you could use ReadConsoleOutput (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/readconsoleoutput.asp) to "save" it and WriteConsoleOutput (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/writeconsoleoutput.asp) to "restore" it.
Title: Re: Backing up a screen buffer?
Post by: MichaelW on June 02, 2005, 09:43:04 AM
Jeff,

That is what I thought too, at first. But omdown has another recent post here in the campus that deals with detecting Ctrl+F, and a post in the 16-bit DOS forum that deals with an app that detects Ctrl+F, and is having problems with it.

omdown,

Whether this is a Windows Console app or a DOS app, my suggestion would be the same. Why backup and restore when your application can have multiple screen buffers (or display pages for DOS)? For a Windows Console app instead of backing up the current screen buffer, you could just leave it as is, create a new one, use it for whatever, and then switch back to the previous one. AFAIK you can create as many screen buffers as will fit in the available memory. For a DOS app you would do essentially the same, just switching display pages. Where under DOS or Windows 9x you would typically have 8 display pages available, I seem to recall that Windows 2000 and XP limit the number of display pages to 4.

You have already been shown how to work with display pages. For console screen buffers, take a look at the CreateConsoleScreenBuffer and SetConsoleActiveScreenBuffer functions here:

MSDN: Character Mode Applications (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/character_mode_applications.asp)