GUI/Maximum window dimensions: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(73 intermediate revisions by 38 users not shown)
Line 1:
{{task|GUI}}{{requires|Graphics}}
 
The task is to determine the maximum height and width of a window that can fit within the physical display area of the screen without scrolling. This is effectively the screen size (not the total desktop area, which could be bigger than the screen display area) in pixels minus any adjustments for window decorations and menubars. The idea is to determine the physical display parameters for the maximum height and width of the usable display area in pixels (without scrolling). The values calculated should represent the usable desktop area of a window maximized to fit the the screen.
 
This is effectively the screen size (not the total desktop area, which could be bigger than the screen display area) in pixels minus any adjustments for window decorations and menubars.
=== Considerations ===
 
The idea is to determine the physical display parameters for the maximum height and width of the usable display area in pixels (without scrolling).
==== Multiple Monitors ====
 
For multiple monitors, theThe values calculated should represent the size of the usable displaydesktop area onof thea monitorwindow whichmaximized isto related tofit the task (ie the monitor which would display a window if such instructions were given)screen.
 
==== Tiling Window Managers ====
 
;Considerations:
 
;--- Multiple Monitors:
For multiple monitors, the values calculated should represent the size of the usable display area on the monitor which is related to the task (i.e.:   the monitor which would display a window if such instructions were given).
 
;--- Tiling Window Managers
For a tiling window manager, the values calculated should represent the maximum height and width of the display area of the maximum size a window can be created (without scrolling). This would typically be a full screen window (minus any areas occupied by desktop bars), unless the window manager has restrictions that prevents the creation of a full screen window, in which case the values represent the usable area of the desktop that occupies the maximum permissible window size (without scrolling).
<br><br>
 
=={{header|Ada}}==
{{libheader|GTK}}
{{libheader|GtkAda}}
<langsyntaxhighlight Adalang="ada">with Gtk.Main;
with Glib;
with Gtk.Window; use Gtk.Window;
Line 42 ⟶ 48:
New_Line;
Hid := Gtk.Main.Quit_Add_Destroy (0, Win);
end Max_Size;</langsyntaxhighlight>
Output (on a 1280 x 800 screen with Windows XP):
<pre>Maximum dimensions of window : W 1280 x H 734
</pre>
 
