Extended ConsoleClass Functions

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Mysoft
Posts: 779
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Extended ConsoleClass Functions

Postby Mysoft » Apr 15, 2008 3:37

for those that want to have one extra debug window... that looks like the console... or that want a more like DOS console.. i have made this "class"

it have most of the user input/output functions, also i have added blink support, DOS mouse style cursor, direct access buffer, etc... (windows only)

download Console.bas
Example file ConsoleTest.bas

instructions:

Console.Create( [width], [height] )
Created a new console... only one console is allowed by applicaiton the default console (if omitted) is 80,25

Console.Destroy()
Destroy(closes) the application console.. optionally it can auto terminate the program

Console.Width( [width], [height] )
Changed the width of the console..

Console.Title( "Title" )
Sets the title of the console window

Console.cls()
Clear the console screen with the current color attributes

Console.Color( [ForeGround], [Background] )
Change the color attributes.. can be both 0 to 31 for the foreground color (to use with the blink (will disable bright colors in background)) and 0 to 15 to the background...)

Console.Locate( [Line], [Column] )
Change the current cursor position (for future printings)

Console.View( [Startline] , [Endline] )
Select the are of the winow where you can print things (equivalent to the view print instruction...

Console.echo ( "Text", [Line] , [Column] )
Draw text in the screen into the select cursor position or in the specified location, this function only draws the text, the attributes(colors) will remaing the same... and no scroll will occur (if there no space the text is clipped) and the cursor position doesnt change...

Console.write( "Text", [Line] , [Column] )
Draw colored text into the selected cursor position or in the specified location, no scroll will occur (extra text will be clipped out)

Console.print( "Text", [Line], [Column] )
Draw colored text into the selected cursos position or in the specified location, escape codes will be evaluated, scroll will occur, and the cursos position will be updated

Console.Palette( ColorNumber, Red, Green, Blue )
Console.Palette( COlorNumber, ColorReference )
Set a color in the console palette, you can do it by passing the RGB values or the integer reference..

Console.PaletteReset( [UseWindowsPalette] )
reset the palette to the default palette, if the parameter
UseWindowsPalette is non zero the windows console palette will be loaded or else the dos palette will be loaded (the dos palette have "grayed" bright colors and the "dark yellow" is brown)

Console.Lock()
Prevent the console to be updated... you're advised to use this when directly change the console buffer, so is a good pratictie to only keep the console locked for a small amount of time, since no update will occur while locked

Console.Unlock()
Unlock a previously locked window (Console.Lock) use this when youre done with directly access for the memory buffer

Console.sleep( [Period] , [DisableKeys] )
waits the espeficied amount of time or the user to press a key, the second parameter if set force to wait the specified amount of time ignoring key presses

Console.Sync( [Quantity] )
Wait the console to be updated... the quantity is just to have another synced "sleep", this instruction only works if the console update is in the automatic mode... or else it return imediatelly.

Console.Draw()
This is used to manually update the screen, it will return imediatelly if the screen is locked, but it will work even in the automatic update or normal update modes...

Console.WaitClose()
wait the console to be closed... its useful to sync the close of a threaded program, to only end the program after the console got closed (similar to the ThreadWait() instruction)

Funcitons:

Console.IsCreated()
Return nonzero if the windows is created, you can use this to check if the user closed the window without locking your program waiting for it (Console.WaitClose)

Console.GetTitle()
Return a string with the title of the console window

Console.Getmouse( MouseLine, MouseColumn , MouseButtons )
this function fills the integers variables with the current position of the mouse (in lines/colums). if the mouse got off the console the value returned are -1

Console.GetPalette( ColorNumber )
returns the integer reference of the especified color

Console.Multikey( Scancode )
returns nonzero if the key especified by the scancode is pressed down

Console.GetBuffer( CharBufferPtr, AttributeBufferPtr )
Fill the pointers with the address of the Character buffer and the Attributes(colors) Buffer, every char is one byte and every attribute is one byte (4 bits Text | 4 bits Background)

Console Options:

Console.Option( OptionToChange )
Modifies the setting where OptionToChange is:

- BlinkOn
Activates text blinking (will disable manual update and the background bright colors will be disabled)
- BlinkOff Default
Turn off text blink mode
- AutomaticUpdate Default
The update will be done automatic at vsync rate
- NormalUpdate
The update will be done when you print something into the screen
- ManualUpdate
No update will be made and youre responbile to call the Console.Draw instrunction to update the window, some options like blink or DosCursor that need made constant changes to the screen will disable this option
- HideConsole
Hide the console window
- ShowConsole Default
Show the console window
- CursorOn
Activate the position cursor (not implement yet)
- CursorOff Default
Deactivate the position cursor (not implement yet)
- UseDosCursor
The cursor will be a filled char with inverse colors (like dos text cursors)
- UseWindowsCursor Default
- EndWithConsoleOn
- EndWithConsoleOff Default


is still in development stage, it may have bugs... also someone have ideas im hearing ;P
Last edited by Mysoft on Sep 12, 2010 19:44, edited 3 times in total.
D.J.Peters
Posts: 8172
Joined: May 28, 2005 3:28
Contact:

Postby D.J.Peters » Apr 15, 2008 11:50

Download:
Console.bas
ConsoleTest.bas

the second link was broken
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Apr 15, 2008 13:04

It sounds good. It compiled OK and then bombed out when I ran it. Does it work in WIN2K?
---------------------------
ConsoleTest.exe - Application Error
---------------------------
The instruction at "0x77e25c9f" referenced memory at "0x00000000". The memory could not be "read".


Click on OK to terminate the program
Click on CANCEL to debug the program
---------------------------
OK Cancel
---------------------------
dodicat
Posts: 6687
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Extended ConsoleClass Functions

Postby dodicat » Apr 15, 2008 16:27

Mysoft wrote:for those that want to have one extra debug window... that looks like the console... or that want a more like DOS console.. i have made this "class" ... <snip>

fb 18.4 , Win XP pro.
Compile error on Quick Run, FBide:
(239) error 41: Variable not declared, VK_C in 'if wparam = VK_C and Control<>0 then'
Mysoft
Posts: 779
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Postby Mysoft » Apr 16, 2008 8:24

yeah, k im fixing something... and i will post it again, im not sure about win2k ... about the VK_C is the windows header... (changing it to 67 will also work) that you have the old one... anyway i have updated it here to avoid this... i will fix some visual gliths today... so i post it fixed again in a some hours... anyone else?
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Ha

Postby JaDogg » Apr 16, 2008 10:16

AWZom Projekt but It EaTZ!!! Mem a LOt, and StuckZ!!!! da Computer
JaDogg
Posts: 345
Joined: Apr 13, 2008 12:11
Location: Sri Lanka - Negombo
Contact:

Re: Extended ConsoleClass Functions

Postby JaDogg » Apr 16, 2008 10:18

dodicat wrote:
Mysoft wrote:for those that want to have one extra debug window... that looks like the console... or that want a more like DOS console.. i have made this "class" ... <snip>

fb 18.4 , Win XP pro.
Compile error on Quick Run, FBide:
(239) error 41: Variable not declared, VK_C in 'if wparam = VK_C and Control<>0 then'


HEYY I DID-NT GOT AN ERR oN Xp Pro (SP2)
counting_pine
Site Admin
Posts: 6225
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Apr 16, 2008 13:19

Hello JaDogg, welcome to the FreeBASIC community forum.
Just a note: we use a more conventional English style on this forum. If you could follow along with this, it would be much appreciated, thanks.
Again, welcome to the forum.
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Postby notthecheatr » Apr 16, 2008 18:01

o.O
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Apr 16, 2008 19:27

In consoletest.bas, line 50: you have to change "43" to "42", then it works.
Mysoft
Posts: 779
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Postby Mysoft » Apr 17, 2008 3:17

Cherry wrote:In consoletest.bas, line 50: you have to change "43" to "42", then it works.


omg... really sorry, for that ^^"""""""""""""
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Apr 17, 2008 13:10

I tested with XP and it works great. I still would like to know why it doesn't work in Win2K.
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Postby phishguy » Apr 17, 2008 17:25

OK, I figured out how to get it to work on WIN2K. I remmed out the following lines in console.bas. Evidently loading the icon from console.dll doesn't work on WIN2K. I don't know if it's a problem with a different version of console.dll or if it's a different issue.

Code: Select all

  '  HLIB = LoadLibrary(SYSDIR+"\console.dll")
  '  LIBRES = FindResource( HLIB, cast(any ptr,8) , RT_ICON )
  '  LIBMEM = LoadResource( HLIB, LIBRES )
  '  CMDICO = CreateIconFromResource( LIBMEM , SizeofResource(HLIB,LIBRES) , True , &h00030000)       
  '  FreeLibrary(HLIB)
Mysoft
Posts: 779
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Postby Mysoft » Apr 18, 2008 4:01

phishguy wrote:OK, I figured out how to get it to work on WIN2K. I remmed out the following lines in console.bas. Evidently loading the icon from console.dll doesn't work on WIN2K. I don't know if it's a problem with a different version of console.dll or if it's a different issue.

Code: Select all

  '  HLIB = LoadLibrary(SYSDIR+"\console.dll")
  '  LIBRES = FindResource( HLIB, cast(any ptr,8) , RT_ICON )
  '  LIBMEM = LoadResource( HLIB, LIBRES )
  '  CMDICO = CreateIconFromResource( LIBMEM , SizeofResource(HLIB,LIBRES) , True , &h00030000)       
  '  FreeLibrary(HLIB)


yeah thkz... i tought that, but i tought that it will only ignore the icon... but it crashed instead? =\

also ok, maybe i need to try get the icon from different places, it probabily the way i have used to keep a copy of the icon, without need to have the console.dll loaded into my process ^^" or is something about icon index that i dunno, or even a w2k problem related to some of the function (that falls to case 1)... also i will investigate... thkz =]
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Postby notthecheatr » Apr 18, 2008 15:15

Would be nice if we could hide/show the console. Console.Destroy doesn't seem to do the trick.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests