I write some macro to simplify the console programming.because I will output TOO MANY contents to fit the console window buffer, I need scroll up the window.but it seems that my action of scroll is useless and error happened:random blank rows in my output sometimes Who can tell me why? Thanks all! :stupid:

;====Macro I Defined==============

.data?
ConsoleScr_BufInfo CONSOLE_SCREEN_BUFFER_INFO {}
srctScrollRect SMALL_RECT {}
destScrollRect SMALL_RECT {}
coordDest DWORD ?
Charinfo CHAR_INFO {}
ConsoleCur_Info1 CONSOLE_CURSOR_INFO {}
ConsoleCur_Info2 CONSOLE_CURSOR_INFO {}
hStdOut DWORD ?
CurPos DWORD ?
szBlank db (MAX_PATH + 4) dup(?)

InitConsoleWindow macro
push esi
push edi

invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hStdOut, eax

invoke GetConsoleCursorInfo, hStdOut, addr ConsoleCur_Info1
mov ecx,sizeof(CONSOLE_CURSOR_INFO)
lea esi, ConsoleCur_Info1
lea edi, ConsoleCur_Info2
rep movsb

mov (CONSOLE_CURSOR_INFO ptr ).bVisible,FALSE
invoke SetConsoleCursorInfo, hStdOut, addr ConsoleCur_Info2

invoke GetConsoleScreenBufferInfo, hStdOut, addr ConsoleScr_BufInfo
lea edx, ConsoleScr_BufInfo
mov eax,(CONSOLE_SCREEN_BUFFER_INFO ptr ).dwCursorPosition
mov CurPos, eax

lea edx, srctScrollRect
lea ecx, destScrollRect
mov (SMALL_RECT ptr ).Left, 0
mov (SMALL_RECT ptr ).Left, 0
mov (SMALL_RECT ptr ).Top,1
mov (SMALL_RECT ptr ).Top, 0
mov ax, (CONSOLE_SCREEN_BUFFER_INFO ptr ).dwMaximumWindowSize.x
dec ax
mov (SMALL_RECT ptr ).Right, ax
mov (SMALL_RECT ptr ).Right, ax
mov ax, (CONSOLE_SCREEN_BUFFER_INFO ptr ).dwMaximumWindowSize.y
dec ax
mov (SMALL_RECT ptr ).Bottom, ax
mov (SMALL_RECT ptr ).Bottom, 1

mov coordDest, 0

lea edx, Charinfo
mov (CHAR_INFO ptr ).Attributes, BACKGROUND_GREEN or FOREGROUND_RED
mov (CHAR_INFO ptr ).Char.AsciiChar, " "


lea edi, szBlank
mov ecx, MAX_PATH
mov al," "
rep stosb
mov BYTE ptr ,0

pop edi
pop esi
endm

UnInitConsoleWindow macro
invoke SetConsoleCursorInfo, hStdOut, addr ConsoleCur_Info1
endm

StdOutInCurPos macro lpStr
invoke SetConsoleCursorPosition, hStdOut, CurPos
invoke StdOut, addr szBlank
invoke SetConsoleCursorPosition, hStdOut, CurPos
invoke StdOut,lpStr
endm

IncCurPos macro
CRLF

invoke GetConsoleScreenBufferInfo, hStdOut, addr ConsoleScr_BufInfo
lea edx, ConsoleScr_BufInfo
movzx eax,(CONSOLE_SCREEN_BUFFER_INFO ptr ).dwCursorPosition.y
movzx ecx,(CONSOLE_SCREEN_BUFFER_INFO ptr ).dwSize.y
sub ecx, eax
.if ecx < 3;if need scroll up.
invoke ScrollConsoleScreenBuffer, hStdOut, addr srctScrollRect, addr srctScrollRect, coordDest, addr Charinfo
.else
mov eax,(CONSOLE_SCREEN_BUFFER_INFO ptr ).dwCursorPosition
mov CurPos, eax
.endif
endm
;======ENd of Macro==================


Thanks all!;)
Posted on 2002-12-02 07:32:29 by smallwaves
:confused:
Posted on 2002-12-04 06:32:45 by smallwaves
on a quick look i've saw that GetStdHandle returns 0 instead the handle and
GetConsoleCursorInfo returns INVALID_HANDLE error.

i will try to see where is the problem. what is weird is that it shows in ConTEXT
output console ... hmmm


dumb me ... i compiled as GUI instead of console
have tried converting the code from win32.hlp/Scrolling a Screen Buffer's Contents ?
Posted on 2002-12-04 07:37:13 by TBD