right ive had a spare half hour so here is my framework for the console window cleaned up a bit.
the reason im posting this is for anyone else to look at/use before i go and add some demo specific stuff.
#include "windows.bi"
Type AsciiWindow
ScreenWidth As Integer
ScreenHeight As Integer
Origin As COORD
Dimensions As SMALL_RECT
CHwnd As HANDLE
Size As COORD
WndPtr As CHAR_INFO Ptr
End Type
Declare Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
Declare Function SetUpAsciiWindow( ByVal X As Integer = 0 , ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
Declare Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )
Dim Shared MyTextWnd As AsciiWindow Ptr
MyTextWnd = SetUpAsciiWindow( 0, 0, 80, 50 )
While Not Inkey$ = chr(27)
For Y = 0 to 80 * 50
If Y And 1 Then
MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 40 )
MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 4 )
Else
MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 1 )
End If
Next
FlipAsciiBuffers( MyTextWnd )
ClearAsciiBuffers( MyTextWnd )
Wend
KillAsciiWindow( MyTextWnd )
Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
For Y = 1 To 80 * 50
Buffer->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
Buffer->WndPtr[Y].Attributes = 0
Next
End Sub
Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
WriteConsoleOutput( Buffer->CHwnd , Buffer->WndPtr , Buffer->Size , Buffer->Origin , @Buffer->Dimensions )
End Sub
Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )
Return FCol + ( BCol Shl 4 )
End Function
Function SetUpAsciiWindow( ByVal X As Integer = 0 ,ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
Dim As AsciiWindow Ptr TmpWindow
TmpWindow = CAllocate( SizeOf( AsciiWindow ) )
TmpWindow->ScreenWidth = Wdth
TmpWindow->ScreenHeight = Hght
TmpWindow->WndPtr = CAllocate( TmpWindow->ScreenWidth * TmpWindow->ScreenHeight * Sizeof( AsciiWindow ) )
TmpWindow->Size.X = TmpWindow->ScreenWidth
TmpWindow->Size.Y = TmpWindow->ScreenHeight
TmpWindow->Origin.X = X
TmpWindow->Origin.Y = Y
TmpWindow->Dimensions.Left = 0
TmpWindow->Dimensions.Top = 0
TmpWindow->Dimensions.Right = TmpWindow->ScreenWidth - 1
TmpWindow->Dimensions.Bottom = TmpWindow->ScreenHeight - 1
TmpWindow->CHwnd = CreateConsoleScreenBuffer( GENERIC_WRITE Or GENERIC_READ , 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)
SetConsoleActiveScreenBuffer( TmpWindow->CHwnd )
SetConsoleScreenBufferSize( TmpWindow->CHwnd, TmpWindow->Size )
SetConsoleWindowInfo( TmpWindow->CHwnd, TRUE, @TmpWindow->Dimensions )
Return TmpWindow
End Function
Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
If ( AscWindow ) Then
If ( AscWindow->WndPtr ) Then
Deallocate( AscWindow->WndPtr )
End If
Deallocate( AscWindow )
End If
End Sub