I have changed some background attributes on a console, when I then use cls to clear the the screen it only clears the foreground text & leaves the background in a mess. Is this normal? If so I'll have to write my own proc to to do the job unless someone has already written a proc
This is old code, and not exactly what you asked for, but perhaps it will be useful.
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
include \masm32\macros\macros.asm
SetTextColor PROTO :DWORD,:DWORD
SetScreenColor PROTO :DWORD,:DWORD
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
.code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
invoke locate,0,2
mov ebx,32
mov edi,0
@@:
invoke SetTextColor,0,edi
print chr$("XX")
inc edi
dec ebx
jnz @B
mov eax,input(13,10,13,10,"Press enter to continue...")
invoke SetScreenColor,15,1
mov eax,input(13,10,"Press enter to exit...")
exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; This proc sets the foreground and background attributes for
; the characters written to the console screen buffer.
;
; The color values are normal 4-bit IRGB character mode
; attributes where:
; bit3 = intensity
; bit2 = red
; bit1 = green
; bit0 = blue
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SetTextColor proc fore:DWORD,back:DWORD
LOCAL hStdOut:DWORD
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hStdOut,eax
; The attribute is stored in a single byte.
mov eax,back
shl eax,4
or eax,fore
invoke SetConsoleTextAttribute,hStdOut,eax
ret
SetTextColor endp
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; This is the MASM32 ClearScreen procedure modified to set the
; attribute bytes for the entire screen buffer to the value
; specified by the arguments.
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
SetScreenColor proc fore:DWORD,back:DWORD
LOCAL hOutPut:DWORD
LOCAL noc :DWORD
LOCAL cnt :DWORD
LOCAL sbi :CONSOLE_SCREEN_BUFFER_INFO
;cls
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov hOutPut, eax
invoke GetConsoleScreenBufferInfo,hOutPut,ADDR sbi
mov eax, sbi.dwSize ; 2 word values returned for screen size
; -----------------------------------------------
; extract the 2 values and multiply them together
; -----------------------------------------------
push ax
rol eax, 16
mov cx, ax
pop ax
mul cx
cwde
mov cnt, eax
; The attribute is stored in a single byte.
mov edx,back
shl edx,4
or edx,fore
invoke FillConsoleOutputAttribute,hOutPut,edx,cnt,NULL,ADDR noc
ret
SetScreenColor endp
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Thanks MichaelW I'll study the code & see if can be useful
Success :U
The SetScreenColor proc works perfectly
Thanks MichaelW
See bug, http://www.masm32.com/board/index.php?topic=14565.msg117433#msg117433
But ty Michael just what I was looking for :bg