It is currently Tue Oct 15, 2019 12:00 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Alternate Console
PostPosted: Mon Nov 03, 2014 8:43 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
-----------------------------------------------------------------------------------

Download Alternate Console from My PureBasic Stuff

-----------------------------------------------------------------------------------

Tricks 'n' Tips
PureBasic Interface to OpenCV
PureBasic Interface to WinDivert
PureBasic Interface to WinRAR
PureBasic Interface to 7-Zip
PureBasic Interface to ImDisk
Windows Services & Other Stuff
Invading Space Aliens
Death Star vs Asteroids
GIF Toolkit
LSB File Embedding
Spider Web Drawing
Deform Image: MLS
Video Snipping Tool
Stitch Images: SIFT
Image Waves: LUT
YouTube Player & Downloader
MP4 Player & Downloader
Barcode Generator
Embed JS into PureBasic
Geolocation: Google Maps
Book & Viewer & Magnify
Video for Windows: VfW
Alternate Console
Network Share Management

-----------------------------------------------------------------------------------

ShowConsole(State = 1)
- defaults to showing Console in Normal Mode (1)
- sets state for both AltConsole or CmdConsole (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)

BringToTop(hConsole)
- not called directly
- brings AltConsole or a visible CmdConsole to the foreground on open

GetColors(CharacterColor, BackgroundColor)
- not called directly
- sets colors for both AltConsole or CmdConsole

HandlerRoutine(dwCtrlType)
- not called directly
- callback to catch AltConsole or CmdConsole closing

-----------------------------------------------------------------------------------

altOpenConsole(State = 1, Title.s = "Alternative Console", xColumn = 80, yRow = 300)
- defaults to showing Console in Normal Mode (1) with "Alternative Console" for Title and Console Width (80) Height (300)
- opens in various states (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)
- resizes the Console width/height
- opens a new Console with specified Title

altConsoleTitle(State = 1, Title.s = "Alternative Console")
- defaults "Alternative Console" for new Title
- changes current Console's Title

altPrint(Text.s = " ", nRepeat = 1)
- defaults one space
- option to repeat Text n times