=={{header|BBC BASICAutoHotkey}}==
This is a modified example taken from the AutoHotkey documentation for the [http://ahkscript.org/docs/commands/SysGet.htm SysGet] command.
Also, the built in variables [http://ahkscript.org/docs/Variables.htm#Screen A_ScreenHeight] and [http://ahkscript.org/docs/Variables.htm#Screen A_ScreenWidth] contain the width and height of the primary monitor, in pixels.
<syntaxhighlight lang="autohotkey">SysGet, MonitorCount, MonitorCount
SysGet, MonitorPrimary, MonitorPrimary
MsgBox, Monitor Count:`t%MonitorCount%`nPrimary Monitor:`t%MonitorPrimary%
Loop, %MonitorCount%
{
SysGet, MonitorName, MonitorName, %A_Index%
SysGet, Monitor, Monitor, %A_Index%
SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
MsgBox, % "Monitor:`t#" A_Index
. "`nName:`t" MonitorName
. "`nLeft:`t" MonitorLeft "(" MonitorWorkAreaLeft " work)"
. "`nTop:`t" MonitorTop " (" MonitorWorkAreaTop " work)"
. "`nRight:`t" MonitorRight " (" MonitorWorkAreaRight " work)"
. "`nBottom:`t" MonitorBottom " (" MonitorWorkAreaBottom " work)"
}</syntaxhighlight>
'''Output:'''
<pre>Monitor Count: 1
Primary Monitor: 1
 
Monitor: #1
Name: \\.\DISPLAY1
Left: 0(0 work)
Top: 0 (0 work)
Right: 1920 (1920 work)
Bottom: 1080 (1040 work)</pre>
 
=={{header|Axe}}==
 
Because Axe is currently (6/22/2015) only available on the TI-83/84 black and white calculators, the screen dimensions are fixed at 96 by 64 pixels.
 
=={{header|BASIC}}==
==={{header|BaCon}}===
Requires BaCon version 4.0.1 or higher, using GTK3.
<syntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
FUNCTION Define_Window
 
LOCAL (*max)() = gtk_window_maximize TYPE void
LOCAL id
 
id = GUIDEFINE("{ type=WINDOW name=window }")
CALL GUIFN(id, "window", max)
RETURN id
 
ENDFUNCTION
 
SUB Print_Dimensions
 
LOCAL (*size)() = gtk_window_get_size TYPE void
LOCAL x, y
 
CALL GUIFN(gui, "window", size, &x, &y)
PRINT x, "-", y
END
 
ENDSUB
 
gui = Define_Window()
ALARM Print_Dimensions, 500
event$ = GUIEVENT$(gui)</syntaxhighlight>
{{out}}
Result when executed using my 1600x900 screen:
<pre>1600-838</pre>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> SPI_GETWORKAREA = 48
DIM rc{l%,t%,r%,b%}
SYS "SystemParametersInfo", SPI_GETWORKAREA, 0, rc{}, 0
PRINT "Maximum width = " ; rc.r% - rc.l%
PRINT "Maximum height = " ; rc.b% - rc.t%</langsyntaxhighlight>
'''Output:'''
<pre>
Line 59 ⟶ 133:
Maximum height = 1021
</pre>
 
=={{header|C}}==
===Windows===
The following implementation has been tested on Windows 8.1, may not work on Linux systems.
<syntaxhighlight lang="c">
#include<windows.h>
#include<stdio.h>
 
int main()
{
printf("Dimensions of the screen are (w x h) : %d x %d pixels",GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
return 0;
}
</syntaxhighlight>
Output :
<pre>
Dimensions of the screen are (w x h) : 1536 x 864 pixels
</pre>
 
=={{header|C sharp}}==
{{trans|Visual Basic .NET}}
'''Compiler:''' Roslyn C# (language version >= 6)
{{works with|.NET Framework|4.7.2}} (simple enough that it should probably work on every Framework version--.NET Core 3.0 will support Windows Forms on Windows only)
Must be referenced:
<!--Wrap in a span with display:flex to remove libheader's line break-->
<span style="display:flex">{{libheader|GDI+}}<span style="white-space:pre"> (managed interface) [System.Drawing]</span></span>
<span style="display:flex">{{libheader|Windows Forms}}<span style="white-space:pre"> [System.Windows.Forms]</span></span>
 
Bounds are the screen's dimensions; working area is the is the region that excludes "taskbars, docked windows, and docked tool bars" (from Framework documentation).
 
<syntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Windows.Forms;
 
static class Program
{
static void Main()
{
Rectangle bounds = Screen.PrimaryScreen.Bounds;
Console.WriteLine($"Primary screen bounds: {bounds.Width}x{bounds.Height}");
 
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
Console.WriteLine($"Primary screen working area: {workingArea.Width}x{workingArea.Height}");
}
}</syntaxhighlight>
 
{{out}}
<pre>Primary screen bounds: 1714x1143
Primary screen working area: 1714x1103</pre>
 
Alternatively, use the dimensions of a borderless form with WindowState set to FormWindowState.Maximized (i.e. a full-screen window that is shown above the taskbar).
 
<syntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Windows.Forms;
 
static class Program
{
static void Main()
{
using (var f = new Form() { FormBorderStyle = FormBorderStyle.None, WindowState = FormWindowState.Maximized })
{
f.Show();
Console.WriteLine($"Size of maximized borderless form: {f.Width}x{f.Height}");
}
}
}</syntaxhighlight>
 
{{out}}
<pre>Size of maximized borderless form: 1714x1143</pre>
 
=={{header|Creative Basic}}==
<syntaxhighlight lang="creative basic">
<lang Creative Basic>
DEF Win:WINDOW
DEF Close:CHAR
Line 96 ⟶ 240:
 
Output: Maximum drawing area values: width is 1280 and height is 749.
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| Winapi.Windows}}
{{libheader| System.SysUtils}}
{{libheader| Vcl.Forms}}
<syntaxhighlight lang="delphi">
unit Main;
 
interface
 
uses
Winapi.Windows, System.SysUtils, Vcl.Forms;
 
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
 
var
Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
var
w,h:Integer;
begin
w := Screen.Monitors[0].WorkareaRect.Width;
h := Screen.Monitors[0].WorkareaRect.Height;
Caption:= format('%d x %d',[w,h]);
SetBounds(0,0,w,h);
end;
 
end.</syntaxhighlight>
Resources from form:
<syntaxhighlight lang="delphi">object Form1: TForm1
OnCreate = FormCreate
end</syntaxhighlight>
 
=={{header|EGL}}==
Line 128 ⟶ 311:
</pre>
Usage of the Browser external type in a RuiHandler.
<syntaxhighlight lang="egl">
<lang EGL>
browser Browser{};
bvh int = browser.getViewportHeight();
Line 134 ⟶ 317:
SysLib.writeStdout("ViewportHeight: " + bvh);
SysLib.writeStdout("ViewportWidth: " + bvw);
</syntaxhighlight>
</lang>
Output
<pre>
Line 141 ⟶ 324:
</pre>
 
