Window management: Difference between revisions
Content added Content deleted
(Added Wren) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 33: | Line 33: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">F1:: ;; when user hits the F1 key, do the following |
||
WinGetTitle, window, A ; get identity of active window into a variable |
WinGetTitle, window, A ; get identity of active window into a variable |
||
WinMove, %window%, , 100, 100, 800, 800 ; move window to coordinates, 100, 100 |
WinMove, %window%, , 100, 100, 800, 800 ; move window to coordinates, 100, 100 |
||
Line 53: | Line 53: | ||
} |
} |
||
WinClose, % window |
WinClose, % window |
||
return</ |
return</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang="bbcbasic"> SWP_NOMOVE = 2 |
||
SWP_NOZORDER = 4 |
SWP_NOZORDER = 4 |
||
SW_MAXIMIZE = 3 |
SW_MAXIMIZE = 3 |
||
Line 94: | Line 94: | ||
PRINT "Closing the window in two seconds..." |
PRINT "Closing the window in two seconds..." |
||
WAIT 200 |
WAIT 200 |
||
QUIT</ |
QUIT</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
C does not have any standard windowing library, although cross platform libraries are available, and although it's technically possible to create windows from scratch given the '''''Dark powers''''' that C commands, I chose the simplest option, the Windows API. On running this program, the user is taken over all the sub tasks listed in this task one by one. |
C does not have any standard windowing library, although cross platform libraries are available, and although it's technically possible to create windows from scratch given the '''''Dark powers''''' that C commands, I chose the simplest option, the Windows API. On running this program, the user is taken over all the sub tasks listed in this task one by one. |
||
===Windows=== |
===Windows=== |
||
<syntaxhighlight lang="c"> |
|||
<lang C> |
|||
#include<windows.h> |
#include<windows.h> |
||
#include<unistd.h> |
#include<unistd.h> |
||
Line 238: | Line 238: | ||
return Msg.wParam; |
return Msg.wParam; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
< |
<syntaxhighlight lang="gambas">sWindow As New String[4] |
||
'________________________ |
'________________________ |
||
Public Sub Form_Open() |
Public Sub Form_Open() |
||
Line 327: | Line 327: | ||
End If |
End If |
||
End</ |
End</syntaxhighlight> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 352: | Line 352: | ||
{{libheader|gotk3}} |
{{libheader|gotk3}} |
||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 451: | Line 451: | ||
window.ShowAll() |
window.ShowAll() |
||
gtk.Main() |
gtk.Main() |
||
}</ |
}</syntaxhighlight> |
||
=={{header|HicEst}}== |
=={{header|HicEst}}== |
||
< |
<syntaxhighlight lang="hicest">CHARACTER title="Rosetta Window_management" |
||
REAL :: w=-333, h=25, x=1, y=0.5 ! pixels < 0, relative window size 0...1, script character size > 1 |
REAL :: w=-333, h=25, x=1, y=0.5 ! pixels < 0, relative window size 0...1, script character size > 1 |
||
Line 463: | Line 463: | ||
WINDOW(WIN=wh, MAXimize) ! maximize (hides the script window) |
WINDOW(WIN=wh, MAXimize) ! maximize (hides the script window) |
||
WINDOW(Kill=wh) ! close |
WINDOW(Kill=wh) ! close |
||
END</ |
END</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
The demo program opens three windows, one with a running commentary on the action. |
The demo program opens three windows, one with a running commentary on the action. |
||
< |
<syntaxhighlight lang="icon">link graphics |
||
procedure main() |
procedure main() |
||
Line 519: | Line 519: | ||
WWrite(W3,"Enter Q or q here to quit") |
WWrite(W3,"Enter Q or q here to quit") |
||
WDone(W3) |
WDone(W3) |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 526: | Line 526: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
Java cannot (easily) manipulate windows created by other programs. This code manipulates windows that it has created, but any window created in the same JVM can be controlled similarly. This example uses Swing - for AWT or SWT go figure. |
Java cannot (easily) manipulate windows created by other programs. This code manipulates windows that it has created, but any window created in the same JVM can be controlled similarly. This example uses Swing - for AWT or SWT go figure. |
||
< |
<syntaxhighlight lang="java">import java.awt.BorderLayout; |
||
import java.awt.EventQueue; |
import java.awt.EventQueue; |
||
import java.awt.Frame; |
import java.awt.Frame; |
||
Line 717: | Line 717: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Uses the Gtk windowing package, so the package can manage Gtk's windows. |
Uses the Gtk windowing package, so the package can manage Gtk's windows. |
||
< |
<syntaxhighlight lang="julia">using Gtk |
||
function controlwindow(win, lab) |
function controlwindow(win, lab) |
||
Line 764: | Line 764: | ||
runwindow() |
runwindow() |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
Mathematica can only easily access and control windows created by itself. |
Mathematica can only easily access and control windows created by itself. |
||
< |
<syntaxhighlight lang="mathematica">nb=NotebookCreate[]; (*Create a window and store in a variable*) |
||
nb===nb2 (*test for equality with another window object*) |
nb===nb2 (*test for equality with another window object*) |
||
SetOptions[nb,Visible->False](*Hide*) |
SetOptions[nb,Visible->False](*Hide*) |
||
Line 774: | Line 774: | ||
NotebookClose[nb] (*Close*) |
NotebookClose[nb] (*Close*) |
||
SetOptions[nb,WindowMargins->{{x,Automatic},{y,Automatic}}](*Move to x,y screen position*) |
SetOptions[nb,WindowMargins->{{x,Automatic},{y,Automatic}}](*Move to x,y screen position*) |
||
SetOptions[nb,WindowSize->{100,100}](*Resize*)</ |
SetOptions[nb,WindowSize->{100,100}](*Resize*)</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
==={{libheader|gintro}}=== |
==={{libheader|gintro}}=== |
||
< |
<syntaxhighlight lang="nim">import os |
||
import gintro/[glib, gobject, gtk, gio] |
import gintro/[glib, gobject, gtk, gio] |
||
from gintro/gdk import processAllUpdates |
from gintro/gdk import processAllUpdates |
||
Line 862: | Line 862: | ||
let app = newApplication(Application, "Rosetta.Window.Management") |
let app = newApplication(Application, "Rosetta.Window.Management") |
||
discard app.connect("activate", activate) |
discard app.connect("activate", activate) |
||
discard app.run()</ |
discard app.run()</syntaxhighlight> |
||
==={{libheader|Gtk2}}=== |
==={{libheader|Gtk2}}=== |
||
< |
<syntaxhighlight lang="nim">import os |
||
import gdk2, glib2, gtk2 |
import gdk2, glib2, gtk2 |
||
Line 941: | Line 941: | ||
discard bQuit.signal_connect("clicked", SIGNAL_FUNC(thisDestroy), nil) |
discard bQuit.signal_connect("clicked", SIGNAL_FUNC(thisDestroy), nil) |
||
window.show_all() |
window.show_all() |
||
main()</ |
main()</syntaxhighlight> |
||
==={{libheader|IUP}}=== |
==={{libheader|IUP}}=== |
||
< |
<syntaxhighlight lang="nim">import iup |
||
# assumes you have the iup .dll or .so installed |
# assumes you have the iup .dll or .so installed |
||
Line 1,011: | Line 1,011: | ||
discard dlg.show() |
discard dlg.show() |
||
discard mainloop() |
discard mainloop() |
||
iup.Close()</ |
iup.Close()</syntaxhighlight> |
||
=={{header|Oz}}== |
=={{header|Oz}}== |
||
Line 1,022: | Line 1,022: | ||
because it shows how to extend an object's interface even when we don't have control over object creation. |
because it shows how to extend an object's interface even when we don't have control over object creation. |
||
< |
<syntaxhighlight lang="oz">declare |
||
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']} |
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']} |
||
Line 1,109: | Line 1,109: | ||
end |
end |
||
in |
in |
||
{Record.forAll Windows CreateWindow}</ |
{Record.forAll Windows CreateWindow}</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Line 1,119: | Line 1,119: | ||
I wrote the code using the Tk module, as that's what I had on my computer, and I was too lazy to install Tkx. Translating from perl/tk to Tkx should be fairly trivial. |
I wrote the code using the Tk module, as that's what I had on my computer, and I was too lazy to install Tkx. Translating from perl/tk to Tkx should be fairly trivial. |
||
< |
<syntaxhighlight lang="perl">#!perl |
||
use strict; |
use strict; |
||
use warnings; |
use warnings; |
||
Line 1,196: | Line 1,196: | ||
__END__ |
__END__ |
||
</syntaxhighlight> |
|||
</lang> |
|||
In the Tcl code I translated from, the second label of the main window had a textvariable attribute. For some reason, this didn't work correctly for me, either due to a bug in Tk.pm, or some other reason. Because of that, I kept around a handle to that second label ($lab), and called configure on it when I needed it's text to change. |
In the Tcl code I translated from, the second label of the main window had a textvariable attribute. For some reason, this didn't work correctly for me, either due to a bug in Tk.pm, or some other reason. Because of that, I kept around a handle to that second label ($lab), and called configure on it when I needed it's text to change. |
||
Line 1,206: | Line 1,206: | ||
{{libheader|Phix/basics}} |
{{libheader|Phix/basics}} |
||
{{libheader|Phix/pGUI}} |
{{libheader|Phix/pGUI}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Window_management.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Window_management.exw</span> |
||
<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: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 1,279: | Line 1,279: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
||
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
The following works on ErsatzLisp, the Java version of PicoLisp. |
The following works on ErsatzLisp, the Java version of PicoLisp. |
||
< |
<syntaxhighlight lang="picolisp">$ ersatz/pil + |
||
: (setq |
: (setq |
||
JFrame "javax.swing.JFrame" |
JFrame "javax.swing.JFrame" |
||
Line 1,322: | Line 1,322: | ||
# Close window |
# Close window |
||
(java Win 'dispose)</ |
(java Win 'dispose)</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">;- Create a linked list to store created windows. |
||
NewList Windows() |
NewList Windows() |
||
Define i, j, dh, dw, flags, err$, x, y |
Define i, j, dh, dw, flags, err$, x, y |
||
Line 1,384: | Line 1,384: | ||
Delay(2000) |
Delay(2000) |
||
End</ |
End</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 1,390: | Line 1,390: | ||
{{libheader|tkinter}} |
{{libheader|tkinter}} |
||
Using the tkinter GUI: |
Using the tkinter GUI: |
||
<syntaxhighlight lang="python"> |
|||
<lang Python> |
|||
from tkinter import * |
from tkinter import * |
||
import tkinter.messagebox |
import tkinter.messagebox |
||
Line 1,423: | Line 1,423: | ||
mainloop() |
mainloop() |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket/gui |
#lang racket/gui |
||
Line 1,444: | Line 1,444: | ||
(say 'Resize) (send frame resize 100 100) (sleep 1) |
(say 'Resize) (send frame resize 100 100) (sleep 1) |
||
(say 'Close) (send frame show #f) (sleep 1) ; that's how we close a window |
(say 'Close) (send frame show #f) (sleep 1) ; that's how we close a window |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 1,451: | Line 1,451: | ||
This are generic window handling routines. They work for any window managed by the X11 display server, not just windows created by the program. |
This are generic window handling routines. They work for any window managed by the X11 display server, not just windows created by the program. |
||
<lang |
<syntaxhighlight lang="raku" line>use X11::libxdo; |
||
my $xdo = Xdo.new; |
my $xdo = Xdo.new; |
||
Line 1,514: | Line 1,514: | ||
$xdo.raise-window($id); |
$xdo.raise-window($id); |
||
sleep .25; |
sleep .25; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
Load "guilib.ring" |
Load "guilib.ring" |
||
Line 1,672: | Line 1,672: | ||
###-------------------------------------------- |
###-------------------------------------------- |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
< |
<syntaxhighlight lang="tcl">package require Tk |
||
# How to open a window |
# How to open a window |
||
Line 1,737: | Line 1,737: | ||
grid [button .b4 -text "Maximize" -command maximizeWin] - |
grid [button .b4 -text "Maximize" -command maximizeWin] - |
||
grid [button .b5 -text "Move" -command moveWin] - |
grid [button .b5 -text "Move" -command moveWin] - |
||
grid [button .b6 -text "Resize" -command resizeWin] -</ |
grid [button .b6 -text "Resize" -command resizeWin] -</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 1,744: | Line 1,744: | ||
The following just manipulates a window created by the application itself and works fine on Ubuntu 20.04. |
The following just manipulates a window created by the application itself and works fine on Ubuntu 20.04. |
||
< |
<syntaxhighlight lang="ecmascript">/* window_management.wren */ |
||
var GTK_WINDOW_TOPLEVEL = 0 |
var GTK_WINDOW_TOPLEVEL = 0 |
||
Line 1,860: | Line 1,860: | ||
buttonBox.add(btnClose) |
buttonBox.add(btnClose) |
||
Window.showAll()</ |
Window.showAll()</syntaxhighlight> |
||
<br> |
<br> |
||
We now embed the above script in the following C program, build and run. |
We now embed the above script in the following C program, build and run. |
||
< |
<syntaxhighlight lang="c">/* gcc `pkg-config --cflags gtk+-3.0` -DGDK_VERSION_MIN_REQIRED=GDK_VERSION_3_2 window_management.c -o window_management `pkg-config --libs gtk+-3.0` -lwren -lm */ |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
Line 2,112: | Line 2,112: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |