Page 1 of 1

FillConsoleOutputAttribute_()

Posted: Sat Jun 11, 2005 10:45 pm
by ShadowRunnaX
I was tryna make the background colour for a console change by usin' WinAPI, so I used this, but it don't work:-

Code: Select all

 OpenConsole()
               
               Bob.COORD
               Bob\X=1
               Bob\Y=1
               
               conOut = GetStdHandle_(#STD_OUTPUT_HANDLE) 
              
           FillConsoleOutputAttribute_(conOut,#BACKGROUND_BLUE,80*50,B
           ob,1)
               Delay(5000)
           

'Cos I ain't that good at API, please help me in a way I'd understand please.
Thanks in advance

Posted: Sat Jun 11, 2005 11:18 pm
by dell_jockey
my first hunch is to clear the screen as soon as the new attribute is set. Didn't test it, but that is how consoles worked in the old days...

Posted: Sun Jun 12, 2005 12:07 am
by Killswitch
I tried that with clearscreen and it didn't work. Anybody else have any ideas?

Posted: Sun Jun 12, 2005 2:59 am
by Sparkie
Here's a starting point. The key to this is the COORD structure needs to be a long. We do this with the MakeLong() procedure.

Code: Select all

Procedure MakeLong(lo.w, hi.w) 
  ProcedureReturn (hi * $10000) | (lo & $FFFF) 
EndProcedure

OpenConsole() 
ConsoleLocate(30, 10)
conOut = GetStdHandle_(#STD_OUTPUT_HANDLE)
PrintN("Hello World!")
conC.COORD 
conC\x=0
conC\y=0 
sbi.CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo_(conOut, @sbi)
FillConsoleOutputAttribute_(conOut, #FOREGROUND_GREEN | #FOREGROUND_RED | #BACKGROUND_BLUE, sbi\dwSize\x * sbi\dwSize\y, MakeLong(conC\x, conC\y), @aOut) 
SetConsoleTextAttribute_(conOut, #FOREGROUND_GREEN | #FOREGROUND_RED | #BACKGROUND_BLUE)
w$ = "Yellow on Blue"
ConsoleLocate(29, 12)
WriteConsole_(conOut, @w$, Len(w$), @wOut, 0)
Input()
CloseConsole()

Posted: Sun Jun 12, 2005 11:36 am
by traumatic
Nice example, Sparkie. :)

BTW, OpenConsole() already returns the console handle, so
GetStdHandle_() isn't necessarily needed.

Code: Select all

conOut = OpenConsole()

Posted: Sun Jun 12, 2005 2:51 pm
by Sparkie
Thanks traumatic :)

It was a post on Google that led to my success with the COORD to LONG. ;)