== {{header|GambasFBSL}} ==
In the graphics mode, Windows does it all automatically and displays a form that fills the entire area not obscured by the taskbar on your primary monitor:
<syntaxhighlight lang="qbasic">#INCLUDE <Include\Windows.inc>
ShowWindow(ME, SW_MAXIMIZE)
BEGIN EVENTS
END EVENTS</syntaxhighlight>
 
Alternatively, one can obtain the unobscured area's dimensions using the following console script:
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE
#INCLUDE <Include\Windows.inc>
 
TYPE RECT
%Left
%Top
%Right
%Bottom
END TYPE
 
DIM rc AS RECT
SystemParametersInfo(SPI_GETWORKAREA, 0, @rc, 0)
PRINT "width = ", rc.Right - rc.Left, ", height = ", rc.Bottom - rc.Top
 
PAUSE</syntaxhighlight>
 
A typical output for a 1680x1050 primary monitor will be:
<pre>width = 1680, height = 1017
 
Press any key to continue...</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' Using SystemParametersInfo function in Win32 API
Dim As Any Ptr library = DyLibLoad("user32")
Dim Shared SystemParametersInfo As Function (ByVal As ULong, ByVal As ULong, ByVal As Any Ptr, ByVal As ULong) As Long
SystemParametersInfo = DyLibSymbol(library, "SystemParametersInfoA")
 
Type Rect
As Long left, top, right, bottom
End Type
 
#Define SPI_GETWORKAREA &H30
Dim r As Rect
SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0)
DyLibFree(library)
Print "Maximum usable desktop area : W" ; r.right - r.left; " x H"; r.bottom - r.top; " pixels"
Print
Print "Press any key to quit"
Sleep</syntaxhighlight>
Output for my machine:
{{out}}
<pre>
Maximum usable desktop area : W 1366 x H 728 pixels
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">include "NSLog.incl"
 
CGRect r
r = fn ScreenVisibleFrame( fn ScreenMainScreen )
NSLog(@"x:%.0f, y:%.0f, w:%.0f, h:%.0f",r.origin.x,r.origin.y,r.size.width,r.size.height)
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
x:0, y:50, w:1728, h:1029
</pre>
 
=={{header|Gambas}}==
 
=== Overview ===
Line 151 ⟶ 402:
From with the project create a form (FMain) with the following properties set:
 
<langsyntaxhighlight lang="gambas">FMain.Maximized = True
FMain.Visible = False ' The form can be invisible</langsyntaxhighlight>
 
From within the projectview, rightclick the FMain form and select Edit class from the contextmenu. This will display a form class file (FMain.class) as follows:
 
<langsyntaxhighlight lang="gambas">PUBLIC SUB _new()
 
END
Line 162 ⟶ 413:
PUBLIC SUB Form_Open()
 
END</langsyntaxhighlight>
 
=== Adding the form resize event ===
Line 168 ⟶ 419:
We can now add a Form_Resize() event to the class file with the necessary code to obtain the screen dimensions as follows:
 
<langsyntaxhighlight lang="gambas">PUBLIC SUB Form_Resize()
PRINT "The maximum window size that can be used without scrolling is "; FMain.Width; " x "; FMain.Height
END</langsyntaxhighlight>
 
=={{header|Gambas}}==
<syntaxhighlight lang="gambas">Public Sub Form_Open()
 
Print Desktop.Width
Print Desktop.Height
 
End</syntaxhighlight>
Output:
<pre>
1920
1055
</pre>
 
=={{header|Go}}==
{{libheader|RobotGo}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
"github.com/go-vgo/robotgo"
)
 
func main() {
w, h := robotgo.GetScreenSize()
fmt.Printf("Screen size: %d x %d\n", w, h)
fpid, err := robotgo.FindIds("firefox")
if err == nil && len(fpid) > 0 {
pid := fpid[0]
robotgo.ActivePID(pid)
robotgo.MaxWindow(pid)
_, _, w, h = robotgo.GetBounds(pid)
fmt.Printf("Max usable : %d x %d\n", w, h)
}
}</syntaxhighlight>
 
On my machine the figures are:
<pre>
Screen size: 1366 x 768
Max usable : 1301 x 744
</pre>
 
=={{header|Groovy}}==
<syntaxhighlight lang="groovy">def window = java.awt.GraphicsEnvironment.localGraphicsEnvironment.maximumWindowBounds
 
println "width: $window.width, height: $window.height"</syntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">import Graphics.UI.Gtk
import Control.Monad (when)
import Control.Monad.Trans (liftIO)
Line 224 ⟶ 521:
liftIO $ putStrLn ("The inner window region is now " ++ show x ++
" pixels wide and " ++ show y ++ " pixels tall.")
return True</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Raise and query a hidden window.
<langsyntaxhighlight Iconlang="icon">link graphics
 
