Alternate Console

Share your advanced PureBasic knowledge/code with the community.
User avatar
ostapas
Enthusiast
Enthusiast
Posts: 192
Joined: Thu Feb 18, 2010 11:10 pm

Re: Alternate Console

Post by ostapas »

Many thanks for the recent "parcel out" of your codes, this really brings some fresh air to the forum!
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

Hi ostapas,

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

Cheers!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

Splendid !!! Works very well...
Impressive the man work and panther :shock:
Thanks for sharing 8)
Last edited by Kwai chang caine on Wed Mar 16, 2022 5:38 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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
Last edited by JHPJHP on Tue May 08, 2018 9:15 pm, edited 3 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

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: Select all

Dim lpBuffer.CHAR_INFO(BufferSize, nRight - 1)
in the procedure

Code: Select all

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
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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
Last edited by JHPJHP on Tue Jun 20, 2017 12:01 am, edited 3 times in total.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Alternate Console

Post by Kwai chang caine »

Thanks a lot for your answer, i try your tips
Have a good night
ImageThe happiness is a road...
Not a destination
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: Alternate Console

Post by jassing »

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: Select all

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: Select all

Macro AltCloseConsole() : FreeConsole_() : EndMacro
Any idea how to tell which window/console has input/focus?

great work!
-j
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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
jassing
Addict
Addict
Posts: 1745
Joined: Wed Feb 17, 2010 12:00 am

Re: Alternate Console

Post by jassing »

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: Select all

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
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: Alternate Console

Post by JHPJHP »

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+.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Alternate Console

Post by Derren »

Hey,

I just wanted to test your code. Sadly you offer it only on your website for a payment. :(
Locked