News:

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

SetConsoleMode

Started by redskull, September 19, 2005, 04:06:23 PM

Previous topic - Next topic

redskull

Can anybody explain how to set SetConsoleMode() to not wrap around, but to still process Non Printing Characters?
When set the value to 03h, a test string terimnated with 13,10 prints like it should; the string over and over, each on a new line, the window automatically scrolling.  When I set it to 02h, it also behaves as expected; the string over and over, but the 13,10 have turned into the prinatble equivalents, and the string is not moved down to the new line, but it still wraps at the end of the line and the window scrolls.  When I set it to 00h, i get the string without the line breaks, but it stops wrapping and scrolling.  Again, all of these are as expected;
But when when I set it to 01h, I get the same output as 03h.  Each string is printed on a new line, like it's supposed to, but the window keeps on scrolling and advancing the buffer?  Is there any way to turn off the window automatically scolling when the cursor position is set outside the window limit?

alan
Strange women, lying in ponds, distributing swords, is no basis for a system of government

MichaelW

If I understand you correctly, the problem is that the string is wrapping in the screen buffer. You can correct this by increasing the width of the screen buffer.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hConsoleOutput  dd 0
      cMode           dd 0
      csbi            CONSOLE_SCREEN_BUFFER_INFO <>
      teststr         db 126 dup("X"),"Y",0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetStdHandle, STD_OUTPUT_HANDLE
    mov   hConsoleOutput, eax

    invoke GetConsoleMode, hConsoleOutput, ADDR cMode
    print chr$("output mode = ")
    print uhex$(cMode),13,10
    invoke SetConsoleMode, hConsoleOutput, ENABLE_PROCESSED_OUTPUT
    invoke GetConsoleMode, hConsoleOutput, ADDR cMode
    print chr$("output mode = ")
    print uhex$(cMode),13,10

    invoke GetConsoleScreenBufferInfo, hConsoleOutput, ADDR csbi
    print chr$("console screen buffer rows = ")
    movzx eax, csbi.dwSize.y
    print ustr$(eax)
    print chr$(13,10,"console screen buffer cols = ")
    movzx eax, csbi.dwSize.x
    print ustr$(eax)
    mov   eax, input(13,10,"Press enter to continue...")

    mov   ax,csbi.dwSize.y
    shl   eax,16
    mov   ax,160                  ; <<=== new width

    invoke SetConsoleScreenBufferSize,hConsoleOutput,eax

    invoke GetConsoleScreenBufferInfo, hConsoleOutput, ADDR csbi
    print chr$("console screen buffer rows = ")
    movzx eax, csbi.dwSize.y
    print ustr$(eax)
    print chr$(13,10,"console screen buffer cols = ")
    movzx eax, csbi.dwSize.x
    print ustr$(eax)
    mov   eax, input(13,10,"Press enter to continue...")

    REPEAT 20
      print ADDR teststr,13,10
    ENDM

    mov   eax, input(13,10,"Press enter to exit...")
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

redskull

I guess in a more simplified question: Is there anyway to print characters in the screen buffer outside the boundaries of the display window?  If I disable ENABLE_WRAP_AT_EOL_OUTPUT, and then SetConsoleCursorPosition() off the bottom end, why does it automatically scroll down?
Strange women, lying in ponds, distributing swords, is no basis for a system of government

MichaelW

The code I posted prints characters to the screen buffer outside the boundaries of the window (where outside means beyond the right edge of the window), without wrapping or scrolling the contents of the window horizontally. Setting the cursor position outside the boundaries of the window is different:
Quote
If the new cursor position is not within the boundaries of the console screen buffer's window, the window origin changes to make the cursor visible.

MSDN: SetConsoleCursorPosition

If you are trying to print at specific locations outside the boundaries of the window you could try saving the cursor position, setting the new position, printing the output, and restoring the saved position.


eschew obfuscation

redskull

Why do I suck?  This prints a sample string, but keeps wrapping it


.486
.model flat, stdcall
option casemap:none

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

COORD STRUCT
  x  WORD      ?
  y  WORD      ?
COORD ENDS

.const
ENABLE_WRAP_AT_EOL_OUTPUT equ 2h
STD_OUTPUT_HANDLE    equ -11
NULL          equ 0
INFINITE          equ -1

.data
outputstring db "THIS IS AN OUTPUT STRING", 13, 10
CursorXY       COORD <15,90>
.data?
nStdHandleOut  DWORD ?
Addrspace      DWORD ?

.code
start:
invoke AllocConsole                         
invoke GetStdHandle, STD_OUTPUT_HANDLE     
mov nStdHandleOut, eax           
invoke SetConsoleMode, nStdHandleOut, ENABLE_WRAP_AT_EOL_OUTPUT
invoke SetConsoleCursorPosition, nStdHandleOut, dword ptr CursorXY
invoke WriteConsole, nStdHandleOut, addr outputstring, 25, addr Addrspace, NULL
invoke Sleep, INFINITE
invoke ExitProcess, NULL
end start


again, thanks for the advice
Strange women, lying in ponds, distributing swords, is no basis for a system of government

redskull

sorry, i didn't see that last reply before I posted...

So SetConsoleCursorPosition() operated independently of the Enable_Wrap_At_EOL_Output?  That's beat..

But it also seems like writing downward(?) on the console, even though the default screen buffer is larger (80x300) in that direction, writing with WriteConsole still scrolls is up, like in

default cursor 0,0

REPEAT 100
invoke WriteConsole, nStdHandleOut, addr outputstring, 25, addr Addrspace, NULL
ENDM

woud still scroll the screen down, even though the buffer isn't full?
Strange women, lying in ponds, distributing swords, is no basis for a system of government

MichaelW

Yes, but the screen scrolls up, not down.

With ENABLE_WRAP_AT_EOL_OUTPUT, which BTW is not supported for 95/98/ME, the output will wrap when it reaches the right edge of the screen buffer.

Also, the value 25 does not include the linefeed character. Rather than counting (or in this case miscounting) characters, it would be easier to use 'SIZEOF outputstring'.

eschew obfuscation

redskull

Nothing I can do about the vertical scrolling?  That's a bummer, but i suppose that's life.  Thanks for the advice on SIZEOF, i'll start using that;

while were on the subject, what are the advantages/disadvantges (if any) of using AllocConsole with /subsystem:windows instead of /subsytem:console without AllocConsole?
Strange women, lying in ponds, distributing swords, is no basis for a system of government