procedure main() # Window size
Line 237 ⟶ 535:
 
write("The display size is w=",dw,", h=",dh)
end</langsyntaxhighlight>
 
{{improve|Icon|Need to handle window borders which will vary from system to system and handle or comment on additional requirements.}}
 
=={{header|IWBASIC}}==
<syntaxhighlight lang="iwbasic">
<lang IWBASIC>
DEF Win:WINDOW
DEF Close:CHAR
Line 277 ⟶ 576:
 
Output: Maximum drawing area values: width is 1280 and height is 749.
</syntaxhighlight>
</lang>
 
=={{header|MathematicaJ}}==
 
For this task, we can create a temporary window, and subtract its usable area from its size. This gives us the size (in pixels) used for decorations. Then we can query the screen size and subtract the size of those decorations.
 
For example:
 
<syntaxhighlight lang="j"> (".wd 'qscreen') -&(2 3&{) (wd'pclose') ]-/".'qform',:&wd 'pc a; cc g isidraw; pshow; qchildxywh g'
1348 750</syntaxhighlight>
 
Here, we had a screen with 1366 by 768 pixels (width and height), and space for decorations subtract 18 from each of those dimensions.
 
=={{header|Java}}==
<syntaxhighlight lang="java">import java.awt.*;
import javax.swing.JFrame;
 
public class Test extends JFrame {
 
public static void main(String[] args) {
new Test();
}
 
Test() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
 
Dimension screenSize = toolkit.getScreenSize();
System.out.println("Physical screen size: " + screenSize);
 
Insets insets = toolkit.getScreenInsets(getGraphicsConfiguration());
System.out.println("Insets: " + insets);
 
screenSize.width -= (insets.left + insets.right);
screenSize.height -= (insets.top + insets.bottom);
System.out.println("Max available: " + screenSize);
}
}</syntaxhighlight>
 
Output:
 
<pre>Physical screen size: java.awt.Dimension[width=1920,height=1080]
Insets: java.awt.Insets[top=0,left=0,bottom=30,right=0]
Max available: java.awt.Dimension[width=1920,height=1050]</pre>
 
=={{header|Julia}}==
Uses the Gtk library.
<syntaxhighlight lang="julia">
win = GtkWindow("hello", 100, 100)
fullscreen(win)
sleep(10)
println(width(win), " ", height(win))
destroy(win)
</syntaxhighlight>
{{output}} <pre>
1920 1080
</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang="scala">// version 1.1
 
import java.awt.Toolkit
import javax.swing.JFrame
 
class Test : JFrame() {
init {
val r = Regex("""\[.*\]""")
val toolkit = Toolkit.getDefaultToolkit()
val screenSize = toolkit.screenSize
println("Physical screen size : ${formatOutput(screenSize, r)}")
val insets = toolkit.getScreenInsets(graphicsConfiguration)
println("Insets : ${formatOutput(insets, r)}")
screenSize.width -= (insets.left + insets.right)
screenSize.height -= (insets.top + insets.bottom)
println("Max available : ${formatOutput(screenSize, r)}")
}
 
private fun formatOutput(output: Any, r: Regex) = r.find(output.toString())!!.value.replace(",", ", ")
}
 
fun main(args: Array<String>) {
Test()
}</syntaxhighlight>
Sample output:
{{out}}
<pre>
Physical screen size : [width=1366, height=768]
Insets : [top=0, left=0, bottom=40, right=0]
Max available : [width=1366, height=728]
</pre>
 
=={{header|Lingo}}==
<syntaxhighlight lang="lingo">put _system.desktopRectList
-- [rect(0, 0, 1360, 768), rect(1360, 0, 2960, 1024)]</syntaxhighlight>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">nw = require("nw")
win = nw:app():window(320, 240)
win:show()
win:maximize()
cw, ch = win:client_size()
print(cw .. " x " .. ch)</syntaxhighlight>
On a 1920 x 1080 screen..
{{out}}
<pre>1920 x 1017</pre>
 
=={{header|M2000 Interpreter}}==
Move console to all monitors, at full screen (at each monitor). Then open a form and resize it to fill all monitors, the move the form to monitor with bigger area and expand form to fill that monitor. At the end close the window. All actions performed with once running threads, using After milliseconds { }
 
 
Unit for screen is twip (not pixel)
 
We can read twipsX and twipsY as twips per pixel in X and Y direction
 
