changing the text color in DOS possible?

BlitzMax Forums/BlitzMax Programming/changing the text color in DOS possible?

im not sure if its possible but could you change the color for DOS using blitzmax. its for a blitzmax program im working on and i dunno if thats possible

If you use Windows you could use the console API calls.
Otherwise I think it's one of those things that's hard to make crossplatform without core BlitzMax support for it.

no im not making a cross platform. Its just for windows. also what api calls do i need to do?

Can't remember. Search MSDN.com. I can remember that you use SetConsoleTextAttribute to set the fore/background color of the text so maybe that's a starting point.

Heres a link to a quick example im C++: http://support.microsoft.com/default.aspx?scid=kb;en-us;104094

Hello.

Can't remember, but can't you change the prompt and throw in some ANSI codes...or was that the Amiga? (It's been a while :o) )

Goodbye.

Here you go, pretty simple

Edit: And oh btw its probably not the best idea to post the same topic multiple times (you've posted it in the beginners area as well)

' Simple console color example
' Written by Tim Leonard (Aka. Helios)

' Setup compiler
SuperStrict

' Import win32 functions
Extern "Win32"
	Function SetConsoleTextAttribute:Int(hConsoleOutput:Int Ptr,wAttributes:Int)
	Function GetStdHandle:Int Ptr(nStdHandle:Int)
End Extern

' A few usefull constants
Const STD_OUTPUT_HANDLE:Int = -11;
Const COLOR_BLACK:Int	= $0000
Const COLOR_BLUE:Int 	= $0001
Const COLOR_GREEN:Int 	= $0002 
Const COLOR_CYAN:Int 	= $0003
Const COLOR_RED:Int	= $0004
Const COLOR_MAGENTA:Int= $0005
Const COLOR_YELLOW:Int = $0006
Const COLOR_GREY:Int 	= $0007
Const COLOR_WHITE:Int 	= $0008

' Print out some junk to test the colors
Print "Hello world!"
SetConsoleColor(COLOR_RED|COLOR_WHITE) ; Print "Hello world!"
SetConsoleColor(COLOR_GREEN,True) 	   ; Print "Hello world!"

' Wait till somone presses a key
Print "Done, press any key to exit"
While Not AppTerminate()
Wend

' Sets the color of the console
Function SetConsoleColor(Color:Int,Background:Int = False)
	If Background = True Then Color:*$0010
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Color)	
End Function


Sorry to bump an old thread, but with 1.24 running the above code and pressing the "X" in the console window crashes.

(compiled as non gui app)

Does anyone have a work around or fix for it ?

It doesn crash actualy, but it is non-responsive so windows has to terminate it abnormaly.

Its because of this code:
' Wait till somone presses a key
Print "Done, press any key to exit"
While Not AppTerminate()
Wend


It seems polled input is only activated by a call to Graphics, (and possibly MaxGUI canvas?)

Its better to use feks Input()

or something like:
' Wait till somone presses a key
Print "Done, press any key to exit"
While Not getch()
	Delay 20 ' avoids eating cpu
Wend
End
Extern "C"
	Function getch:Int()
EndExtern


EDIT: i see now it doesnt realy solve the "crash" ;) but atleast it exits on key-press hehe.

More to the point, shouldn't clicking on the (X) on a console window generate an AppTerminate() event...

More to the point, shouldn't clicking on the (X) on a console window generate an AppTerminate() event...
EVENT_APPTERMINATE only works on Macs AFAIK.