; --- test ---
; Console tour number 1
; Allocate console, toggle screenmode, write to console and read from keyboard
Call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
IntControl(73, 1, 0, 0, 0)
result = udfConAllocConsole ()
Terminate(result==0,"udfConAllocConsole","could not allocate console")
title = udfConGetConsoleTitle ()
Message("Console is allocated. Get Original Console Title",title)
title = StrCat("My Console Output Test ",TimeYmdHms())
result = udfConSetConsoleTitle (title)
title = udfConGetConsoleTitle ()
Message("This is My Console Title",title)
hStdOut = udfConGetHandleStdOut ()
Terminate(hStdOut==-1,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
Terminate(hStdIn==-1,"udfConGetHandleStdIn","cannot get handle")
WinActivate(title)
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 1.%@crlf%")
Terminate(result==0,"udfConWriteConsole","could not write to console")
TimeDelay(3)
result = udfConWriteConsole (hStdOut, "Window should be in Fullscreen mode.%@crlf%")
TimeDelay(3)
; toggle screen mode
If udfConIsConsoleFullScreen ()
result = udfConToggleConsoleState ()
EndIf
state = ItemExtract(1+udfConIsConsoleFullScreen(),"Window,Fullscreen",",")
result = udfConWriteConsole (hStdOut, "The Window is in %state% mode.%@crlf%")
If !udfConIsConsoleFullScreen ()
If (WinState(title)==@normal)
result = udfConWriteConsole (hStdOut, "Now You can try to resize the console window with the mouse ...%@crlf%")
TimeDelay(10)
EndIf
EndIf
result = udfConWriteConsole (hStdOut, "... still 5 seconds left ...%@crlf%")
TimeDelay(5)
; toggle screen mode
If !udfConIsConsoleFullScreen ()
result = udfConToggleConsoleState ()
EndIf
state = ItemExtract(1+udfConIsConsoleFullScreen(),"Window,Fullscreen",",")
result = udfConWriteConsole (hStdOut, "The Window is in %state% mode.%@crlf%")
TimeDelay(5)
result = udfConWriteConsole (hStdOut, StrCat("Type in a line and press Enter to quit:",@crlf))
inputstr = udfConReadConsole (hStdIn)
Terminate(result==0,"udfConReadConsole","could not read from console")
result = udfConWriteConsole (hStdOut, StrCat("OK. No more input please.",@crlf))
TimeDelay(3)
; toggle WinState
result = udfConToggleConsoleState ()
TimeDelay(3)
Message("Your last console input was ...",inputstr)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
TimeDelay(3)
:cancel
:wberrorhandler
If IsDefined(hStdIn) Then result = udfCloseHandle (hStdIn)
If IsDefined(hStdOut) Then result = udfCloseHandle (hStdOut)
result = udfConFreeConsole ()
Exit
; --- test ---
; Console tour number 2
; Allocate console, toggle cursor, set cursor
Call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
IntControl(73, 1, 0, 0, 0)
result = udfConAllocConsole ()
If (result==0) Then Terminate(@yes!=AskYesNo("udfConAllocConsole","Unable to allocate console.%@crlf%Try to use existing console?"),"","")
title = StrCat("My Console Output Test ",TimeYmdHms())
result = udfConSetConsoleTitle (title)
hStdOut = udfConGetHandleStdOut ()
Terminate(hStdOut==-1,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
Terminate(hStdIn==-1,"udfConGetHandleStdIn","cannot get handle")
WinActivate(title)
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 2.%@crlf%")
Terminate(result==0,"udfConWriteConsole","could not write to console")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "Window should be in Fullscreen mode.%@crlf%")
TimeDelay(3)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
TimeDelay(3)
result = udfConWriteConsole (hStdOut, "%@crlf%We will make some cursor tests:%@crlf%")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "Cursor should be visible, do you see the cursor blinking?%@crlf%")
result = udfConWriteConsole (hStdOut, "Please type in 'yes' or 'no' and press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, StrCat('Your answer was: "',inputstr,'"',@crlf))
TimeDelay(3)
result = udfConSetCursorInfo (hStdOut, "12 0")
result = udfConWriteConsole (hStdOut, "Cursor should be invisible, do you see the cursor blinking?%@crlf%")
result = udfConWriteConsole (hStdOut, "Please type in 'yes' or 'no' and press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, StrCat('Your answer was: "',inputstr,'"',@crlf))
result = udfConSetCursorInfo (hStdOut, "12 1")
result = udfConWriteConsole (hStdOut, @crlf)
TimeDelay(3)
cursorinfo = "50 1"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Cursor should be visible, about half cell block. Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
cursorinfo = "44 0"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Cursor should be invisible. Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
cursorinfo = "66 1"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Cursor should be visible. Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
cursorinfo = "99 1"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Cursor should be visible, full cell block. Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
cursorinfo = "100 1"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
cursorinfo = "12 1"
result = udfConWriteConsole (hStdOut, StrCat('udfConSetCursorInfo ("',cursorinfo,'")',@crlf))
result = udfConSetCursorInfo (hStdOut, cursorinfo)
cursorinfo = udfConGetCursorInfo (hStdOut)
result = udfConWriteConsole (hStdOut, StrCat('udfConGetCursorInfo (hStdOut) reports: "',cursorinfo,'"',@crlf))
result = udfConWriteConsole (hStdOut, "Cursor should be visible, sized as normal cursor. Press [Enter]: ")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, @crlf)
For i=1 To 24
result = udfConWriteConsole (hStdOut, @crlf)
Next
For i=0 To 7
result = udfConSetCursorPos (hStdOut, 10*i, i)
result = udfConWriteConsole (hStdOut, "We can write text at specific position")
TimeDelay(1)
Next
result = udfConSetCursorPos (hStdOut, 0, 24)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
TimeDelay(3)
:cancel
:wberrorhandler
If IsDefined(hStdIn) Then result = udfCloseHandle (hStdIn)
If IsDefined(hStdOut) Then result = udfCloseHandle (hStdOut)
result = udfConFreeConsole ()
Terminate(result==0,"udfConFreeConsole","unable to free console")
Exit
; --- test ---
; Console tour number 3
; Allocate console, create another screenbuffer, toggle buffers
Call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
IntControl(73, 1, 0, 0, 0)
result = udfConAllocConsole ()
If (result==0) Then Terminate(@yes!=AskYesNo("udfConAllocConsole","Unable to allocate console.%@crlf%Try to use existing console?"),"","")
title = StrCat("My Console Output Test ",TimeYmdHms())
result = udfConSetConsoleTitle (title)
hStdOut = udfConGetHandleStdOut ()
Terminate(hStdOut==-1,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
Terminate(hStdIn==-1,"udfConGetHandleStdIn","cannot get handle")
WinActivate(title)
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 3.%@crlf%")
Terminate(result==0,"udfConWriteConsole","could not write to console")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "Window should be in Fullscreen mode.%@crlf%")
TimeDelay(3)
result = udfConWriteConsole (hStdOut, "%@crlf%We can have more than one screen to write to or read from.%@crlf%")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "This is screen one.%@crlf%")
TimeDelay(1)
info0 = udfConGetScreenBufferInfo (hStdOut, 0)
info1 = udfConGetScreenBufferInfo (hStdOut, 1)
info2 = udfConGetScreenBufferInfo (hStdOut, 2)
info3 = udfConGetScreenBufferInfo (hStdOut, 3)
info4 = udfConGetScreenBufferInfo (hStdOut, 4)
info5 = udfConGetScreenBufferInfo (hStdOut, 5)
info6 = udfConGetScreenBufferInfo (hStdOut, 6)
info7 = udfConGetScreenBufferInfo (hStdOut, 7)
info8 = udfConGetScreenBufferInfo (hStdOut, 8)
info9 = udfConGetScreenBufferInfo (hStdOut, 9)
info10 = udfConGetScreenBufferInfo (hStdOut, 10)
info11 = udfConGetScreenBufferInfo (hStdOut, 11)
result = udfConWriteConsole (hStdOut, "The metrics are:%@crlf%")
result = udfConWriteConsole (hStdOut, "All screenbuffer values in a tab list:%@crlf%")
result = udfConWriteConsole (hStdOut, StrCat(info0,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Screenbuffer Size X : ",info1,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Screenbuffer Size Y : ",info2,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Cursor Position X : ",info3,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Cursor Position Y : ",info4,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Character Attribut : ",info5,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Win top left Pos X : ",info6,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Win top left Pos Y : ",info7,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Win bottom right Pos X : ",info8,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Win bottom right Pos Y : ",info9,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Console Win Max Size X : ",info10,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Console Win Max Size Y : ",info11,@crlf))
info12 = udfConGetMaxWindowSize (hStdOut, 1)
info13 = udfConGetMaxWindowSize (hStdOut, 2)
result = udfConWriteConsole (hStdOut, StrCat("Largest Console Window Size X : ",info12,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Largest Console Window Size Y : ",info13,@crlf))
info14 = udfConGetInputCP ()
info15 = udfConGetOutputCP ()
result = udfConWriteConsole (hStdOut, StrCat("Codepage Input : ",info14,@crlf))
result = udfConWriteConsole (hStdOut, StrCat("Codepage Output : ",info15,@crlf))
DropWild("info*")
result = udfConWriteConsole (hStdOut, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, "We create another screenbuffer ...%@crlf%")
result = udfConWriteConsole (hStdOut, "... and activate it ...%@crlf%")
TimeDelay(3)
GENERIC_WRITE = 1073741824 ; 2**30
GENERIC_READ = 2147483648 ; 2**31
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2
DesiredAccess = GENERIC_WRITE|GENERIC_READ
ShareMode = FILE_SHARE_WRITE|FILE_SHARE_READ
hOutTwo = udfConCreateScreenBuffer (DesiredAccess, ShareMode)
Terminate(hOutTwo==-1,"udfConCreateScreenBuffer","cannot get handle")
result = udfConSetActiveScreenBuffer (hOutTwo)
result = udfConWriteConsole (hOutTwo, "We use the new handle to write to screen two.%@crlf%")
result = udfConWriteConsole (hOutTwo, "We can also read from keyboard using the known StdIn handle.%@crlf%")
result = udfConWriteConsole (hOutTwo, "Type something, input will be echoed to this screen, and press [Enter] ...%@crlf%")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hOutTwo, "That's great!%@crlf%")
result = udfConWriteConsole (hOutTwo, StrCat(StrUpper(inputstr),@crlf))
result = udfConWriteConsole (hOutTwo, "%@crlf%Switching to screen one ...%@crlf%")
result = udfConWriteConsole (hOutTwo, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConSetActiveScreenBuffer (hStdOut)
result = udfConWriteConsole (hStdOut, "%@crlf%Switching to screen two ...%@crlf%")
result = udfConWriteConsole (hStdOut, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConSetActiveScreenBuffer (hOutTwo)
TimeDelay(1)
result = udfConWriteConsole (hOutTwo, "The metrics are:%@crlf%")
result = udfConWriteConsole (hOutTwo, "All screenbuffer values in a tab list:%@crlf%")
info0 = udfConGetScreenBufferInfo (hOutTwo, 0)
result = udfConWriteConsole (hOutTwo, StrCat(info0,@crlf))
result = udfConWriteConsole (hOutTwo, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConSetActiveScreenBuffer (hStdOut)
result = udfConSetCursorPos (hStdOut, 0, 24)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
TimeDelay(3)
Message("Console Tour 3","Done.")
:cancel
:wberrorhandler
If IsDefined(hStdIn) Then result = udfCloseHandle (hStdIn)
If IsDefined(hStdOut) Then result = udfCloseHandle (hStdOut)
If IsDefined(hOutTwo) Then result = udfCloseHandle (hOutTwo)
result = udfConFreeConsole ()
Terminate(result==0,"udfConFreeConsole","unable to free console")
Exit
; --- test ---
; Console tour number 4
; Allocate console, read from screen
Call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
IntControl(73, 1, 0, 0, 0)
result = udfConAllocConsole ()
If (result==0) Then Terminate(@yes!=AskYesNo("udfConAllocConsole","Unable to allocate console.%@crlf%Try to use existing console?"),"","")
title = StrCat("My Console Output Test ",TimeYmdHms())
result = udfConSetConsoleTitle (title)
hStdOut = udfConGetHandleStdOut ()
Terminate(hStdOut==-1,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
Terminate(hStdIn==-1,"udfConGetHandleStdIn","cannot get handle")
WinActivate(title)
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 4.%@crlf%")
Terminate(result==0,"udfConWriteConsole","could not write to console")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "Window should be in Fullscreen mode.%@crlf%")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "%@crlf%We can read characters from the screen.%@crlf%")
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "%@crlf%Reading floating 24 bytes from line 1, starting at column 10:%@crlf%")
TimeDelay(1)
bbattr = udfBinaryAllocAttrBuf (24) ; allocate a buffer to store the attributes
result = udfConReadOutputAttr (hStdOut, 10, 1, 24, bbattr) ; but we do not use it in this demo
BinaryFree(bbattr) ; therefore free the attributte buffer
charstr = udfConReadOutputChar (hStdOut, 10, 1, 24)
result = udfConWriteConsole (hStdOut, StrCat('"',charstr,'"',@crlf))
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "%@crlf%Reading floating 300 bytes from row 0, starting at column 0:%@crlf%")
TimeDelay(1)
str = udfConReadOutputChar (hStdOut, 0, 0, 300)
result = udfConWriteConsole (hStdOut, StrCat('"',str,'"',@crlf,@crlf))
TimeDelay(1)
result = udfConWriteConsole (hStdOut, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConWriteConsole (hStdOut, "%@crlf%Reading region rectangle from col=5 row=1 to col=40 row=5 :%@crlf%")
bbchar = udfBinaryAllocCharAttrBuf(5, 1, 40, 5) ; allocate temporary buffer for multiple use
result = udfConReadOutputRegion (hStdOut, 5, 1, 40, 5, bbchar)
TimeDelay(3)
attr = udfConGetScreenBufferInfo (hStdOut, 5)
BinaryReplace(bbchar,Num2Char(attr),Num2Char(attr<<4),@false) ; shift color to make region visible
result = udfConWriteConsole (hStdOut, "%@crlf%We will create a new screenbuffer and paste the copied region into it.%@crlf%")
TimeDelay(1)
GENERIC_WRITE = 1073741824 ; 2**30
GENERIC_READ = 2147483648 ; 2**31
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2
DesiredAccess = GENERIC_WRITE|GENERIC_READ
ShareMode = FILE_SHARE_WRITE|FILE_SHARE_READ
hOutTwo = udfConCreateScreenBuffer (DesiredAccess, ShareMode)
Terminate(hOutTwo==-1,"udfConCreateScreenBuffer","cannot get handle")
result = udfConSetActiveScreenBuffer (hOutTwo)
result = udfConWriteConsole (hOutTwo, "%@crlf%Pasting rectangle to another place on screen two:%@crlf%")
result = udfConWriteOutputRegion (hOutTwo, 15, 6, 50, 10, bbchar)
BinaryFree(bbchar) ; if we do not use the buffer anymore, then we can free it
TimeDelay(1)
result = udfConWriteConsole (hOutTwo, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = StrClean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConSetActiveScreenBuffer (hStdOut)
result = udfConSetCursorPos (hStdOut, 0, 24)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
TimeDelay(3)
Message("Console Tour 4","Done.")
:cancel
:wberrorhandler
If IsDefined(hStdIn) Then result = udfCloseHandle (hStdIn)
If IsDefined(hStdOut) Then result = udfCloseHandle (hStdOut)
result = udfConFreeConsole ()
Terminate(result==0,"udfConFreeConsole","unable to free console")
Exit
; --- test ---
; Console tour number 5
; Allocate console, and so on ... read events from inputstream
call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
intcontrol(73, 1, 0, 0, 0)
result = udfConAllocConsole ()
if (result==0) then terminate(@yes!=askyesno("udfConAllocConsole","Unable to allocate console.%@crlf%Try to use existing console?"),"","")
title = strcat("My Console Output Test ",timeymdhms())
result = udfConSetConsoleTitle (title)
hStdOut = udfConGetHandleStdOut ()
terminate(hStdOut==INVALID_HANDLE_VALUE,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
terminate(hStdIn==INVALID_HANDLE_VALUE,"udfConGetHandleStdIn","cannot get handle")
winactivate(title)
timedelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 5.%@crlf%")
terminate(result==0,"udfConWriteConsole","could not write to console")
; toggle screen mode
if !udfConIsConsoleFullScreen ()
result = udfConToggleConsoleState ()
endif
timedelay(1)
result = udfConWriteConsole (hStdOut, "Window should be in Fullscreen mode.%@crlf%")
timedelay(1)
result = udfConWriteConsole (hStdOut, "%@crlf%We will try to write some colors to the screen.%@crlf%")
timedelay(2)
; store the color attribute from this screen
Out1_Attr_old = udfConGetScreenBufferInfo (hStdOut,5)
; define new attribute
Out2_Attr = FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_BLUE
; set this screen attribute to new color
result = udfConSetTextAttribute (hStdOut, Out2_Attr)
; do not use it, but inherit the attribute to new screen
; udfConCreateScreenBuffer does a "clearscreen" with the "old" text attribute.
hOut2 = udfConCreateScreenBuffer (GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ)
terminate(hOut2==INVALID_HANDLE_VALUE,"udfConCreateScreenBuffer","cannot get handle")
; write to screen2
result = udfConSetCursorPos (hOut2, 18, 12)
result = udfConWriteConsole (hOut2, "Oh sorry, this is a blue screen message ...")
result = udfConSetActiveScreenBuffer (hOut2)
timedelay(2)
result = udfConSetCursorInfo(hOut2,"12 0")
result = udfConSetCursorPos (hOut2, 22, 14)
result = udfConWriteConsole (hOut2, "... have some time to meditate ...")
result = udfConRandomFillWindow (hOut2)
timedelay(2)
result = udfConFillScreenBuffer (hOut2, " ", 32)
result = udfConFillOutputAttr (hOut2, 30, 10, 20, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
result = udfConFillOutputAttr (hOut2, 30, 11, 20, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
result = udfConFillOutputAttr (hOut2, 30, 12, 20, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
result = udfConFillOutputAttr (hOut2, 30, 13, 20, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
result = udfConFillOutputAttr (hOut2, 30, 14, 20, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
result = udfConWriteCharStr (hOut2, 35, 12, "GAME OVER")
timedelay(5)
for i=255 to 0 by -1
result = udfConFillScreenBuffer (hOut2, num2char(i), i)
;TimeDelay(.01)
yields(1000)
next
timedelay(2)
result = udfConSetActiveScreenBuffer (hStdOut)
; set std screen attribute to old color
result = udfConSetTextAttribute (hStdOut, Out1_Attr_old)
result = udfConWriteConsole (hStdOut, @crlf)
result = udfConWriteConsole (hStdOut, "Back to ScreenBuffer 1, black and white.")
result = udfConWriteConsole (hStdOut, @crlf)
result = udfConWriteConsole (hStdOut, "Press [Enter] ...")
result = udfConFlushInputBuffer (hStdIn)
inputstr = strclean(udfConReadConsole(hStdIn),@crlf,"",0,1)
result = udfConSetActiveScreenBuffer (hStdOut)
result = udfConSetCursorPos (hStdOut, 0, 24)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
timedelay(3)
message("Console Tour 5","Done.")
:cancel
:wberrorhandler
if isdefined(hStdIn) then result = udfCloseHandle (hStdIn)
if isdefined(hStdOut) then result = udfCloseHandle (hStdOut)
result = udfConFreeConsole ()
terminate(result==0,"udfConFreeConsole","unable to free console")
exit
; --- test ---
; Console tour number 6
; DOS console shell
call("W:\WINBATCH\2001\WinBatch Test\udflib.console.wbt","")
; set wberrorhandler
intcontrol(73, 1, 0, 0, 0)
if !udfConConsoleExists ()
result = udfConAllocConsole ()
if (result==0) then terminate(@yes!=askyesno("udfConAllocConsole","Unable to allocate console.%@crlf%Try to use existing console?"),"","")
timedelay(1)
endif
title = strcat("My Console Output Test ",timeymdhms())
result = udfConSetConsoleTitle (title)
hStdOut = udfConGetHandleStdOut ()
terminate(hStdOut==INVALID_HANDLE_VALUE,"udfConGetHandleStdOut","cannot get handle")
hStdIn = udfConGetHandleStdIn ()
terminate(hStdIn==INVALID_HANDLE_VALUE,"udfConGetHandleStdIn","cannot get handle")
winactivate(title)
timedelay(1)
result = udfConWriteConsole (hStdOut, "This is Console Tour 6.%@crlf%")
terminate(result==0,"udfConWriteConsole","could not write to console")
; toggle screen mode
if udfConIsConsoleFullScreen ()
result = udfConToggleConsoleState ()
endif
timedelay(1)
result = udfConWriteConsole (hStdOut, "Console screen should be in window mode now.%@crlf%")
timedelay(1)
result = udfConWriteConsole (hStdOut, "%@crlf%We will let you do some DOS operations like ""dir"".%@crlf%")
timedelay(2)
result = udfConWriteConsole (hStdOut, "We launch command.com and give you a prompt.%@crlf%")
prompt = "WinBatch DOS-Shell (leave it with ""exit""+[Enter])%@crlf%WB>"
environset("PROMPT",prompt)
run(environment("comspec"),"/e:2048")
udfConWriteConsole (hStdOut,"If you are here now, ...%@crlf%")
timedelay(2)
udfConWriteConsole (hStdOut,"after your mighty fight against the old dos dragon ...%@crlf%")
timedelay(2)
udfConWriteConsole (hStdOut,"in the black and white dos dungeon ...%@crlf%")
timedelay(4)
udfConSetTextAttribute (hStdOut, FOREGROUND_CYAN|FOREGROUND_INTENSITY|BACKGROUND_MAGENTA|BACKGROUND_INTENSITY)
udfConWriteConsole (hStdOut,"... you have really won!%@crlf%")
timedelay(1)
udfConSetTextAttribute (hStdOut, FOREGROUND_LTGRAY)
udfConWriteConsole (hStdOut,"... some new insights ???%@crlf%")
timedelay(2)
udfConWriteConsole (hStdOut,"%@crlf%Press [Enter] to continue ...")
udfConReadConsole (hStdIn)
hOut2 = udfConCreateScreenBuffer (GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE|FILE_SHARE_READ)
terminate(hOut2==INVALID_HANDLE_VALUE,"udfConCreateScreenBuffer","cannot get handle")
udfConFillScreenBuffer (hStdOut, " ", FOREGROUND_LTGRAY|FOREGROUND_INTENSITY)
udfConSetCursorPos (hStdOut, 0, 0)
udfConWriteConsole (hStdOut,"Now we are going into a WinBatch loop.%@crlf%")
udfConWriteConsole (hStdOut,"To leave the loop use the command 'wow'.%@crlf%")
prompt = "WinBatch command loop (leave it with ""wow""+[Enter])%@crlf%WOW>"
cmdstr=""
while 1
udfConFillScreenBuffer (hStdOut, " ", FOREGROUND_LTGRAY)
udfConSetCursorPos (hStdOut, 0, 0)
udfConSetActiveScreenBuffer (hStdOut)
udfConSetTextAttribute (hStdOut, FOREGROUND_CYAN|FOREGROUND_INTENSITY|BACKGROUND_BLUE)
udfConWriteConsole (hStdOut, strfix(strcat("Last cmd: ",cmdstr)," ",320))
udfConSetTextAttribute (hStdOut, FOREGROUND_LTGRAY|FOREGROUND_INTENSITY|BACKGROUND_RED)
udfConWriteConsole (hStdOut,prompt)
udfConSetTextAttribute (hStdOut, FOREGROUND_LTGRAY)
cmdstr = udfConReadConsole (hStdIn)
cmdstr = strtrim(cmdstr)
cmdstr = strlower(cmdstr)
cmdstr = strclean(cmdstr,@crlf,"",0,1)
if (cmdstr=="wow") then break
if (strsub(cmdstr,1,4)=="copy")
ThisWnd=wingetactive()
display(3,"OH, BOY","'%cmdstr%' ERROR%@crlf%Sorry, '%cmdstr%' is not allowed today ...%@crlf%")
winactivate(ThisWnd)
continue
endif
if (strsub(cmdstr,1,4)=="move")
ThisWnd=wingetactive()
display(3,"OH, GIRL","'%cmdstr%' ERROR%@crlf%Sorry, '%cmdstr%' is not allowed tonight ...%@crlf%")
winactivate(ThisWnd)
continue
endif
udfConSetActiveScreenBuffer (hOut2)
run(environment("comspec"),strcat("/e:2048 /c ",cmdstr))
udfConWriteConsole (hOut2,"Press [Enter] to continue ...")
udfConReadConsole (hStdIn)
endwhile
udfConSetTextAttribute (hStdOut, FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE)
result = udfConSetCursorPos (hStdOut, 0, 24)
result = udfConWriteConsole (hStdOut, "... see you later consolerator ...")
timedelay(3)
message("Console Tour 6","Done.")
:cancel
:wberrorhandler
if isdefined(hStdIn) then result = udfCloseHandle (hStdIn)
if isdefined(hStdOut) then result = udfCloseHandle (hStdOut)
result = udfConFreeConsole ()
terminate(result==0,"udfConFreeConsole","unable to free console")
exit