<syntaxhighlight lang="m2000 interpreter">
Module CheckAllMonitors {
mode 16 ' font size
i=-1
Flush
Do {
i++
Window mode, i
Print Window=i
Wait 100
Form ; ' expand Background to fill monitor (form without arguments cut that frame)
if window=i Then {
Background {
Cls 0, 0
data i, scale.x, scale.y, motion.x, motion.y
}
} else exit
} Always
Dim Scrx(i), ScrY(i), ScrLeft(i), ScrTop(i)
While Not Empty {
Read i
Read Scrx(i), ScrY(i), ScrLeft(i), ScrTop(i)
}
\\ check if we have same left top point
For i=0 to Len(Scrx())-1 {
Print "Monitor:", i, "left top (";ScrLeft(i);",";ScrTop(i);") size: (";Scrx(i);",";ScrY(i);")"
}
A=ScrLeft(0)
B=ScrTop(0)
LeftMargin=A
TopMargin=B
RightMargin=Scrx(0)+A
BottomMargin=Scry(0)+B
MaxArea=Scrx(0)*Scry(0)
ChooseMonitor=0
Out=True
If Len(Scrx())>1 then {
For i=1 to Len(Scrx())-1 {
LeftMargin=Min.Data(A, ScrLeft(i))
TopMargin=Min.Data(B, ScrTop(i))
RightMargin=Max.Data(RightMargin, Scrx(i)+Scrleft(i))
BottomMargin=Max.Data(BottomMargin, Scry(i)+ScrTop(i))
Out=Out and (A=ScrLeft(i) and B=ScrTop(i))
if MaxArea<Scrx(i)*Scry(i) then MaxArea=Scrx(i)*Scry(i) : ChooseMonitor=i
}
}
If Len(Scrx())=1 then {
Print "One Monitor"
} else Print If$(Out ->"Clone Monitors", "Multiple Monitors ")
Print "Left Top Corner:", LeftMargin, TopMargin
Print "Width, Height", RightMargin-LeftMargin, BottomMargin-TopMargin
Declare Form1 Form
\\ After 100ms Form1 expand to all monitors
After 100 {
Method Form1,"Move", LeftMargin, TopMargin, RightMargin-LeftMargin, BottomMargin-TopMargin
}
\\ After 2000-100ms Form1 move to montior ChooseMonitor, and has same width and height
After 2000 {
Try {
Method Form1,"Move", ScrLeft(ChooseMonitor),ScrTop(ChooseMonitor), Scrx(ChooseMonitor), Scry(ChooseMonitor)
}
}
\\ after 4000 ms from other threads, form1 close
After 4000 {
Try {
Method Form1, "CloseNow"
}
}
Method Form1, "Show", 1
Declare Form1 Nothing
Threads Erase
}
CheckAllMonitors
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Example output on a 1280x1024 system.
<langsyntaxhighlight Mathematicalang="mathematica">Differences@Transpose@SystemInformation["Devices"][[1, 2, 1, 1, 2]]
->{{1260, 951}}</langsyntaxhighlight>
 
=={{header|Nim}}==
===With Gtk2 ===
{{libheader|Gtk2}}
Getting the screen size, ignoring borders, is as easy as:
<syntaxhighlight lang="nim">import
gtk2, gdk2
 
nim_init()
var w = gdk2.screen_width()
var h = gdk2.screen_height()
echo("WxH=",w,"x",h)</syntaxhighlight>
{{out}}
<pre>WxH=1920x1080</pre>
 
But getting the real size excluding borders is more difficult, at least with Gtk. We need to draw a window at maximum size and wait enough time before asking for its size. The following program does the job:
<syntaxhighlight lang="nim">import glib2, gtk2
 
proc printSize(window: PWindow): guint {.cdecl.} =
var width, height: gint
window.get_size(addr(width), addr(height))
echo "W x H = ", width, " x ", height
main_quit()
 
nim_init()
 
let window = window_new(WINDOW_TOPLEVEL)
window.maximize()
window.show_all()
 
discard g_timeout_add(100, printSize, addr(window[]))
 
main()</syntaxhighlight>
{{out}}
<pre>W x H = 1920 x 1031</pre>
 
===With Gtk3 (gintro)===
{{libheader|gintro}}
This is the translation of Gtk2 program to Gtk3 using “gintro” bindings.
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio]
 
var window: ApplicationWindow
 
#---------------------------------------------------------------------------------------------------
 
proc printSize(data: pointer): gboolean {.cdecl.} =
var width, height: int
window.getSize(width, height)
echo "W x H = ", width, " x ", height
window.destroy()
 
#---------------------------------------------------------------------------------------------------
 
proc activate(app: Application) =
## Activate the application.
 
window = app.newApplicationWindow()
window.maximize()
window.showAll()
 