altPrintN(Text.s = #Null$, nRepeat = 1)
- defaults one newline
- option to repeat Text/Newline n times

altFillChar(Character, nLength = 1)
- fills ascii Character n length

altFillColor(CharacterColor = 7, BackgroundColor = 0, nLength = 1)
- defaults one character length of the deafult colors
- fills n character length to chosen colors (color codes same as PureBasic)

altConsoleColor(CharacterColor = 7, BackgroundColor = 0, Mode = 0)
- default colors for new text (Mode 0) old text remains the same
- Mode 0: changes colors for new text / old text remains the same (color codes same as PureBasic)
- Mode 1: changes entire Console to chosen colors (color codes same as PureBasic)

altConsoleLocate(xColumn, yRow)
- moves the cursor to the new x/y location

altReadConsoleData(xColumn = 0, yRow = 0, nLength = 0)
- defaults reading the entire Console text
- reads the console text from x/y n length

altClearConsole(xColumn = 0, yRow = 0, nLength = 0)
- defaults clearing the entire Console's text and colors
- clears the Console text from x/y n length

altNewConsole(State = 99, Title.s = #Null$)
- defaults to showing Console in State from previous Console with Title from previous Console
- closes previous Console
- opens new Console with optional new State
- opens new Console with optional new Title

altInkey()
- captures ascii key strokes showing the character key value

altRawKey()
- shows the raw key code for ascii and non-ascii keys

altConsoleImage(ImageName.s = #Null$, nDelay = 1000)
- defaults with an OpenFileRequester prompt and a transition Delay of 1000ms
- optional ImageName can be either path or path\filename
- translates the pixels from a *.jpg | *.png | *.bmp file to console characters
- nDelay is used to pause n milliseconds between images

altConsoleAnimate(hImage)
- translates the pixels from a *.png file to console characters
- requires a sprite sheet with equally spaced x/y images or an animated GIF

altInput(Text.s = #Null$)
- defaults a pause waiting for the Enter key to be pressed
- reads text written after the input (pause) location
- allows for Text to be included with the pause
- dispalys optional Text in bottom/left of visible Console

-----------------------------------------------------------------------------------

cmdOpenConsole(State = 1, Title.s = "Command Console")
- defaults to showing Console in Normal Mode (1) with "Command Console" for Title
- opens in various states (0 = hidden, 1 = Normal, 2 = Minimized, 3 = Maximized)
- opens a new Command Console with specified Title

cmdChangeColor(CharacterColor = 7, BackgroundColor = 0)
- defaults the Command Console to default colors
- changes the Command Console to chosen colors (color codes same as PureBasic)

cmdAddAlias(Source.s, Target.s, ExeName.s = "cmd.exe")
- defaults alias commands to cmd.exe
- allows multiple commands to be combined then called using an alias
- alias commands can be used with any executable

cmdRunScript(Text.s, RunAndWait = #False)
- defaults to passing commands without waiting for them to finish
- runs commands passed by Text with an option to wait for them to finish

cmdRunBatch(FileName.s = #Null$, RunAndWait = #False)
- defaults with an OpenFileRequester prompt
- reads a .bat or .txt file line by line and runs the commands
- optional run and wait (will be applied to each command)

cmdReadConsole(nLeft = 0, nTop = 0, nRight = 0, nBottom = 0, nDelay = 0)
- defaults reading the entire Command Console text
- reads the Command Console text from the left/top/right/bottom location
- delay the reading until the console is fully populated

cmdCloseConsole()
- closes the Command Console
- this should always be called with a hidden Command Console

-----------------------------------------------------------------------------------

NOTE (Windows 10):

If the animations show in full-screen:
- delete the Registry key: HKEY_CURRENT_USER\Console
-- the Console key will be recreated when changes are made to a console's properties
- set cmd.exe (Command Console) to legacy mode from properties
-- don't set this option from the console created by the program
-- this option may not be available in earlier versions of Windows

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Fri Oct 11, 2019 1:15 am, edited 70 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Mon Nov 03, 2014 11:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Feb 18, 2010 11:10 pm
Posts: 192
Many thanks for the recent "parcel out" of your codes, this really brings some fresh air to the forum!


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Tue Nov 04, 2014 10:01 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Hi ostapas,

You're most welcome. It was cathartic to "clean out my script closet", and hopefully provide something useful in the process.

Cheers!

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Fri Nov 07, 2014 10:56 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4507
Location: Lyon - France
Splendid !!! Works very well...
Impressive the man work and panther :shock:
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Sat Oct 03, 2015 9:22 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Hi Kwai chang caine,

Thank you for your comments.

--------------------------------------------------

Updated to support Windows 10, including various bug fixes.

If the animations show in full-screen:
- delete the Registry key: HKEY_CURRENT_USER\Console
-- the Console key will be recreated when changes are made to a console's properties
- set cmd.exe (Command Console) to legacy mode from properties
-- don't set this option from the console created by the program
-- this option may not be available in earlier versions of Windows

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Tue May 08, 2018 9:15 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Sun Feb 05, 2017 12:08 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Updated:
- added 1 example
-- alt_animation_gif.pb
- added 5 images
-- countdown.gif, fishing.gif, flipping.gif, running.gif, troll.gif

Previously only Sprite sheets were used to generate Console animations, but thanks to the PureBasic team adding GIF support, animated GIF's can also be used.

If your interest is only Console animations, download the Standalone version of Console Animation from the first post, I'm not sure the Alternate Console download has a use outside of curiosity; this was one of the first things I wrote while learning PureBasic, and maybe can assist someone travelling a similar road.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Sat Jun 17, 2017 5:24 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4507
Location: Lyon - France
Hello JHPJHP :D

I use your splendid alternate console since several month ago 8) , and i don't know why, only sometime not always, i have an IMA at this line
Code:
Dim lpBuffer.CHAR_INFO(BufferSize, nRight - 1)
in the procedure
Code:
ReadCmdConsole(nLeft.i = 0, nTop.i = 0, nRight.i = 0, nBottom.i = 0)
Then i stop the code, and run another time and all is good after :shock:

I have noticed the variable "BufferSize" is empty, have you an idea what is the reason why ?

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Sat Jun 17, 2017 10:18 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Hi Kwai chang caine,

I can see a couple problems...

1. The version you are using is out of date: Download links in the first post have been updated.
2. The Function GetConsoleScreenBufferInfo can fail, but I wasn't trapping for it; this has been updated.
-- you may want to include a notification if the call fails

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Tue Jun 20, 2017 12:01 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Sat Jun 17, 2017 11:09 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4507
Location: Lyon - France
Thanks a lot for your answer, i try your tips
Have a good night

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Wed Nov 28, 2018 6:14 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 1324
Location: (Embarrassed to say country)
Some good stuff in there.
I spotted a couple of (minor) errors.
  • in cmdRunBatch(), (OpenFileRequester()) "StandardFile$" is not defined as local or global variable... shouldn't it be "FileName"?
  • * In cmdReadConsole(), there is a variable that is added to others. "Increment" but this is not defined, so it has no effect.
  • I also found that altPrint() doesn't work if the app is compiled as a console app.

this seems to fix (or hack into submission) the last item.
Code:
Procedure altOpenConsole(State = 1, Title.s = "Alternative Console", xColumn = 80, yRow = 300)
  Protected GetConsoleWindow.protoGetConsoleWindow
  Result = #False
 
  CompilerIf #PB_Compiler_ExecutableFormat = #PB_Compiler_Console
    If  #True  ; hackish, I know.
  CompilerElse
    If AllocConsole_()
  CompilerEndIf



Added a small macro to be the companion to altOpenConsole()
Code:
Macro AltCloseConsole() : FreeConsole_() : EndMacro


Any idea how to tell which window/console has input/focus?

great work!
-j


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Thu Nov 29, 2018 6:04 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Hi jassing,

Thank you for your generous contribution, and for your previous post outlining some potential problems with Alternate Console.

Alternate Console was probably my first attempt at creating something "useful" with PureBasic; looking over the code...
- in cmdRunBatch(), (OpenFileRequester()) "StandardFile$" is not defined as local or global variable
-- fixed, package updated
- in cmdReadConsole(), there is a variable that is added to others. "Increment" but this is not defined
-- Increment is used for scrolling/copying the console contents to the debug window/variable; updated the example cmd_show_console.pb to better demonstrate its use
- I also found that altPrint() doesn't work if the app is compiled as a console app
-- I compiled/tested some of the examples (Windows 10) without a problem, please be more specific; small change made to the Procedures altPrint, altPrintN
- Added a small macro to be the companion to altOpenConsole()
-- Shouldn't be needed, see the Procedure/Callback HandlerRoutine, it will free the console on a close event
- Any idea how to tell which window/console has input/focus?
-- Try using the API GetActiveWindow and GetFocus, matched against data derived from an enumeration of opened Window handles; let me know if you need any help

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Fri Nov 30, 2018 6:24 am 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 1324
Location: (Embarrassed to say country)
JHPJHP wrote:
- Added a small macro to be the companion to altOpenConsole()
-- Shouldn't be needed, see the Procedure/Callback HandlerRoutine, it will free the console on a close event


... unless you want to close the console before program end ...


as for the compiled as a console issue (and maybe I'm missing something...)
Code:
IncludeFile "Alt_Console.pbi"
CompilerIf #PB_Compiler_ExecutableFormat = #PB_Compiler_Console
  If altOpenConsole(1,"Test print",100,500)
    altPrintN("This is a test")
    altInput() 
  Else
    MessageRequester("Ooops","Console Open Failed")
  EndIf
CompilerElse : CompilerError("Compile as a console")
CompilerEndIf


For me, when run as a windows program, it works as expected. but when run as a console, altOpenConsole() fails


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Fri Nov 30, 2018 4:41 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Hi jassing,

jassing wrote:
as for the compiled as a console issue (and maybe I'm missing something...)

You're correct, I overlooked your code snippet about the Compiler Format, and only focused on compiling an executable; allocating a console in Console Mode is redundant.
- fixed, package updated

jassing wrote:
... unless you want to close the console before program end ...

Can you provide an example where the CloseConsole Macro is needed; the existing Event Handler should be sufficient.

Cheers.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Alternate Console
PostPosted: Fri Oct 04, 2019 9:53 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1584
Updated:
- added a clear console registry option
- applied a couple minor improvements

Clear Console: Registry
This option only applies to the animated examples executed in Windows 10+.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye