FillConsoleOutputAttribute_()

Just starting out? Need help? Post your questions and find answers here.
ShadowRunnaX
User
User
Posts: 33
Joined: Wed Oct 27, 2004 4:36 pm
Location: South East England

FillConsoleOutputAttribute_()

Post 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
--
ShadowRunnaX
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Post by Killswitch »

I tried that with clearscreen and it didn't work. Anybody else have any ideas?
~I see one problem with your reasoning: the fact is thats not a chicken~
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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()
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Nice example, Sparkie. :)

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

Code: Select all

conOut = OpenConsole()
Good programmers don't comment their code. It was hard to write, should be hard to read.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks traumatic :)

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

PB 5.21 LTS (x86) - Windows 8.1
Post Reply