discard timeoutAdd(PRIORITY_DEFAULT, 100, SourceFunc(printSize), nil, nil)
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
let app = newApplication(Application, "Rosetta.ScreenSize")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
{{out}}
<pre>W x H = 1920 x 1031</pre>
 
===With IUP===
{{libheader|IUP}}
<syntaxhighlight lang="nim">import
iup
 
# assumes you have the iup .dll or .so installed
 
discard iup.open(nil,nil)
 
var scrnFullSize = GetGlobal("FULLSIZE")
var scrnSize = GetGlobal("SCREENSIZE")
var scrnMInfo = GetGlobal("MONITORSINFO")
var scrnVScreen = GetGlobal("VIRTUALSCREEN")
 
var dlg = Dialog(nil)
SetAttribute(dlg, "SIZE", "FULL")
var scrnXSize = GetAttribute(dlg,"MAXSIZE")
 
echo scrnFullSize, "\n", scrnSize, "\n", scrnMInfo, "\n", scrnVScreen, "\n", scrnXSize
 
discard iup.Alarm("Screen client size", scrnFullSize ,"Ok",nil, nil)
 
#discard iup.mainloop()
iup.close()</syntaxhighlight>
{{out}}
<pre>1280x800
1280x800
0 0 1280 800
 
0 0 1280 800
65535x65535</pre>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">plothsizes()[1..2]</syntaxhighlight>
 
=={{header|Perl}}==
==={{libheader|Perl/Tk}}===
<lang Perl>
<syntaxhighlight lang="perl">
use strict;
use warnings;
Line 294 ⟶ 886:
return ($mw->maxsize);
}
</syntaxhighlight>
</lang>
get_size returns (1425,870) here.
 
=={{header|Phix}}==
{{trans|Nim}}
{{libheader|Phix/pGUI}}
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">scrnFullSize</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetGlobal</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"FULLSIZE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">scrnSize</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetGlobal</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"SCREENSIZE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">scrnMInfo</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetGlobal</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"MONITORSINFO"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">scrnVScreen</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetGlobal</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"VIRTUALSCREEN"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"SIZE=FULL"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">scrnXSize</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"MAXSIZE"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?{</span><span style="color: #000000;">scrnFullSize</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">scrnSize</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">scrnMInfo</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">scrnVScreen</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">scrnXSize</span><span style="color: #0000FF;">}</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{Out}}
<pre>
{"1920x1080","1920x1080","0 0 1920 1080\n","0 0 1920 1080","65535x65535"}
</pre>
You could instead use atom {x,y} = IupGetIntInt(NULL,"FULLSIZE"|"SCREENSIZE"|"MAXSIZE") to get numbers instead of strings.
 
