Forum > FV/Textmode IDE
[SOLVED]Access private functions in CRT unit, trying to get console width
old_DOS_err:
Hi all,
An oldy, but still seems no simple way to get console width. I have done the usual gymnastics trying to get this. I’m writing a simple util to display small files (it’s primarily for checking results of output files). I have screen wrapping (using WhereX), but it is not reliable as the console can easily be resized.
I saw some people in forums saying WindMaxX - WinMinX, but that clearly doesn’t work as they are constants. I did however put them in a loop just to confirm they did not change as the console size was changed. Just to be sure.
I found GetConsoleScreenBufferInfo, which I found initially in unit JwaWinCon. I got the code to compile but the function failed, suspect I needed the JEDI package, which I am not going to do.
A search for that term (I wrote my own text search program, not complete but works) in the Lazarus folder found in it func.inc and a few others. I tried doing a direct include, but no go (it didn't recognise the command).
A further search online brought me back to CRT. Opened up CRT and it has the functions I want, especially GetScreenWidth (which calls GetConsoleScreenBufferInfo and takes care of the vars). But that is not recognised, but the normal public functions, like NormVideo are recognised (just to confirm it was actually reaching CRT).
So the hopefully simple question is how I can access this GetScreenWidth in CRT? Or is there any other simple way to get the console width?
Any help would be much appreciated.
Phil
Thaddy:
Screenwidth <> ConsoleWidth, so what do you actually mean?
Do you want the ScreenWidth, which is likely different but can be equal to or do you want the ConsoleWidth?
Imo you should just need the console width and that is already accessible.
old_DOS_err:
Thanks Thaddy for the reply.
Sadly my body started to decline a couple of years ago and lately my brain has started to follow. I feel I'm being incredibly stupid with this, but I could not find ConsoleWidth. I ran a text search on the Lazarus folder and found console.inc, but a text search for console.inc did not turn up anything useful.
So if you could tell me which unit I need to add, which object to use, or at worst, which package to add, then that would be extremely helpful. As I say, it's kind of embarrassing, I feel like an ex runner who now can barely walk to the local shops.
Here is the basic demo I was working on. This would be very simple using a form. I think I'm getting lost between old DOS (my world, but the screen size never changed) and forms, where resizing is a basic part of the development.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Uses Classes, SysUtils, CRT, // these are the other units or similar I tried //JwaWinBase, JwaWinCon, JwaWinType, // MAY NEED PACKAGE - function was recognised, but failed //FPUsrScr, // not found. looked like part of a package //w32smsg, ditto // func.inc looks good, but cannot find a reference to in Lazarus Procedure test_win_coords;{ So what I want this demo to do is that each time through the loop, I can change the console (window) size with the mouse, then if I press Return I want it to show the new width.} Var s : String; //h : HANDLE; //C : _CONSOLE_SCREEN_BUFFER_INFO; x, y : DWord; Begin WriteLn( '| Press Enter to rerun, E and Enter to end' ); Repeat //WriteLn( '| WindMinX = ', WindMinX, ', WindMaxX = ', WindMaxX, ', WindMinY = ', WindMinY, ', WindMaxY = ', WindMaxY ); THESE ARE FIXED AND DO NOT CHANGE //x := p_int__really_stupid_get_console_width; // I tried writing a poor alternative that moved the cursor along by 1 until it didn't change, it didn't work //x := {ConsoleWidth;} ScreenWidth; // compiler did not recognise either WriteLn( '| Screen Width = ', x ); // I want x to reflect the current width after I change the console size ReadLn( s ); Until UpCase( s ) = 'E'; { If Not GetConsoleScreenBufferInfo( h, c ) Then // this was in JwaWinCon, above, ran but function failed WriteLn( '| Get function failed' ) Else WriteLn( '| Get function good:' );} //WriteLn( '| ScreenWidth = ', GetScreenWidth ); // this was in CRT.pp but I could not find how to access //NormVideo; // just checking was reaching CRT //GetScreenCursor( x, y ); // think this was also in CRT.pp End;
I know I'm going to feel very stupid when someone points outs the bleeding obvious, the mental equivalent of going out and forgetting to put your trousers on.
Phil
Thaddy:
You should take a look at Screen which is a global variable of TScreen and has lots of info you need.
old_DOS_err:
Sorry Thaddy, I feel I'm being really dumb here.
I tried Screen, not recognised. Searched online for TScreen, found the Free Pascal page. This made a reference to package x11. A search online found a lot of references, but none directly useful, though they mentioned various other names, including xlib and xauth. A search in the Lazarus package lists did not mention x11, xlib, xauth, etc.
In the Free Pascal page on x11, they gave a demo, that used the units xlib, x, ctypes. I put those in direct, only ctypes was recognised.
It seems like what I am trying to do, i.e. just get the current width of the console (terminal, DOS window), should be incredibly easy, but given how many people read this, you have been the only one to reply. I know I didn't word it very well, but I would have thought someone MUST have done that.
I think unless you can put me out of misery and tell what I am missing (beside a huge number of brain cells), I will leave this for a while and maybe repost a simplified version (if that is possible for me) in the beginners section. For now I am just focussing on doing the file output of my ‘simple’ util, that is to show a data file in byte form (a bit like a hex editor), that bit was easy, oh the irony.
Phil
Navigation
[0] Message Index
[#] Next page