Created
September 19, 2013 15:05
-
-
Save fushnisoft/6624857 to your computer and use it in GitHub Desktop.
Clarion console app!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member() | |
Include('ConsoleSupport.inc'),ONCE | |
Map | |
MODULE('32-bit Windows API') | |
! General functions | |
GetLastError(),DWORD,PASCAL | |
! Console functions | |
GetStdHandle(DWORD),HANDLE,PASCAL,PROC,RAW | |
WriteConsole(Handle,Long,Dword,long,long),bool,Raw,Pascal,name('WriteConsoleA') | |
ReadConsole(Handle,Long,Dword,long,long),bool,Raw,Pascal,name('ReadConsoleA') | |
SetConsoleTitle(Long),Bool,Raw,Pascal,name('SetConsoleTitleA') | |
GetConsoleTitle(Long,dword),Bool,Raw,Pascal,name('GetConsoleTitleA') | |
SetConsoleMode(Handle,dWord),BOOL,RAW,PASCAL | |
GetConsoleMode(Handle,Long),BOOL,RAW,PASCAL | |
End | |
End | |
ConsoleSupport.Construct PROCEDURE | |
CODE | |
ConsoleSupport.Destruct PROCEDURE | |
CODE | |
ConsoleSupport.Init PROCEDURE () !,BYTE,VIRTUAL | |
CODE | |
SELF.OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE) | |
If SELF.OutputHandle = INVALID_HANDLE_VALUE | |
Halt(1,'Unable to get output handle (' & GetLastError() & ')') | |
RETURN INVALID_HANDLE_VALUE | |
End | |
SELF.InputHandle = GetStdHandle(STD_INPUT_HANDLE) | |
if SELF.InputHandle = INVALID_HANDLE_VALUE | |
Halt(2,'Unable to get console input handle (' & GetLastError() & ')') | |
RETURN INVALID_HANDLE_VALUE | |
End | |
If ~SetConsoleMode(SELF.InputHandle,ENABLE_PROCESSED_INPUT ) | |
Halt(3,'Unable to set console mode (' & GetLastError() & ')') | |
RETURN INVALID_OTHER | |
End | |
RETURN FALSE | |
ConsoleSupport.WriteLine PROCEDURE (STRING pText) !,BYTE,PROC,VIRTUAL | |
CODE | |
SELF.TextBuffer = pText & '<13,10>' | |
If WriteConsole(SELF.OutputHandle, ADDRESS(SELF.TextBuffer), LEN(SELF.TextBuffer),ADDRESS(SELF.BytesWritten), NULL) = 0 | |
Halt(4,'WriteConsoleError (' & GetLastError() & ')') | |
RETURN -1 | |
End | |
RETURN FALSE | |
Consolesupport.ReadKey PROCEDURE () !,STRING,PROC,VIRTUAL | |
CODE | |
SELF.WriteLine('Press any key to continue...') | |
Clear(SELF.InBuffer) | |
Loop | |
IF ReadConsole(SELF.InputHandle,Address(SELF.InBuffer),100,Address(SELF.BytesRead),NULL) = 0 THEN | |
Halt(5,'Error on read console (' & GetLastError() & ')') | |
Break | |
End | |
Until SELF.BytesRead > 0 | |
RETURN SELF.InBuffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ConsoleSupport_ EQUATE(1) | |
HANDLE EQUATE(UNSIGNED) | |
DWORD EQUATE(ULONG) | |
INVALID_HANDLE_VALUE EQUATE(-1) | |
INVALID_OTHER EQUATE(-2) | |
NULL EQUATE(0) | |
!************************************************************************************************************ | |
! Console-specific EQUATEs | |
!************************************************************************************************************ | |
ENABLE_PROCESSED_INPUT EQUATE(1) ! Input Mode flags | |
ENABLE_LINE_INPUT EQUATE(2) | |
ENABLE_ECHO_INPUT EQUATE(4) | |
ENABLE_WINDOW_INPUT EQUATE(8) | |
ENABLE_MOUSE_INPUT EQUATE(16) | |
ENABLE_PROCESSED_OUTPUT EQUATE(1) ! Output Mode flags | |
ENABLE_WRAP_AT_EOL_OUTPUT EQUATE(2) | |
STD_INPUT_HANDLE EQUATE(-10) ! Standard input and output handles | |
STD_OUTPUT_HANDLE EQUATE(-11) | |
STD_ERROR_HANDLE EQUATE(-12) | |
CONSOLE_TEXTMODE_BUFFER EQUATE(1) ! The type of console screen buffer to create | |
ATTACH_PARENT_PROCESS EQUATE(-1) | |
ConsoleSupport Class(),Type,Module('ConsoleSupport.Clw'),LINK('ConsoleSupport.Clw',1) | |
! Properties | |
InputHandle Handle | |
OutputHandle Handle | |
TextBuffer CString(2048) | |
OutBuffer CString(2048) | |
InBuffer CString(2048) | |
BytesWritten Long | |
BytesRead Long | |
! Methods | |
Construct PROCEDURE | |
Destruct PROCEDURE () ,VIRTUAL | |
Init PROCEDURE () ,BYTE,PROC,VIRTUAL | |
WriteLine PROCEDURE (STRING pText) ,BYTE,PROC,VIRTUAL | |
ReadKey PROCEDURE () ,STRING,PROC,VIRTUAL | |
END | |
!_EndOfInclude_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME 'CONSOLETEST' CUI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROGRAM | |
Include('ConsoleSupport.inc'),ONCE | |
MAP | |
END | |
Console ConsoleSupport | |
CODE | |
IF Console.Init() | |
Halt() | |
END | |
Console.WriteLine('*** Clarion console app! ***') | |
! ======================= | |
! Do your stuff in here | |
! ======================= | |
! ======================= | |
Console.ReadKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment