Resize Console Buffer

Just starting out? Need help? Post your questions and find answers here.
armixeight
New User
New User
Posts: 9
Joined: Sun Sep 13, 2009 4:34 am

Resize Console Buffer

Post by armixeight »

I have a program that runs with the OpenConsole() command and i would like to get rid of the scroll bar on the side.
I have read around for awhile about how to remove the scroll bar and has been the result of resizing the buffer to 80x24.
The problem is i can't seem to implement the resize in purebasic. It can be done in C++ and languages like that because of code I found on the Microsoft MSDN's example areas.

Basically it needs to look something like the Dwarf Fortress and Rogue games, where there is no scroll bar.
Thank you to how ever helps, because you will know that you saved someone hours of console scripting.

Please somebody help.

Image
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Resize Console Buffer

Post by TomS »

If it's on MSDN it can probably done with PB.
How about a link?
armixeight
New User
New User
Posts: 9
Joined: Sun Sep 13, 2009 4:34 am

Re: Resize Console Buffer

Post by armixeight »

http://msdn.microsoft.com/en-us/library ... S.85).aspx

And here is some code that I tried to make: (no luck though ... :(

Code: Select all

OpenConsole()
stdout.l=GetStdHandle_(#STD_OUTPUT_HANDLE)

NewSize.COORD
NewSize\X=80
NewSize\Y=23
SetConsoleScreenBufferSize_(stdout, @NewSize)

Input()
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Resize Console Buffer

Post by TomS »

I found this http://purearea.net/pb/CodeArchiv/Input ... onsole.pbi
and in it there was a procedure to set the buffer size. :)

Code: Select all

Procedure ConsoleBufferSize(handle.i, characterWidth.i, characterHeight.i) 	
	Protected consoleInfo.CONSOLE_SCREEN_BUFFER_INFO
	Protected rect.SMALL_RECT
	
	GetConsoleScreenBufferInfo_(handle, @consoleInfo) 
	
	If characterWidth < consoleInfo\dwSize\x Or characterHeight < consoleInfo\dwSize\y 
		 
		If characterWidth < 13 ;Smaller thant 13 seems not possible
			rect\right = 13 - 1 
			characterWidth = 13 
		ElseIf characterWidth < consoleInfo\dwSize\x 
			rect\right = characterWidth - 1 
		Else 
			rect\right = consoleInfo\dwSize\x - 1 
		EndIf 
		
		If characterHeight <= 0 
			rect\bottom = 1 - 1 
			characterHeight = 1 
		ElseIf characterHeight < consoleInfo\dwSize\y 
			rect\bottom = characterHeight - 1 
		Else 
			rect\bottom = consoleInfo\dwSize\y - 1 
		EndIf 
		
		
		SetConsoleWindowInfo_(handle, 1, @rect) 
	EndIf 
	
	
	SetConsoleScreenBufferSize_(handle, characterWidth + (65536 * characterHeight)) 
EndProcedure 



OpenConsole()

ConsoleBufferSize(GetStdHandle_(#STD_OUTPUT_HANDLE), 79, 30)

Input()
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Resize Console Buffer

Post by Demivec »

@armixeight: a note regarding the parameters for the function SetConsoleScreenBufferSize_(). It takes a COORD structure, not a pointer to a COORD structure.

Like this:

Code: Select all

SetConsoleScreenBufferSize_(stdout, newSize\y << 16 + newSize\x)
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: Resize Console Buffer

Post by eesau »

Dwarf Fortress' window isn't a console, it's rendered graphics. That's what I suggest you do as well, as working with a console only is very limited.
armixeight
New User
New User
Posts: 9
Joined: Sun Sep 13, 2009 4:34 am

Re: Resize Console Buffer

Post by armixeight »

TomS:
Thank you so very much, that is exactly what I needed. Thank you!

Demivec:
I would also like to thank you for helping me understand I bit more about COORD structures and how to implement them.

And finally essau:
You said "Dwarf Fortress' window isn't a console, it's rendered graphics. That's what I suggest you do as well".
How would you accomplish this Rendered Graphics alternative. I really would like to learn about this. Thanks.
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Resize Console Buffer

Post by TomS »

Demivec wrote:...SetConsoleScreenBufferSize_() [...] takes a COORD structure, not a pointer to a COORD structure
Figured that one, too. But didn't work either :|
Seems like the SetConsoleWindowInfo() with a matching RECT is mandatory.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Resize Console Buffer

Post by Demivec »

TomS wrote:
Demivec wrote:...SetConsoleScreenBufferSize_() [...] takes a COORD structure, not a pointer to a COORD structure
Figured that one, too. But didn't work either :|
Seems like the SetConsoleWindowInfo() with a matching RECT is mandatory.
@TomS: It had foiled my first attempts also. :)

For the sake of completeness, here's the original example with the needed change extracted from the helpful code in the CodeArchive:

Code: Select all

OpenConsole()
stdout=GetStdHandle_(#STD_OUTPUT_HANDLE)

newSize.COORD
newSize\x=80
newSize\y=23

rect.SMALL_RECT
rect\right = newSize\x - 1
rect\bottom = newSize\y - 1
SetConsoleWindowInfo_(stdout, 1, @rect)
SetConsoleScreenBufferSize_(stdout, newSize\x + newSize\y << 16)
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Resize Console Buffer

Post by Zach »

From what I can tell it's an ASCII art game, at least according to its Features page..
Extended ASCII character set rendered in 16 colors (including black) as well as 8 background colors (including black).
How that ultimately gets to the screen I don't know.. So maybe that's what he was saying.. Anyhow you'd probably want to look at something like Graphical Console mode, but that is restricted to Windows only, so cross-platform would not work if that were one of your goals.
Post Reply