Controlling the window size of a compiled program?
Controlling the window size of a compiled program?
I am not new to BASIC. I am, however, new to FreeBASIC.
I have a bunch of small financial and statistical routines, written years ago and ultimately ported to QuickBASIC 4.5, that help me in my work. Some date from my PhD, almost 40 years ago. Traditionally I have run these from within the QB45 IDE, under vDOSPlus, although I also run them from within the QB64 IDE on 64-bit machines.
The attraction of compilation is that I won't need to faff around with an IDE. Also, I'll be able to share them -- various people have found them useful.
Having compiled a couple of programs under WinFBE, which compiles to FreeBASIC 1.07.1, I find that the resulting windows are too small, defaulting to characters 6 pixels high and 12 pixels wide. Windows doesn't seem to remember any changed settings, when I manually change the character size. My preference is 13 pixels wide, and 28 pixels high.
Someone from the QB64 forum pointed me here. I last looked at FreeBASIC ten years ago, when I wanted a means of running BASIC under Linux, and I'm impressed at how much it has developed. It seems odd, though, that such a seemingly obvious requirement should be lacking. I've seen other posts which apparently invoke 50-100 lines of code to control text size, but surely there's something simpler?
TIA,
Malcolm
I have a bunch of small financial and statistical routines, written years ago and ultimately ported to QuickBASIC 4.5, that help me in my work. Some date from my PhD, almost 40 years ago. Traditionally I have run these from within the QB45 IDE, under vDOSPlus, although I also run them from within the QB64 IDE on 64-bit machines.
The attraction of compilation is that I won't need to faff around with an IDE. Also, I'll be able to share them -- various people have found them useful.
Having compiled a couple of programs under WinFBE, which compiles to FreeBASIC 1.07.1, I find that the resulting windows are too small, defaulting to characters 6 pixels high and 12 pixels wide. Windows doesn't seem to remember any changed settings, when I manually change the character size. My preference is 13 pixels wide, and 28 pixels high.
Someone from the QB64 forum pointed me here. I last looked at FreeBASIC ten years ago, when I wanted a means of running BASIC under Linux, and I'm impressed at how much it has developed. It seems odd, though, that such a seemingly obvious requirement should be lacking. I've seen other posts which apparently invoke 50-100 lines of code to control text size, but surely there's something simpler?
TIA,
Malcolm
Re: Controlling the window size of a compiled program?
Hi, so the window is too small and the too fonts?
What system are you using now windows or linux?
And what is the output are you using:
* Console / terminal (screen 0)?
* Graphics window (screen / screenres command)?
* A GUI toolkit (FLTK / GTK / Windows API)?
For 'Console / terminal' it is a system / terminal setting, not controlled by freebasic as far as I know.
For the graphics window, the default font sizes are (including black surrounding) 8x8, 8x14, 8x16. See WIDTH command. Something bigger is possible, but more work. DRAW STRING supports custom fonts, but I have never tried that myself.
For a GUI toolkit any font size should be possible.
Also check this post: viewtopic.php?f=3&t=26229&hilit=true+font#p241697
What system are you using now windows or linux?
And what is the output are you using:
* Console / terminal (screen 0)?
* Graphics window (screen / screenres command)?
* A GUI toolkit (FLTK / GTK / Windows API)?
For 'Console / terminal' it is a system / terminal setting, not controlled by freebasic as far as I know.
For the graphics window, the default font sizes are (including black surrounding) 8x8, 8x14, 8x16. See WIDTH command. Something bigger is possible, but more work. DRAW STRING supports custom fonts, but I have never tried that myself.
For a GUI toolkit any font size should be possible.
Also check this post: viewtopic.php?f=3&t=26229&hilit=true+font#p241697
Re: Controlling the window size of a compiled program?
hello MWheatley
to get a bigger console window in Windows, launch your program then right-click on the title bar of the console window and select properties
then you can change your font/font size and under the tab layout you can set the window size
you only need to do this once, thereafter the console will open with the font/font size and window size that you selected
to get a bigger console window in Windows, launch your program then right-click on the title bar of the console window and select properties
then you can change your font/font size and under the tab layout you can set the window size
you only need to do this once, thereafter the console will open with the font/font size and window size that you selected
-
- Posts: 165
- Joined: Apr 19, 2019 19:03
Re: Controlling the window size of a compiled program?
There is almost all possible in FreeBASIC. It would depend on your code (if you could give a short example) and what you want to get at the end.MWheatley wrote: but surely there's something simpler?
A easy solution would be FB-Truetype. There you can choose any window size with screenres and use Truetype fonts:
viewtopic.php?f=14&t=25083
The luxus way is to use a GUI with fltk:
viewtopic.php?f=14&t=24547&hilit=fltk+c
Re: Controlling the window size of a compiled program?
Windows.
For console you can change font size / console dimension for a session via code.
(Tested Win 10 only)
For console you can change font size / console dimension for a session via code.
Code: Select all
#include "windows.bi"
dim as HWND console = GetConsoleWindow()
dim as RECT r
GetWindowRect(console, @r) 'get the console size
dim as integer s
print "Original font size"
print getconsolefontsize(GetStdHandle(STD_OUTPUT_HANDLE),s).x;" by ";
print getconsolefontsize(GetStdHandle(STD_OUTPUT_HANDLE),s).y
print
dim as _CONSOLE_FONT_INFOEX x
with x
.cbsize=sizeof(_CONSOLE_FONT_INFOEX)
.nfont=0
.dwfontsize=type(13,28)'new font size
.fontfamily=0
.fontweight=100
.facename="consolas"' "courier" '....
end with
print "Press a key"
sleep
setcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),1, @x )
MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE)
print "new font size this session"
print getconsolefontsize(GetStdHandle(STD_OUTPUT_HANDLE),s).x;" by ";
print getconsolefontsize(GetStdHandle(STD_OUTPUT_HANDLE),s).y
print "Now change the console size, press a key"
sleep
shell "MODE CON: COLS=60 LINES=10"
print
print "Press a key to end"
sleep
Re: Controlling the window size of a compiled program?
I am using Windows. The output is directed to a Windows terminal window, as would happen under QB45. I don't really understand what is meant by "graphics window", but the answer is that I don't think so. As for the GUI toolkit, the answer is that I don't think so. I have my (fairly simple) QB45 code, and WinFBE.badidea wrote:Hi, so the window is too small and the too fonts?
What system are you using now windows or linux?
And what is the output are you using:
* Console / terminal (screen 0)?
* Graphics window (screen / screenres command)?
* A GUI toolkit (FLTK / GTK / Windows API)?
For 'Console / terminal' it is a system / terminal setting, not controlled by freebasic as far as I know.
For the graphics window, the default font sizes are (including black surrounding) 8x8, 8x14, 8x16. See WIDTH command. Something bigger is possible, but more work. DRAW STRING supports custom fonts, but I have never tried that myself.
For a GUI toolkit any font size should be possible.
Also check this post: viewtopic.php?f=3&t=26229&hilit=true+font#p241697
Malcolm
Re: Controlling the window size of a compiled program?
This is exactly what I am doing, but it is NOT being 'remembered'. I am having to do it each time. It makes no difference as to whether I change the font in "Properties" or "Defaults" -- it is not being remembered.srvaldez wrote:hello MWheatley
to get a bigger console window in Windows, launch your program then right-click on the title bar of the console window and select properties
then you can change your font/font size and under the tab layout you can set the window size
you only need to do this once, thereafter the console will open with the font/font size and window size that you selected
Hence my query regarding forcing it from within BASIC.
Given that you say that it should be remembered, I'll experiment with other computers.
Malcolm
Re: Controlling the window size of a compiled program?
Just checked with Win7-64, the console does remember font settings. Under XP, there would be a box asking whether to remember it or not. In any case, it's a registry setting, probably a key like HKEY_CURRENT_USER\Console\C:_MyApp.exe
Re: Controlling the window size of a compiled program?
If you were using plots and charts e.t.c it will be a graphics window (screen something).
If not then a console window.
(I think QB64's console is a bit like screen 0 here, i.e. no vertical/horizontal scrolling)
Here is a simplified version of my previous console code, which last for the session in use.
If not then a console window.
(I think QB64's console is a bit like screen 0 here, i.e. no vertical/horizontal scrolling)
Here is a simplified version of my previous console code, which last for the session in use.
Code: Select all
#include "windows.bi"
Sub changefontsize(w As Long, h As Long,ftype As String="consolas")
Dim As _CONSOLE_FONT_INFOEX x
With x
.cbsize=Sizeof(_CONSOLE_FONT_INFOEX)
.nfont=0
.dwfontsize=Type(w,h)
.fontfamily=0
.fontweight=100
.facename=ftype
End With
setcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),1, @x )
End Sub
Sub changeconsolesize(cols As Long,lines As Long)
Shell "MODE CON: COLS="+Str(cols)+ "LINES="+Str(lines)
End Sub
'====================
Print "Press a key"
Sleep
changefontsize(13,28)
Print "new font size this session = 13 by 28"
Dim As String asci
For n As Long=0 To 255
asci+=Chr(n) 'create a string
Next
Locate 10
Print asci
Print "Now change the console size again, press a key"
Sleep
Cls
changefontsize(15,30)
changeconsolesize(50,4)
Print "New console size = COLS=50 LINES=4"
Print "Font size 15 by 30"
Print "Press a key to end . . . "
Sleep
Re: Controlling the window size of a compiled program?
Thank you. I will experiment with this tonight.dodicat wrote:If you were using plots and charts e.t.c it will be a graphics window (screen something).
If not then a console window.
(I think QB64's console is a bit like screen 0 here, i.e. no vertical/horizontal scrolling)
Here is a simplified version of my previous console code, which last for the session in use.Code: Select all
#include "windows.bi" Sub changefontsize(w As Long, h As Long,ftype As String="consolas") Dim As _CONSOLE_FONT_INFOEX x With x .cbsize=Sizeof(_CONSOLE_FONT_INFOEX) .nfont=0 .dwfontsize=Type(w,h) .fontfamily=0 .fontweight=100 .facename=ftype End With setcurrentconsolefontex(GetStdHandle(STD_OUTPUT_HANDLE),1, @x ) End Sub Sub changeconsolesize(cols As Long,lines As Long) Shell "MODE CON: COLS="+Str(cols)+ "LINES="+Str(lines) End Sub '==================== Print "Press a key" Sleep changefontsize(13,28) Print "new font size this session = 13 by 28" Dim As String asci For n As Long=0 To 255 asci+=Chr(n) 'create a string Next Locate 10 Print asci Print "Now change the console size again, press a key" Sleep Cls changefontsize(15,30) changeconsolesize(50,4) Print "New console size = COLS=50 LINES=4" Print "Font size 15 by 30" Print "Press a key to end . . . " Sleep
Malcolm
Re: Controlling the window size of a compiled program?
I've tried with another computer (Windows 7, 64-bit). The setting *is* remembered. I'll shortly be moving onto a different computer for my main machine, so assuming that acts the same way, the problem goes away. Thanks everyone! (I'll still try out the recommended code, though.)jj2007 wrote:Just checked with Win7-64, the console does remember font settings. Under XP, there would be a box asking whether to remember it or not. In any case, it's a registry setting, probably a key like HKEY_CURRENT_USER\Console\C:_MyApp.exe
Malcolm
Re: Controlling the window size of a compiled program?
hello MWheatley
instead of selecting properties, select defaults, then change the settings to your liking, it will be remembered by any console programs compiled via WinFBE
however, if 8x16 font is ok then you could use the graphics window, example using the qb dialect, compile as GUI to suppress a console being opened, which is not needed if using graphic window
warning -- if you have the target set to GUI in WinFBE and compile a plain console app, the program will run but you won't see anything, you will then need to terminate the program using the task manager
instead of selecting properties, select defaults, then change the settings to your liking, it will be remembered by any console programs compiled via WinFBE
however, if 8x16 font is ok then you could use the graphics window, example using the qb dialect, compile as GUI to suppress a console being opened, which is not needed if using graphic window
Code: Select all
#lang "qb"
Const Wd = 800, Ht = 600
__ScreenRes Wd, Ht '' if using lang fb then use ScreenRes Wd, Ht
'the two underscore prefix is needed if using lang qb
Width Wd\8, Ht\16 '' Use 8*16 font
print "hello world, have a good day!"
sleep
Re: Controlling the window size of a compiled program?
I had selected defaults. Thank you for the shorter code. I will report back.srvaldez wrote:hello MWheatley
instead of selecting properties, select defaults, then change the settings to your liking, it will be remembered by any console programs compiled via WinFBE
however, if 8x16 font is ok then you could use the graphics window, example using the qb dialect, compile as GUI to suppress a console being opened, which is not needed if using graphic windowwarning -- if you have the target set to GUI in WinFBE and compile a plain console app, the program will run but you won't see anything, you will then need to terminate the program using the task managerCode: Select all
#lang "qb" Const Wd = 800, Ht = 600 __ScreenRes Wd, Ht '' if using lang fb then use ScreenRes Wd, Ht 'the two underscore prefix is needed if using lang qb Width Wd\8, Ht\16 '' Use 8*16 font print "hello world, have a good day!" sleep
Malcolm
Re: Controlling the window size of a compiled program?
If you have a console numerical/statistical program, you wouldn't expect users to re do their console from cmd.exe properties appearance each time to run it.
They would need to write down all their settings, change to your preference, then re-set to their original settings when they are done.
In essence they would be tweaking the system registry each time to run a console program, which is a bit heavy IMHO.
There is no factory default to go back to, the console default is your custom default.
If you are altering the appearance for your eyes only then that of course is another story.
If you settings are not sticking then you probably have a Windows registry problem.
Can you for instance right click a .bas file / properties and change opens with to another program (notepad maybe).
Does it stick?
I had this problem on win 10, I couldn't fix it, I googled all sorts of advice.
Then suddenly it repaired itself after a scannow session .
They would need to write down all their settings, change to your preference, then re-set to their original settings when they are done.
In essence they would be tweaking the system registry each time to run a console program, which is a bit heavy IMHO.
There is no factory default to go back to, the console default is your custom default.
If you are altering the appearance for your eyes only then that of course is another story.
If you settings are not sticking then you probably have a Windows registry problem.
Can you for instance right click a .bas file / properties and change opens with to another program (notepad maybe).
Does it stick?
I had this problem on win 10, I couldn't fix it, I googled all sorts of advice.
Then suddenly it repaired itself after a scannow session .
Re: Controlling the window size of a compiled program?
The compiled programs are .EXE files, so 'open with' isn't really an option. The current machine is a Win 7, 32-bit machine that will be retired before Win 7 goes EOL in January 2020, so I'm not too fussed about this particular machine. I just want to know that a solution exists. I need to work across several machines (don't ask), and running compiled programs is a lot simpler than maintaining an IDE across multiple platforms.dodicat wrote:If you have a console numerical/statistical program, you wouldn't expect users to re do their console from cmd.exe properties appearance each time to run it.
They would need to write down all their settings, change to your preference, then re-set to their original settings when they are done.
In essence they would be tweaking the system registry each time to run a console program, which is a bit heavy IMHO.
There is no factory default to go back to, the console default is your custom default.
If you are altering the appearance for your eyes only then that of course is another story.
If you settings are not sticking then you probably have a Windows registry problem.
Can you for instance right click a .bas file / properties and change opens with to another program (notepad maybe).
Does it stick?
I had this problem on win 10, I couldn't fix it, I googled all sorts of advice.
Then suddenly it repaired itself after a scannow session .
From the advice above, I think a solution has emerged. Thank you for your help.
Malcolm