News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scrolling console buffer

Started by Neil, July 02, 2010, 02:27:02 PM

Previous topic - Next topic

Neil

Anybody got any experience of usingĀ  ScrollConsoleScreenBuffer. I'm struggling a bit with it at the moment. I'm trying to scroll a console buffer up 1 line when it becomes full, leaving the bottom line empty, the above function seems to do exactly what I want, but, getting it to work properly is another matter.

dedndave

shouldn't be too bad - lol

use CreateFile to open a handle to CONOUT$
http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx
scroll down to about 2/3 of the page and find the section on Consoles

use GetConsoleScreenBufferInfo to get the row and column dimensions of the console window
http://msdn.microsoft.com/en-us/library/ms683171(VS.85).aspx
you need to know what values to use to specify for the scroll window (dimensions and current cursor position)
there are probably a number of ways to get this info, but this function also returns some other useful information

EDIT - another approach is to just display a carriage return/line feed and reposition the cursor
judging from your descritption, this may not suit your needs
(it only scrolls, if the cursor was at the bottom of the window)

if you still have trouble, let me know and i will play with it   :P

Neil


dedndave

i saw it   :8)
BOOL WINAPI ScrollConsoleScreenBuffer(
  __in      HANDLE hConsoleOutput,
  __in      const SMALL_RECT *lpScrollRectangle,
  __in_opt  const SMALL_RECT *lpClipRectangle,
  __in      COORD dwDestinationOrigin,
  __in      const CHAR_INFO *lpFill
);

the two functions i mentioned above provide you with the information you need to use this function

dedndave

simplification....
we can use GetStdHandle to get the handle instead of using CreateFile
http://msdn.microsoft.com/en-us/library/ms683231(v=VS.85).aspx
;get the handle for CONOUT$

        INVOKE  GetStdHandle,STD_OUTPUT_HANDLE
        mov     hStdOut,eax

Neil

i know the size of the buffer having set it with the following code :-

  .data?
    max_coord       COORD <>
    small_rect      SMALL_RECT <>
    csbi            CONSOLE_SCREEN_BUFFER_INFO <>

SMALL_RECT STRUCT
    Left      WORD      ?
    Top       WORD      ?
    Right     WORD      ?
    Bottom    WORD      ?
SMALL_RECT ENDS


.code

SetSmallRect proc ps_r:DWORD,left:DWORD,top:DWORD,right:DWORD,bottom:DWORD

    mov edx,ps_r
    mov eax,left
    mov [edx].SMALL_RECT.Left,ax
    mov eax,top
    mov [edx].SMALL_RECT.Top,ax
    mov eax,right
    mov [edx].SMALL_RECT.Right,ax
    mov eax,bottom
    mov [edx].SMALL_RECT.Bottom,ax
   
    invoke SetConsoleWindowInfo,hConsoleOutput,TRUE,ADDR small_rect
    ret
   
SetSmallRect endp


   invoke GetConsoleScreenBufferInfo,hConsoleOutput,ADDR csbi
    mov ax,41               ;make buffer 41 rows
    shl eax,16
    mov ax,csbi.dwSize.x
    invoke SetConsoleScreenBufferSize,hConsoleOutput,eax
    invoke SetSmallRect,ADDR small_rect,0,0,79,52

My problem is how to use this info in the Scroll function

dedndave

ok Neil   :U
give me a few minutes - i am scribbling something up   :P
ok - more than a few - lol - i am getting old

Neil

I,m not getting old, I AM OLD :lol

Got to leave for the moment, back later.


Neil

I'm back, Dave that's a great link  :U It's exactly the the code I'm wanting, I'll change it from C to Assembler & give it a whirl tomorrow.
Going back to that age thing I wonder who is the oldest member? I won't say how old I am but I'll give you a clue, when I was born Pearl Harbor was still in the future :wink

dedndave

it would seem like i am older, but i am not
you went and did your thing and got back and i am still farting around   :lol
i think Raymond has a couple years on me   :P

dedndave

here you go, Neil....

i even created some equates for you to play with   :bg

Neil

You have been busy, many thanks that's saved me a lot of time & given something I can build on  :U :clap: