Window creation: Difference between revisions

→‎{{header|PureBasic}}: expanding the task
(→‎{{header|PureBasic}}: expanding the task)
 
(12 intermediate revisions by 11 users not shown)
Line 6:
{{libheader|GtkAda}}
{{uses from|library|GtkAda|component1=Window|component2=Widget|component3=Handlers|component4=Main}}
<langsyntaxhighlight lang="ada">with Gtk.Window; use Gtk.Window;
with Gtk.Widget; use Gtk.Widget;
 
Line 46:
 
Gtk.Main.Main;
end Windowed_Application;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 52:
{{works with|ELLA ALGOL 68|[https://sourceforge.net/projects/algol68/files/algol68toc/algol68toc_1.14 algol68toc_1.14]}}
'''Compile command:''' ca -l gtk-3 -l gdk-3 -l atk-1.0 -l gio-2.0 -l pangocairo-1.0 -l gdk_pixbuf-2.0 -l cairo-gobject -l pango-1.0 -l cairo -l gobject-2.0 -l glib-2.0 firstgtk.a68
<langsyntaxhighlight lang="algol68">PROGRAM firstgtk CONTEXT VOID
USE standard
BEGIN
Line 90:
gtk main
END
FINISH</langsyntaxhighlight>
 
 
=={{header|AmigaBASIC}}==
 
<langsyntaxhighlight lang="amigabasic">WINDOW 2,"New Window"</langsyntaxhighlight>
 
=={{header|AurelBasic}}==
<langsyntaxhighlight AurelBasiclang="aurelbasic">WIN 0 0 400 300 "New Window"</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Gui, Add, Text,, Hello
Gui, Show</langsyntaxhighlight>
 
=={{header|AutoIt}}==
<langsyntaxhighlight AutoItlang="autoit">GUICreate("Test")
GUISetState(@SW_SHOW)
 
Line 114:
Exit
EndSwitch
Until False</langsyntaxhighlight>
 
=={{header|BaCon}}==
BaCon includes a Highlevel Universal GUI abstraction layer (HUG). The implementation is based on GTK.
 
<langsyntaxhighlight lang="freebasic">REM empty window
INCLUDE "hug.bac"
 
Line 125:
 
REM start gtk event loop...
DISPLAY</langsyntaxhighlight>
 
 
=={{header|BASIC256}}==
BASIC256 it has a built-in graphics mode.
<syntaxhighlight lang="basic256">clg
text (50,50, "I write in the graphics area")</syntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
dlg% = FN_newdialog("GUI Window", 0, 0, 200, 150, 8, 1000)
PROC_showdialog(dlg%)</langsyntaxhighlight>
 
=={{header|C}}==
Line 142 ⟶ 148:
 
'''Compile Command:''' gcc `sdl-config --cflags` `sdl-config --libs` SDL_Window.c -o window
<langsyntaxhighlight lang="c">/*
* Opens an 800x600 16bit color window.
* Done here with ANSI C.
Line 163 ⟶ 169:
return 0;
}</langsyntaxhighlight>
 
===GTK===
Line 171 ⟶ 177:
'''Compile command:''' gcc `gtk-config --cflags` `gtk-config --libs` -o window window.c
 
<langsyntaxhighlight lang="c">#include <gtk/gtk.h>
 
int
Line 186 ⟶ 192:
 
return 0;
}</langsyntaxhighlight>
 
===GTK2===
Line 193 ⟶ 199:
'''Compile command:''' gcc -Wall -pedantic `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -o window window.c
 
<langsyntaxhighlight lang="c">#include <gtk/gtk.h>
 
int
Line 207 ⟶ 213:
 
return 0;
}</langsyntaxhighlight>
 
===GLUT===
Line 219 ⟶ 225:
We ''are'' registering a keypress callback, which isn't strictly necessary; It simply allows us to use a keypress to close the program rather than depending on the windowing system the program is run under.
 
<langsyntaxhighlight lang="c">// A C+GLUT implementation of the Creating a Window task at Rosetta Code
// http://rosettacode.org/wiki/Creating_a_Window
#include <stdlib.h>
Line 260 ⟶ 266:
}
 
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
Line 266 ⟶ 272:
{{libheader|Windows Forms}}
{{uses from|library|.NET Framework|component1=System.Windows.Forms|component2=System.Windows.Forms.Window|component3=System.Windows.Forms.Form|component4=System.Windows.Forms.Application}}
<langsyntaxhighlight lang="csharp">using System;
using System.Windows.Forms;
 
Line 280 ⟶ 286:
Application.Run();
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
Line 287 ⟶ 293:
'''Compiler command:''' qmake -pro; qmake
 
<langsyntaxhighlight lang="cpp">#include <QApplication>
#include <QMainWindow>
 
Line 296 ⟶ 302:
window.show();
return app.exec();
}</langsyntaxhighlight>
 
{{libheader|GTK}}
Line 302 ⟶ 308:
'''Compiler command:''' g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`
 
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <gtkmm.h>
 
Line 322 ⟶ 328:
exit( 0 ) ;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Line 328 ⟶ 334:
{{uses from|library|Swing|component1=JFrame}}
 
<langsyntaxhighlight lang="clojure">(import '(javax.swing JFrame))
 
(let [frame (JFrame. "A Window")]
(doto frame
(.setSize 600 800)
(.setVisible true)))</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 341 ⟶ 347:
{{works with|LispWorks}}
 
<langsyntaxhighlight lang="lisp">(capi:display (make-instance 'capi:interface :title "A Window"))</langsyntaxhighlight>
 
==={{libheader|CLIM}}===
Line 349 ⟶ 355:
Setting up the environment:
 
<langsyntaxhighlight lang="lisp">(require :mcclim)
(cl:defpackage #:rc-window
(:use #:clim-lisp #:clim))
(cl:in-package #:rc-window)</langsyntaxhighlight>
 
The actual definition and display:
 
<langsyntaxhighlight lang="lisp">(define-application-frame rc-window ()
()
(:layouts (:default)))
 
(run-frame-top-level (make-application-frame 'rc-window))</langsyntaxhighlight>
 
Note: This creates a small, useless window ("frame"). Useful frames will have some ''panes'' defined inside them.
Line 368 ⟶ 374:
Works with the Armed Bear Common Lisp implementation that targets the JVM.
 
<langsyntaxhighlight lang="lisp">(defun create-window ()
"Creates a window"
(let ((window (jnew (jconstructor "javax.swing.JFrame"))))
Line 374 ⟶ 380:
window (make-immediate-object t :boolean))))
 
(create-window)</langsyntaxhighlight>
 
=={{header|D}}==
{{libheader|FLTK4d}}
<langsyntaxhighlight lang="d"> module Window;
import fltk4d.all;
Line 386 ⟶ 392:
window.show;
FLTK.run;
}</langsyntaxhighlight>
 
{{libheader|Derelict}}
{{libheader|SDL}}
<langsyntaxhighlight lang="d"> import derelict.sdl.sdl;
int main(char[][] args)
Line 421 ⟶ 427:
return 0;
}</langsyntaxhighlight>
 
{{libheader|QD}}
QD is a simple and easy-to-use wrapper around SDL.
<langsyntaxhighlight lang="d"> import qd;
void main() {
screen(640, 480);
while (true) events();
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
Line 436 ⟶ 442:
This first example is a minimalist approach using Delphi's standard Window (form) creation procedure. In Delphi 7, this will create a single Window executable of 362KB.
 
<syntaxhighlight lang="delphi">
<lang Delphi>
 
// The project file (Project1.dpr)
Line 495 ⟶ 501:
end
 
</syntaxhighlight>
</lang>
 
This second example demonstrates a 'pure' Windows API approach (i.e. NOT using the Delphi Visual Component Library). In Delphi 7, this will create a single Window executable of 15KB.
 
<syntaxhighlight lang="delphi">
<lang Delphi>
program Project3;
 
Line 563 ⟶ 569:
 
end.
</syntaxhighlight>
</lang>
 
=={{header|Dragon}}==
{{libheader|GUI}}
<langsyntaxhighlight lang="dragon">select "GUI"
 
window = newWindow("Window")
Line 573 ⟶ 579:
window.setVisible()
 
</syntaxhighlight>
</lang>
 
=={{header|E}}==
Line 592 ⟶ 598:
Platform independent EiffelVision 2 Library
 
<langsyntaxhighlight lang="eiffel ">class
APPLICATION
inherit
Line 610 ⟶ 616:
first_window: MAIN_WINDOW
-- Main window.
end</langsyntaxhighlight>
 
<langsyntaxhighlight lang="eiffel ">class
MAIN_WINDOW
inherit
Line 662 ⟶ 668:
main_container_created: main_container /= Void
end
end</langsyntaxhighlight>
 
 
{{libheader|Windows Forms}}
<langsyntaxhighlight lang="eiffel ">class
APPLICATION
inherit
Line 684 ⟶ 690:
{WINFORMS_APPLICATION}.run_form (Current)
end
end</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(make-frame)</syntaxhighlight>
<lang lisp>
(make-frame)
</lang>
 
=={{header|Euphoria}}==
===ARWEN===
{{libheader|ARWEN}}
<langsyntaxhighlight lang="euphoria">include arwen.ew
 
constant win = create(Window, "ARWEN window", 0, 0,100,100,640,480,{0,0})
 
WinMain(win, SW_NORMAL)
</syntaxhighlight>
</lang>
 
===EuGTK===
{{libheader|EuGTK}}
<langsyntaxhighlight lang="euphoria">include GtkEngine.e
 
constant win = create(GtkWindow,"title=EuGTK Window;size=640x480;border=10;$destroy=Quit")
 
show_all(win)
main()</langsyntaxhighlight>
 
===EuWinGUI===
{{libheader|EuWinGUI}}
<langsyntaxhighlight lang="euphoria">include EuWinGUI.ew
 
Window("EuWinGUI window",100,100,640,480)
Line 721 ⟶ 725:
end while
 
CloseApp(0)</langsyntaxhighlight>
 
===Win32Lib===
{{libheader|Win32Lib}}
<langsyntaxhighlight lang="euphoria">include Win32Lib.ew
 
constant win = createEx( Window, "Win32Lib", 0, Default, Default, 640, 480, 0, 0 )
 
WinMain( win, Normal )</langsyntaxhighlight>
 
===wxEuphoria===
{{libheader|wxEuphoria}}
<langsyntaxhighlight lang="euphoria">include wxeu/wxeud.e
 
constant win = create( wxFrame, {0, -1, "wxEuphoria window", -1, -1, 640, 480} )
 
wxMain( win )</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 743 ⟶ 747:
 
{{libheader|Windows Forms}}
<langsyntaxhighlight lang="fsharp"> open System.Windows.Forms
[<System.STAThread>]
do
Form(Text = "F# Window")
|> Application.Run</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: ui ui.gadgets.labels ;
 
"This is a window..." <label> "Really?" open-window</langsyntaxhighlight>
 
=={{header|Fantom}}==
<langsyntaxhighlight lang="fantom">
using fwt
 
Line 766 ⟶ 770:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
Line 773 ⟶ 777:
'''gtk-server command:''' gtk-server -fifo=ffl-fifo &
 
<langsyntaxhighlight lang="forth">include ffl/gsv.fs
 
\ Open the connection to the gtk-server and load the Gtk2 definitions
Line 805 ⟶ 809:
 
gsv+close drop
[THEN]</langsyntaxhighlight>
 
===iMops===
{{works with|iMops on MacOS}}
<syntaxhighlight lang="iMops">
 
Window+ w \ create a window
View v \ create a view
300 30 430 230 put: frameRect \ size a rectangle for the view
frameRect " Test" docWindow v new: w \ activate the view and window
show: w \ display the window
 
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
<lang FreeBasic>
#Include "windows.bi"
 
Line 825 ⟶ 841:
 
End
</syntaxhighlight>
</lang>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
g=(new graphics).show[]
</syntaxhighlight>
</lang>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1</syntaxhighlight>
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">Public Sub Form_Open()
 
End</langsyntaxhighlight>
 
=={{header|Go}}==
===GTK===
{{libheader|go-gtk}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 854 ⟶ 873:
window.Show()
gtk.Main()
}</langsyntaxhighlight>
 
===SDL===
{{libheader|Go-SDL}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 879 ⟶ 898:
}
window.Destroy()
}</langsyntaxhighlight>
 
===X11===
<langsyntaxhighlight lang="go">package main
 
import (
Line 903 ⟶ 922:
}
}
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
Line 916 ⟶ 935:
We will open notepad as a window here.
<syntaxhighlight lang ="guiss">Start,Programs,Accessories,Notepad</langsyntaxhighlight>
 
To close the window:
 
<syntaxhighlight lang ="guiss">Window:Notepad,Button:Close</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 926 ⟶ 945:
 
A simple graphics library, designed to give the programmer access to most interesting parts of the Win32 Graphics Device Interface and X11 library without exposing the programmer to the pain and anguish usually associated with using these interfaces.
<langsyntaxhighlight lang="haskell">import Graphics.HGL
 
aWindow = runGraphics $
withWindow_ "Rosetta Code task: Creating a window" (300, 200) $ \ w -> do
drawInWindow w $ text (100, 100) "Hello World"
getKey w</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">WINDOW(WINdowhandle=handle, Width=80, Height=-400, X=1, Y=1/2, TItle="Rosetta Window_creation Example")
! window units: as pixels < 0, as relative window size 0...1, ascurrent character sizes > 1
 
WRITE(WINdowhandle=handle) '... some output ...'</langsyntaxhighlight>
 
=={{header|IDL}}==
Line 948 ⟶ 967:
Icon and Unicon windowing is portable between Windows and X-Windows environments.
==={{header|Icon}}===
<langsyntaxhighlight Iconlang="icon">link graphics
 
procedure main(arglist)
Line 954 ⟶ 973:
WOpen("size=300, 300", "fg=blue", "bg=light gray")
WDone()
end</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 962 ⟶ 981:
The Icon solution works in Unicon. An Unicon-only version is as follows:
 
<langsyntaxhighlight lang="unicon">
import gui
$include "guih.icn"
Line 980 ⟶ 999:
w.show_modal ()
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
A minimalist modal dialog:
<langsyntaxhighlight lang="j"> wdinfo 'Hamlet';'To be, or not to be: that is the question:'</langsyntaxhighlight>
 
A free-standing window:
<langsyntaxhighlight lang="j">MINWDW=: noun define
pc minwdw;
pas 162 85;pcenter;
Line 1,001 ⟶ 1,020:
)
minwdw_run ''</langsyntaxhighlight>
 
=={{header|Java}}==
{{libheader|Swing}}
<langsyntaxhighlight lang="java">import javax.swing.JFrame;
 
public class Main {
Line 1,014 ⟶ 1,033:
w.setVisible(true);
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 1,020 ⟶ 1,039:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6
 
using Tk
 
w = Toplevel("Example")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Java}}
 
<langsyntaxhighlight lang="kotlin">import javax.swing.JFrame
 
fun main(args : Array<String>) {
Line 1,037 ⟶ 1,056:
isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Liberty BASIC}}==
Minimum code required to fulfill the task.
<langsyntaxhighlight lang="lb">nomainwin
open "GUI Window" for window as #1
wait
</langsyntaxhighlight>
As it would properly be used in a real program.
<langsyntaxhighlight lang="lb">nomainwin
open "GUI Window" for window as #1
#1 "trapclose Quit"
Line 1,054 ⟶ 1,073:
end
end sub
</langsyntaxhighlight>
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">win = window().new("New Window")
w = 320
h = 240
Line 1,068 ⟶ 1,087:
-- it can be re-used for multiple windows.
win.filename = _movie.path & "empty.dir"
win.open()</langsyntaxhighlight>
 
=={{header|Lua}}==
{{libheader|IUPLua}}
<langsyntaxhighlight lang="lua">local iup = require "iuplua"
 
iup.dialog{
Line 1,083 ⟶ 1,102:
 
iup.MainLoop()
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
Line 1,098 ⟶ 1,117:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module DisplayWindow {
Declare MyForm Form
Line 1,104 ⟶ 1,123:
}
DisplayWindow
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang Mathematica="mathematica">CreateDocument[]</langsyntaxhighlight>
 
=={{header|mIRC Scripting Language}}==
Line 1,123 ⟶ 1,142:
=={{header|Nanoquery}}==
This program creates and displays a 300x300 window with no contents and the title Nanoquery.
<langsyntaxhighlight Nanoquerylang="nanoquery">w = new(Nanoquery.Util.Windows.Window).setSize(300,300).setTitle("Nanoquery").show()</langsyntaxhighlight>
 
=={{header|NetRexx}}==
{{libheader|Swing}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 1,181 ⟶ 1,200:
method isFalse() public static returns boolean
return \(1 == 1)
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Line 1,187 ⟶ 1,206:
{{libheader|gintro}}
 
<langsyntaxhighlight Nimlang="nim">import gintro/[glib, gobject, gtk, gio]
 
proc activate(app: Application) =
Line 1,198 ⟶ 1,217:
let app = newApplication(Application, "Rosetta.Window")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=== gtk2 ===
This is example 9 from the Araq/Nim github repository (modified to include a quit button)
<langsyntaxhighlight lang="nim">import gdk2, glib2, gtk2
 
const
Line 1,248 ⟶ 1,267:
 
window.show_all()
main()</langsyntaxhighlight>
 
=== SDL ===
<langsyntaxhighlight lang="nim">import
sdl, sdl_image, colors
 
Line 1,298 ⟶ 1,317:
greeting.freeSurface()
screen.freeSurface()
sdl.Quit()</langsyntaxhighlight>
 
=== X11 ===
<langsyntaxhighlight lang="nim">import x11/[xlib, xutil, x]
 
const
Line 1,364 ⟶ 1,383:
while true:
eventloop(windata)
windata.closeWindow()</langsyntaxhighlight>
 
=== glut ===
<langsyntaxhighlight lang="nim">import glut
 
var win: int = 0
Line 1,379 ⟶ 1,398:
win = glutCreateWindow("Goodbye, World!")
glutKeyboardFunc(TGlut1Char2IntCallback(myOnKeyPress))
glutMainLoop()</langsyntaxhighlight>
 
=== win ===
<langsyntaxhighlight lang="nim"># test a Windows GUI application
 
import
Line 1,390 ⟶ 1,409:
# {stdcall, import: "MessageBox", header: "<windows.h>"}
 
discard MessageBox(0, "Hello World!", "Nim GUI Application", 0)</langsyntaxhighlight>
 
=== IUP ===
<langsyntaxhighlight lang="nim">import iup
 
# assumes you have the iup .dll or .so installed
Line 1,416 ⟶ 1,435:
 
discard mainloop()
iup.close()</langsyntaxhighlight>
 
=== wxWidgets ===
This example works on MacOS but should be cross platform and native
<langsyntaxhighlight lang="nim">import wx
 
{.experimental.}
Line 1,437 ⟶ 1,456:
window.show(true)
 
run_main_loop()</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
use Gtk2;
Line 1,455 ⟶ 1,474:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Objective-C}}==
Line 1,464 ⟶ 1,483:
It opens a 800&times;600 window, centered on the screen, with title "A Window".
 
<langsyntaxhighlight lang="objc">#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
 
Line 1,512 ⟶ 1,531:
}
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
=={{header|OCaml}}==
 
{{libheader|LablTk}}
<langsyntaxhighlight lang="ocaml">let () =
let top = Tk.openTk() in
Wm.title_set top "An Empty Window";
Wm.geometry_set top "240x180";
Tk.mainLoop ();
;;</langsyntaxhighlight>
execute with:
ocaml -I +labltk labltk.cma sample.ml
 
with the [http://caml.inria.fr/pub/docs/manual-ocaml/manual039.html Graphics] module:
<langsyntaxhighlight lang="ocaml">open Graphics
let () =
open_graph " 800x600";
let _ = read_line() in
close_graph ()</langsyntaxhighlight>
execute with:
ocaml graphics.cma tmp.ml
 
{{libheader|LablGTK2}}
<langsyntaxhighlight lang="ocaml">open GMain
 
let window = GWindow.window ~border_width:2 ()
Line 1,547 ⟶ 1,566:
button#connect#clicked ~callback:window#destroy;
window#show ();
Main.main ()</langsyntaxhighlight>
execute with:
ocaml -I +lablgtk2 lablgtk.cma gtkInit.cmo sample.ml
 
{{libheader|OCamlSDL}}
<langsyntaxhighlight lang="ocaml">let () =
Sdl.init [`VIDEO];
let _ = Sdlvideo.set_video_mode 200 200 [] in
Sdltimer.delay 2000;
Sdl.quit ()</langsyntaxhighlight>
execute with:
ocaml bigarray.cma -I +sdl sdl.cma sample.ml
 
{{libheader|OCamlSDL2}}
<langsyntaxhighlight lang="ocaml">open Sdl
 
let () =
Line 1,576 ⟶ 1,595:
Render.render_present renderer;
Timer.delay 3000;
Sdl.quit ()</langsyntaxhighlight>
execute with:
ocaml -I +sdl2 sdl2.cma sample.ml
 
{{libheader|ocaml-sfml}}
<langsyntaxhighlight lang="ocaml">let () =
let app = SFRenderWindow.make (640, 480) "OCaml-SFML Windowing" in
Line 1,594 ⟶ 1,613:
if continue then loop ()
in
loop ()</langsyntaxhighlight>
execute with:
ocaml -I /tmp/ocaml-sfml/src sfml_system.cma sfml_window.cma sfml_graphics.cma win.ml
 
{{libheader|OCaml-Xlib}}
<langsyntaxhighlight lang="ocaml">open Xlib
let () =
Line 1,610 ⟶ 1,629:
let _ = xNextEventFun d in (* waits any key-press event *)
xCloseDisplay d;
;;</langsyntaxhighlight>
execute with:
ocaml -I +Xlib Xlib.cma sample.ml
 
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
 
import "vendor:sdl2"
 
main :: proc() {
using sdl2
 
window: ^Window = ---
renderer: ^Renderer = ---
event: Event = ---
 
Init(INIT_VIDEO)
CreateWindowAndRenderer(
640, 480,
WINDOW_SHOWN,
&window, &renderer
)
 
SetWindowTitle(window, "Empty window")
RenderPresent(renderer)
 
for event.type != .QUIT {
Delay(10)
PollEvent(&event)
}
 
DestroyRenderer(renderer)
DestroyWindow(window)
Quit()
}</syntaxhighlight>
 
=={{header|OpenEdge ABL/Progress 4GL}}==
 
<syntaxhighlight lang="openedgeabl">
<lang OpenEdgeABL>
 
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
Line 1,650 ⟶ 1,701:
WAIT-FOR CLOSE OF THIS-PROCEDURE.
</syntaxhighlight>
</lang>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">functor
import
Application
Line 1,670 ⟶ 1,721:
Window = {QTk.build GUIDescription}
{Window show}
end</langsyntaxhighlight>
 
=={{header|Pascal}}==
{{works with|Free_Pascal}}
{{libheader|SysUtils}}{{libheader|SDL}}
<langsyntaxhighlight lang="pascal">Program WindowCreation_SDL;
 
{$linklib SDL}
Line 1,691 ⟶ 1,742:
sleep(2000);
SDL_Quit;
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
Line 1,697 ⟶ 1,748:
 
==={{libheader|Perl/Tk}}===
<langsyntaxhighlight lang="perl"> use Tk;
MainWindow->new();
MainLoop;</langsyntaxhighlight>
 
==={{libheader|Perl/SDL}}===
<langsyntaxhighlight lang="perl"> use SDL::App;
use SDL::Event;
Line 1,709 ⟶ 1,760:
$app->loop({
SDL_QUIT() => sub { exit 0; },
});</langsyntaxhighlight>
 
==={{libheader|Perl/Gtk3}}===
<langsyntaxhighlight lang="perl"> use Gtk3 '-init';
$window = Gtk3::Window->new;
Line 1,719 ⟶ 1,770:
);
$window->show_all;
Gtk3->main;</langsyntaxhighlight>
 
==={{libheader|Perl/Qt}}===
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use QtGui4;
Line 1,729 ⟶ 1,780:
my $window = Qt::MainWindow;
$window->show;
exit $app->exec;</langsyntaxhighlight>
 
==={{libheader|Perl/Wx}}===
<langsyntaxhighlight lang="perl"> use Wx;
$window = Wx::Frame->new(undef, -1, 'title');
$window->Show;
Wx::SimpleApp->new->MainLoop;</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
Works on Windows/Linux, 32/64-bit, and you can run this online [http://phix.x10.mx/p2js/Window_creation.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Window_creation.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</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: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
Line 1,751 ⟶ 1,803:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
{{trans|C}}
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/openGl.l")
 
(glutInit)
(glutCreateWindow "Goodbye, World!")
(keyboardFunc '(() (bye)))
(glutMainLoop)</langsyntaxhighlight>
 
=={{header|PowerShell}}==
{{libheader|WPK}}
<syntaxhighlight lang ="powershell">New-Window -Show</langsyntaxhighlight>
{{libheader|Windows Forms}}
<langsyntaxhighlight lang="powershell">$form = New-Object Windows.Forms.Form
$form.Text = "A Window"
$form.Size = New-Object Drawing.Size(150,150)
$form.ShowDialog() | Out-Null</langsyntaxhighlight>
 
=={{header|Processing}}==
<syntaxhighlight lang="java">
size(1000,1000);
</syntaxhighlight>
 
=={{header|Prolog}}==
Works with SWI-Prolog which has a graphic interface XPCE.
<syntaxhighlight lang Prolog="prolog">?- new(D, window('Prolog Window')), send(D, open).</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Define MyWin.i MyWin, Event.i, x, y
x = 400
y = 300
 
MyWin =If OpenWindow(#PB_Any0, 4120, 1720, 402x, 94y, "I am a window - PureBasic", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, x, y) And StartDrawing(ImageOutput(0))
 
DrawingMode(#PB_2DDrawing_Transparent)
; Event loop
Box(0, 0, x, y, #White)
Repeat
Event For i = WaitWindowEvent()1 To 10
DrawText(x/3, y/2, "Hello World!", #Black)
Select Event
;DrawText(Random(200), Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
Next i
StopDrawing()
ImageGadget(0, 0, 0, x, y, ImageID(0))
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
; Handle any gadget events here
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver</lang>
EndIf</syntaxhighlight>
 
=={{header|Python}}==
Line 1,795 ⟶ 1,864:
 
==={{libheader|Tkinter}}===
<langsyntaxhighlight lang="python"> import Tkinter
w = Tkinter.Tk()
w.mainloop()</langsyntaxhighlight>
 
{{works with|Python|3.7}}
<!-- see also https://stackoverflow.com/questions/673174/which-tkinter-modules-were-renamed-in-python-3 -->
<langsyntaxhighlight lang="python">import tkinter
w = tkinter.Tk()
w.mainloop()</langsyntaxhighlight>
 
==={{libheader|wxPython}}===
<langsyntaxhighlight lang="python"> from wxPython.wx import *
class MyApp(wxApp):
Line 1,818 ⟶ 1,887:
app = MyApp(0)
app.MainLoop()</langsyntaxhighlight>
 
==={{libheader|Pythonwin}}===
<langsyntaxhighlight lang="python"> import win32ui
from pywin.mfc.dialog import Dialog
d = Dialog(win32ui.IDD_SIMPLE_INPUT)
d.CreateWindow()</langsyntaxhighlight>
 
==={{libheader|PyGTK}}===
<langsyntaxhighlight lang="python"> import gtk
window = gtk.Window()
window.show()
gtk.main()</langsyntaxhighlight>
 
==={{libheader|PyQT}}===
<langsyntaxhighlight lang="python"> from PyQt4.QtGui import *
 
app = QApplication([])
Line 1,841 ⟶ 1,910:
win.show()
 
app.exec_()</langsyntaxhighlight>
 
=={{header|R}}==
Although R cannot create windows itself, it has wrappers for several GUI toolkits. tcl/tk is shipped with R by default, and you can create windows with that.
<syntaxhighlight lang="r">
<lang r>
win <- tktoplevel()
</syntaxhighlight>
</lang>
 
{{libheader|gWidgets}}
 
The gWidgets packages let you write GUIs in a toolkit independent way. You can create a window with
<syntaxhighlight lang="r">
<lang r>
library(gWidgetstcltk) #or e.g. gWidgetsRGtk2
win <- gwindow()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket/gui
(send (new frame%
Line 1,865 ⟶ 1,934:
[width 100] [height 100])
show #t)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 1,872 ⟶ 1,941:
 
Exit either by clicking the button or the close window control in the upper corner.
<syntaxhighlight lang="raku" perl6line>use GTK::Simple;
use GTK::Simple::App;
 
Line 1,889 ⟶ 1,958:
$button.clicked.tap: { $app.exit }
 
$app.run;</langsyntaxhighlight>
 
=={{header|RapidQ}}==
Line 1,901 ⟶ 1,970:
=={{header|REBOL}}==
 
<syntaxhighlight lang="rebol">
<lang REBOL>
view layout [size 100x100]
</syntaxhighlight>
</lang>
 
'size' needed to show the close-window button.
Line 1,909 ⟶ 1,978:
=={{header|Red}}==
Empty Window with close [X] button
<langsyntaxhighlight Redlang="red">>>view []
</syntaxhighlight>
</lang>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
Load "guilib.ring"
 
Line 1,922 ⟶ 1,991:
show()}
exec()}
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
Line 1,928 ⟶ 1,997:
 
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby"> require 'tk'
window = TkRoot::new()
window::mainloop()</langsyntaxhighlight>
 
{{libheader|GTK}}
<langsyntaxhighlight lang="ruby"> require 'gtk2'
window = Gtk::Window.new.show
Gtk.main</langsyntaxhighlight>
 
{{libheader|Shoes}}
<syntaxhighlight lang ="ruby">Shoes.app {}</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
Show a empty browser with a button to "Close Me"
<langsyntaxhighlight lang="runbasic">html "Close me!"
button #c, "Close Me", [doExit]
wait
Line 1,960 ⟶ 2,029:
history.go(-a);
</script>"
wait</langsyntaxhighlight>
 
=={{header|Rust}}==
{{libheader|winit}}
<langsyntaxhighlight lang="rust">use winit::event::{Event, WindowEvent}; // winit 0.24
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
Line 1,984 ⟶ 2,053:
}
});
}</langsyntaxhighlight>
 
 
Line 1,990 ⟶ 2,059:
{{libheader|sdljava}}
{{libheader|Scala Java Swing interoperability}}
<langsyntaxhighlight lang="scala">import javax.swing.JFrame
 
object ShowWindow{
Line 2,000 ⟶ 2,069:
jf.setVisible(true)
}
}</langsyntaxhighlight>
 
Using native Scala libraries (which are wrappers over Java libraries):
 
<langsyntaxhighlight lang="scala">import scala.swing._
import scala.swing.Swing._
 
Line 2,012 ⟶ 2,081:
preferredSize = ((800, 600):Dimension)
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
{{libheader|Scheme/PsTk}}
 
<langsyntaxhighlight lang="scheme">
#!r6rs
 
Line 2,030 ⟶ 2,099:
 
(tk-event-loop tk)
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
Line 2,039 ⟶ 2,108:
The program waits until a key is pressed and exits.
 
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
Line 2,048 ⟶ 2,117:
KEYBOARD := GRAPH_KEYBOARD;
ignore(getc(KEYBOARD));
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
===Tk===
<langsyntaxhighlight lang="ruby">var tk = require('Tk');
%s'MainWindow'.new;
tk.MainLoop;</langsyntaxhighlight>
 
===Gtk2===
<langsyntaxhighlight lang="ruby">var gtk2 = require('Gtk2') -> init;
var window = %s'Gtk2::Window'.new;
window.signal_connect(destroy => func(*_) { gtk2.main_quit });
window.show_all;
gtk2.main;</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
{{works with|Pharo}}
{{works with|Squeak}}
<syntaxhighlight lang ="smalltalk">SystemWindow new openInWorld.</langsyntaxhighlight>
 
{{works with|Smalltalk/X}}
<langsyntaxhighlight lang="smalltalk">|top|
top := TopView new.
top add: (Label label: 'Hello World') in:(0.0@0.0 corner:1.0@1.0).
top open</langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML (XWindows/Motif module)
<syntaxhighlight lang="standard ml">
<lang Standard ML>
open XWindows ;
open Motif ;
Line 2,097 ⟶ 2,166:
end;
</syntaxhighlight>
</lang>
call
<syntaxhighlight lang="standard ml">
<lang Standard ML>
showWindow ()
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
{{libheader|Tk}}
Loading the [[Tk]] package is all that is required to get an initial window:
<syntaxhighlight lang ="tcl">package require Tk</langsyntaxhighlight>
If you need an additional window:
<syntaxhighlight lang ="tcl">toplevel .top</langsyntaxhighlight>
If you are using the increasingly popular [http://www.equi4.com/tclkit.html tclkit] under MS Windows, all you have to do is associate the tclkit with the extension “<tt>.tcl</tt>” and then create an <i>empty</i> file with, e.g., with the name <tt>nothing.tcl</tt>. Double-clicking that will “open a window” (an empty one).
 
=={{header|TI-89 BASIC}}==
 
<langsyntaxhighlight lang="ti89b">:Text "Rosetta Code"</langsyntaxhighlight>
 
=={{header|Toka}}==
Line 2,125 ⟶ 2,194:
=={{header|TorqueScript}}==
 
<syntaxhighlight lang="torquescript">
<lang TorqueScript>
new GuiControl(GuiName)
{
Line 2,164 ⟶ 2,233:
 
canvas.pushDialog(GuiName);
</syntaxhighlight>
</lang>
 
=={{header|TXR}}==
Line 2,184 ⟶ 2,253:
Here, we exploit TXR's capability to define enumerations of specific types: we make the event enumeration based on <code>uint8</code>, giving it a <code>typedef</code> name, and then use that <code>typedef</code> in the <code>SD_Event</code> union.
 
<langsyntaxhighlight lang="txrlisp">(defvarl SDL_INIT_VIDEO #x00000020)
(defvarl SDL_SWSURFACE #x00000000)
(defvarl SDL_HWPALETTE #x20000000)
Line 2,217 ⟶ 2,286:
(until* (memql (union-get e 'type) '(SDL_KEYUP SDL_QUIT))
(SDL_WaitEvent e))))
(SDL_Quit))</langsyntaxhighlight>
 
===X11===
Line 2,227 ⟶ 2,296:
Also, this uses an enumeration for the events, so when the event type is decoded from the <code>XEvent</code> union, it comes out as a Lisp symbol.
 
<langsyntaxhighlight lang="txrlisp">(typedef XID uint32)
 
(typedef Window XID)
Line 2,292 ⟶ 2,361:
(KeyPress (return)))))
 
(XCloseDisplay d)))</langsyntaxhighlight>
 
===GTK2===
Line 2,298 ⟶ 2,367:
{{trans|C}}
 
<langsyntaxhighlight lang="txrlisp">(typedef GtkObject* (cptr GtkObject))
(typedef GtkWidget* (cptr GtkWidget))
 
Line 2,328 ⟶ 2,397:
(gtk_signal_connect (GTK_OBJECT window) "destroy" gtk_main_quit nil)
(gtk_widget_show window)
(gtk_main))</langsyntaxhighlight>
 
===Win32/Win64===
Line 2,336 ⟶ 2,405:
Note that the <code>CW_USEDEFAULT</code> constant in the Windows header files is defined as <code>0x80000000</code>. This is out of range of the signed <code>int</code> arguments of <code>CreateWindowEx</code> with which it is used. Microsoft is relying on an implementation-defined C conversion to turn this value into the most negative <code>int</code>. When the original constant was used in the TXR translation, TXR's FFI '''uncovered this little problem''' by throwing an exception arising from the out-of-range conversion attempt. The fix is to specify the correct value directly as <code>#x-80000000</code>.
 
<langsyntaxhighlight lang="txrlisp">(typedef LRESULT int-ptr-t)
(typedef LPARAM int-ptr-t)
(typedef WPARAM uint-ptr-t)
Line 2,465 ⟶ 2,534:
(while (GetMessage msg NULL 0 0)
(TranslateMessage msg)
(DispatchMessage msg))))))</langsyntaxhighlight>
 
=={{header|VBA}}==
Line 2,474 ⟶ 2,543:
And :
Programmatic Access to Visual Basic Project must be trusted. See it in Macro's security!</pre>
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
 
Line 2,482 ⟶ 2,551:
strname = myForm.Name
VBA.UserForms.Add(strname).Show
End Sub</langsyntaxhighlight>
 
=={{header|Vedit macro language}}==
Creates an empty window with ID 'A' near the upper left corner of document area, with height of 20 text lines and width of 80 characters.
<langsyntaxhighlight lang="vedit">Win_Create(A, 2, 5, 20, 80)</langsyntaxhighlight>
Note: if you run this command while in Visual Mode, you should adjust your active window smaller so that the created window will not be hidden behind it (since the active window is always on top).
 
=={{header|Visual Basic .NET}}==
<langsyntaxhighlight lang="vb"> Dim newForm as new Form
newForm.Text = "It's a new window"
newForm.Show()</langsyntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Zig">
import gg
import gx
 
fn main() {
mut app := gg.new_context(
bg_color: gx.white
resizable: true
create_window: true
width: 600
height: 600
frame_fn: frame
window_title: "Empty Window"
)
app.run()
}
 
fn frame(mut ctx gg.Context) {
ctx.begin()
ctx.end()
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
<langsyntaxhighlight ecmascriptlang="wren">import "dome" for Window
 
class EmptyWindow {
Line 2,513 ⟶ 2,606:
}
 
var Game = EmptyWindow.new(600, 600)</langsyntaxhighlight>
 
=={{header|X86 Assembly}}==
{{libheader|GTK}}<br>
{{works with|NASM}}
<langsyntaxhighlight lang="asm">
;GTK imports and defines etc.
%define GTK_WINDOW_TOPLEVEL 0
Line 2,576 ⟶ 2,669:
exit_sig_msg db "-> Rage quitting..",10,0
</syntaxhighlight>
</lang>
<br>
{{works with|MASM}}
<langsyntaxhighlight lang="asm">
.586
.model flat, stdcall
Line 2,655 ⟶ 2,748:
WndProc endp
end start
</syntaxhighlight>
</lang>
 
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">open window 400,200 //minimum line required to accomplish the indicated task
clear screen
text 200,100,"I am a window - close me!","cc"
end</syntaxhighlight>
 
{{omit from|Batch File|No access to GUI functions.}}
{{omit from|EasyLang}}
{{omit from|Logtalk}}
{{omit from|Maxima}}
2,122

edits