=={{header|PicoLisp}}==
The following works on ErsatzLisp, the Java version of PicoLisp.
<langsyntaxhighlight PicoLisplang="picolisp">(let Frame (java "javax.swing.JFrame" T "Window")
(java Frame 'setExtendedState
(java (public "javax.swing.JFrame" 'MAXIMIZED_BOTH)) )
Line 307 ⟶ 925:
(prinl "Width: " (java (public Size 'width)))
(prinl "Height: " (java (public Size 'height))) )
(java Frame 'dispose) )</langsyntaxhighlight>
Output (on a 1024x768 screen):
<pre>Width: 1010
Height: 735</pre>
 
=={{header|Processing}}==
 
fullScreen() is the recommended approach to draw a window covering the entire screen from Processing 3.0+ onwards. The implementation below first creates a window and then prints the dimensions onto the canvas.
 
<syntaxhighlight lang="java">
//Aamrun, 26th June 2022
 
fullScreen();
fill(0);
textSize(50);
text("Screen Height : " + str(height), 100, 100);
text("Screen Width : " + str(width), 100, 200);
</syntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">If OpenWindow(0, 0, 0, 5, 5, "", #PB_Window_Maximize + #PB_Window_Invisible)
maxX = WindowWidth(0)
maxY = WindowHeight(0)
CloseWindow(0)
MessageRequester("Result", "Maximum Window Width: " + Str(maxX) + ", Maximum Window Height: " + Str(maxY))
EndIf</langsyntaxhighlight>
Sample output for a screen area 1600 x 1200:
<pre>Maximum Window Width: 1600, Maximum Window Height: 1181</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
#!/usr/bin/env python3
 
import tkinter as tk # import the module.
 
root = tk.Tk() # Create an instance of the class.
root.state('zoomed') # Maximized the window.
root.update_idletasks() # Update the display.
tk.Label(root, text=(str(root.winfo_width())+ " x " +str(root.winfo_height())),
font=("Helvetica", 25)).pack() # add a label and set the size to text.
root.mainloop()
</syntaxhighlight>
Sample output for 1366 x 768 screen:
<pre>1366 x 706</pre>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket/gui
(define-values [W H]
Line 330 ⟶ 978:
(send f show #f))))
(printf "~ax~a\n" W H)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.12}}
This is kind-of a silly task. The maximum window size is going to depend on your OS, hardware, display server and graphics toolkit, not your programming language. Taken at face value, using a Linux system running an X11 display server, the maximum displayable window size is the resolution of your monitor. Basically, the size of your desktop viewport. The Raku module X11::libxdo returns the desktop viewport size for get-desktop-dimensions which is the effective maximum window size.
 
<syntaxhighlight lang="raku" line>use X11::libxdo;
 
my $xdo = Xdo.new;
 
my ($dw, $dh) = $xdo.get-desktop-dimensions( 0 );
 
say "Desktop viewport dimensions: (maximum-fullscreen size) $dw x $dh";</syntaxhighlight>
{{out|On my system returns}}
<pre>Desktop viewport dimensions: (maximum-fullscreen size) 1920 x 1080</pre>
 
=={{header|REXX}}==
Most REXX interpreters essentially run "inside" a DOS window, &nbsp; and any attempts to find the (maximum) size of that
<br>window is limited to that (current) window, not the maximum.
 
Furthermore, the maximum size would depend on the &nbsp; ''smallest'' &nbsp; font supported by that window, which is dependent
<br>upon which code page is being used &nbsp; (and what font sizes it supports). &nbsp; On this author's system, &nbsp; it's a (fixed) font
<br>size of &nbsp; '''5''' &nbsp; (which is <u>barely</u> readable, &nbsp; but it's useful for &nbsp; X,Y &nbsp; plotting or for cut─n─paste).
 
It should be noted that DOS doesn't support a window that extends to other monitors. <br><br>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
load "guilib.ring"
new qApp {
win1 = new qWidget() {
new qPushButton(win1) {
resize(200,200)
settext("Info")
setclickevent(' win1{ setwindowtitle("Width: " + width() + " Height : " + height() ) }')
}
showMaximized()}
exec()
}
</syntaxhighlight>
 
Output:
 
[[File:CalmoSoftWindowSize.jpg]]
 
=={{header|Run BASIC}}==
Line 336 ⟶ 1,028:
IE browser uses different functions than everyone else.
So you write code for the world, and also for IE
<langsyntaxhighlight lang="runbasic">
html "<INPUT TYPE='HIDDEN' id='winHigh' name='winHigh' VALUE='";winHigh;"'></input>"
html "<INPUT TYPE='HIDDEN' id='winWide' name='winWide' VALUE='";winWide;"'></input>"
Line 370 ⟶ 1,062:
var x = winSize();
//--></script>
"</langsyntaxhighlight>
 
=={{header|Scala}}==
<syntaxhighlight lang="scala">import java.awt.{Dimension, Insets, Toolkit}
 
import javax.swing.JFrame
 
class MaxWindowDims() extends JFrame {
val toolkit: Toolkit = Toolkit.getDefaultToolkit
val (insets0, screenSize) = (toolkit.getScreenInsets(getGraphicsConfiguration), toolkit.getScreenSize)
 
println("Physical screen size: " + screenSize)
System.out.println("Insets: " + insets0)
screenSize.width -= (insets0.left + insets0.right)
screenSize.height -= (insets0.top + insets0.bottom)
System.out.println("Max available: " + screenSize)
}
 
object MaxWindowDims {
def main(args: Array[String]): Unit = {
new MaxWindowDims
}
}</syntaxhighlight>
 
=={{header|Sidef}}==
Using the Tk library:
<syntaxhighlight lang="ruby">require('Tk')
 
func max_window_size() -> (Number, Number) {
%s'MainWindow'.new.maxsize;
}
 
var (width, height) = max_window_size();
say (width, 'x', height);</syntaxhighlight>
 
{{out}}
<pre>
1905x1050
</pre>
 
=={{header|Tcl}}==
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tk
proc maxSize {} {
# Need a dummy window; max window can be changed by scripts
Line 384 ⟶ 1,114:
# Default max size of window is value we want
return [wm maxsize $top]
}</langsyntaxhighlight>
On this system, that returns <code>1440 836</code>. Further discussion of related matters, including platform limitations, is on [http://wiki.tcl.tk/10872 the Tcler's Wiki].
 
== {{header|Visual Basic}} ==
 
=== Method 1 ===
Line 393 ⟶ 1,123:
The first method involves querying the screen dimensions and then subtracting pixels used by the frame and desktop bars:
 
<langsyntaxhighlight lang="vb">TYPE syswindowstru
screenheight AS INTEGER
screenwidth AS INTEGER
Line 407 ⟶ 1,137:
syswindow.screenheight=Screen.Height / Screen.TwipsPerPixelY
 
' Make adjustments for window decorations and menubars</langsyntaxhighlight>
 
=== Method 2 ===
 
The alternative method is to create a form that is maximized and then query its dimensions (similar to the method used in gambas).
 
=={{header|Visual Basic .NET}}==
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)
{{works with|.NET Framework|4.7.2}} (simple enough that it should probably work on every Framework version--.NET Core 3.0 will support Windows Forms on Windows only)
Must be referenced:
<!--Wrap in a span with display:flex to remove libheader's line break-->
<span style="display:flex">{{libheader|GDI+}}<span style="white-space:pre"> (managed interface) [System.Drawing]</span></span>
<span style="display:flex">{{libheader|Windows Forms}}<span style="white-space:pre"> [System.Windows.Forms]</span></span>
 
Bounds are the screen's dimensions; working area is the is the region that excludes "taskbars, docked windows, and docked tool bars" (from Framework documentation).
 
<syntaxhighlight lang="vbnet">Imports System.Drawing
Imports System.Windows.Forms
 
Module Program
Sub Main()
Dim bounds As Rectangle = Screen.PrimaryScreen.Bounds
Console.WriteLine($"Primary screen bounds: {bounds.Width}x{bounds.Height}")
 
Dim workingArea As Rectangle = Screen.PrimaryScreen.WorkingArea
Console.WriteLine($"Primary screen working area: {workingArea.Width}x{workingArea.Height}")
End Sub
End Module</syntaxhighlight>
 
{{out}}
<pre>Primary screen bounds: 1714x1143
Primary screen working area: 1714x1103</pre>
 
Alternatively, use the dimensions of a borderless form with WindowState set to FormWindowState.Maximized (i.e. a full-screen window that is shown above the taskbar).
 
<syntaxhighlight lang="vbnet">Imports System.Drawing
Imports System.Windows.Forms
 
Module Program
Sub Main()
Using f As New Form() With {
.WindowState = FormWindowState.Maximized,
.FormBorderStyle = FormBorderStyle.None
}
 
f.Show()
Console.WriteLine($"Size of maximized borderless form: {f.Width}x{f.Height}")
End Using
End Sub
End Module</syntaxhighlight>
 
{{out}}
<pre>Size of maximized borderless form: 1714x1143</pre>
 
=={{header|V (Vlang)}}==
Graphical
<syntaxhighlight lang="Zig">
import ui
import gg
import gx
 
[heap]
struct App {
mut:
window &ui.Window = unsafe {nil}
}
 
fn main() {
mut app := &App{}
app.window = ui.window(
width: gg.screen_size().width
height: gg.screen_size().height
bg_color: gx.white
title: "Maximum Window"
mode: .resizable
layout: ui.row(
spacing: 5
margin_: 10
widths: ui.stretch
heights: ui.stretch
children: [
ui.label(
id: "info"
text: "Window dimensions: W ${gg.screen_size().width} x H ${gg.screen_size().height}"
),
]
)
)
ui.run(app.window)
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "input" for Keyboard
import "dome" for Window, Process
import "graphics" for Canvas, Color
 
class Game {
static init() {
Canvas.print("Maximize the window and press 'm'", 0, 0, Color.white)
}
 
static update() {
if (Keyboard.isKeyDown("m") ) {
System.print("Maximum window dimensions are %(Window.width) x %(Window.height)")
Process.exit(0)
}
}
 
static draw(alpha) {}
}</syntaxhighlight>
 
{{out}}
<pre>
$ ./dome max_window_dimensions.wren
Maximum window dimensions are 1853 x 1018
</pre>
 
=={{header|XPL0}}==
GetFB is a built-in function available on the Raspberry Pi that returns information about the current frame buffer.
<syntaxhighlight lang="xpl0">int A;
[A:= GetFB;
Text(0, "Width = "); IntOut(0, A(0)); CrLf(0);
Text(0, "Height = "); IntOut(0, A(1)); CrLf(0);
]</syntaxhighlight>
 
{{out}}
<pre>
Width = 1280
Height = 720
</pre>
 
[[Category:Initialization]]
Line 417 ⟶ 1,274:
{{omit from|ACL2}}
{{omit from|AWK}}
{{omit from|CBatch File|NoBatch wayFiles(pure) tocannot doextend it meaningfully orto portablyGUI.}}
{{omit from|Commodore BASIC}}
{{omit from|GUISS}}
{{omit from|Logtalk}}
{{omit from|Lotus 123 Macro Scripting}}
{{omit from|Maxima}}
{{omit from|RetroSQL PL|It does not handle GUI}}
9,476

edits