Window creation: Difference between revisions
→{{header|PureBasic}}: expanding the task
m (→Tk: code simplification) |
(→{{header|PureBasic}}: expanding the task) |
||
(96 intermediate revisions by 44 users not shown) | |||
Line 6:
{{libheader|GtkAda}}
{{uses from|library|GtkAda|component1=Window|component2=Widget|component3=Handlers|component4=Main}}
<
with Gtk.Widget; use Gtk.Widget;
Line 46:
Gtk.Main.Main;
end Windowed_Application;</
=={{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
<
USE standard
BEGIN
Line 90:
gtk main
END
FINISH</
=={{header|AmigaBASIC}}==
<syntaxhighlight lang="amigabasic">WINDOW 2,"New Window"</syntaxhighlight>
=={{header|AurelBasic}}==
<syntaxhighlight lang="aurelbasic">WIN 0 0 400 300 "New Window"</syntaxhighlight>
=={{header|AutoHotkey}}==
<
Gui, Show</
=={{header|AutoIt}}==
<
GUISetState(@SW_SHOW)
Line 105 ⟶ 114:
Exit
EndSwitch
Until False</
=={{header|
BaCon includes a Highlevel Universal GUI abstraction layer (HUG). The implementation is based on GTK.
<syntaxhighlight lang="freebasic">REM empty window
INCLUDE "hug.bac"
mainwin = WINDOW("Rosetta Code empty", 400, 300)
REM start gtk event loop...
DISPLAY</syntaxhighlight>
=={{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}}
<
dlg% = FN_newdialog("GUI Window", 0, 0, 200, 150, 8, 1000)
PROC_showdialog(dlg%)</
=={{header|C}}==
Line 125 ⟶ 148:
'''Compile Command:''' gcc `sdl-config --cflags` `sdl-config --libs` SDL_Window.c -o window
<
* Opens an 800x600 16bit color window.
* Done here with ANSI C.
Line 146 ⟶ 169:
return 0;
}</
===GTK===
Line 154 ⟶ 177:
'''Compile command:''' gcc `gtk-config --cflags` `gtk-config --libs` -o window window.c
<
int
Line 169 ⟶ 192:
return 0;
}</
===GTK2===
Line 176 ⟶ 199:
'''Compile command:''' gcc -Wall -pedantic `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -o window window.c
<
int
Line 190 ⟶ 213:
return 0;
}</
===GLUT===
Line 202 ⟶ 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.
<
// http://rosettacode.org/wiki/Creating_a_Window
#include <stdlib.h>
Line 243 ⟶ 266:
}
</syntaxhighlight>
=={{header|C sharp|C#}}==
{{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}}
<syntaxhighlight lang="csharp">using System;
using System.Windows.Forms;
public class Window {
[STAThread]
static void Main() {
Form form = new Form();
form.Text = "Window";
form.Disposed += delegate { Application.Exit(); };
form.Show();
Application.Run();
}
}</syntaxhighlight>
=={{header|C++}}==
Line 250 ⟶ 293:
'''Compiler command:''' qmake -pro; qmake
<
#include <QMainWindow>
Line 259 ⟶ 302:
window.show();
return app.exec();
}</
{{libheader|GTK}}
Line 265 ⟶ 308:
'''Compiler command:''' g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`
<
#include <gtkmm.h>
Line 285 ⟶ 328:
exit( 0 ) ;
}</
=={{header|Clojure}}==
Line 311 ⟶ 334:
{{uses from|library|Swing|component1=JFrame}}
<
(let [frame (JFrame. "A Window")]
(doto frame
(.setSize 600 800)
(.setVisible true)))</
=={{header|Common Lisp}}==
Line 324 ⟶ 347:
{{works with|LispWorks}}
<
==={{libheader|CLIM}}===
Line 332 ⟶ 355:
Setting up the environment:
<
(cl:defpackage #:rc-window
(:use #:clim-lisp #:clim))
(cl:in-package #:rc-window)</
The actual definition and display:
<
()
(:layouts (:default)))
(run-frame-top-level (make-application-frame 'rc-window))</
Note: This creates a small, useless window ("frame"). Useful frames will have some ''panes'' defined inside them.
Line 351 ⟶ 374:
Works with the Armed Bear Common Lisp implementation that targets the JVM.
<
"Creates a window"
(let ((window (jnew (jconstructor "javax.swing.JFrame"))))
Line 357 ⟶ 380:
window (make-immediate-object t :boolean))))
(create-window)</
=={{header|D}}==
{{libheader|FLTK4d}}
<
import fltk4d.all;
Line 369 ⟶ 392:
window.show;
FLTK.run;
}</
{{libheader|Derelict}}
{{libheader|SDL}}
<
int main(char[][] args)
Line 404 ⟶ 427:
return 0;
}</
{{libheader|QD}}
QD is a simple and easy-to-use wrapper around SDL.
<
void main() {
screen(640, 480);
while (true) events();
}</
=={{header|Delphi}}==
Line 420 ⟶ 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">
// The project file (Project1.dpr)
Line 479 ⟶ 501:
end
</syntaxhighlight>
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">
program Project3;
Line 547 ⟶ 569:
end.
</syntaxhighlight>
=={{header|Dragon}}==
{{libheader|GUI}}
<syntaxhighlight lang="dragon">select "GUI"
window = newWindow("Window")
window.setSize(400,600)
window.setVisible()
</syntaxhighlight>
=={{header|E}}==
Line 566 ⟶ 598:
Platform independent EiffelVision 2 Library
<
APPLICATION
inherit
Line 584 ⟶ 616:
first_window: MAIN_WINDOW
-- Main window.
end</
<
MAIN_WINDOW
inherit
Line 636 ⟶ 668:
main_container_created: main_container /= Void
end
end</
{{libheader|Windows Forms}}
<
APPLICATION
inherit
Line 658 ⟶ 690:
{WINFORMS_APPLICATION}.run_form (Current)
end
end</
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(make-frame)</syntaxhighlight>
=={{header|Euphoria}}==
===ARWEN===
{{libheader|ARWEN}}
<
constant win = create(Window, "ARWEN window", 0, 0,100,100,640,480,{0,0})
WinMain(win, SW_NORMAL)
</syntaxhighlight>
===EuGTK===
{{libheader|EuGTK}}
<
constant win = create(GtkWindow,"title=EuGTK Window;size=640x480;border=10;$destroy=Quit")
show_all(win)
main()</
===EuWinGUI===
{{libheader|EuWinGUI}}
<
Window("EuWinGUI window",100,100,640,480)
Line 699 ⟶ 725:
end while
CloseApp(0)</
===Win32Lib===
{{libheader|Win32Lib}}
<
constant win = createEx( Window, "Win32Lib", 0, Default, Default, 640, 480, 0, 0 )
WinMain( win, Normal )</
===wxEuphoria===
{{libheader|wxEuphoria}}
<
constant win = create( wxFrame, {0, -1, "wxEuphoria window", -1, -1, 640, 480} )
wxMain( win )</
=={{header|F_Sharp|F#}}==
Everything is provided by the .NET runtime so this is almost identical to [[C_sharp]].
{{libheader|Windows Forms}}
<syntaxhighlight lang="fsharp"> open System.Windows.Forms
[<System.STAThread>]
do
Form(Text = "F# Window")
|> Application.Run</syntaxhighlight>
=={{header|Factor}}==
<
"This is a window..." <label> "Really?" open-window</
=={{header|Fantom}}==
<
using fwt
Line 733 ⟶ 770:
}
}
</syntaxhighlight>
=={{header|Forth}}==
Line 740 ⟶ 777:
'''gtk-server command:''' gtk-server -fifo=ffl-fifo &
<
\ Open the connection to the gtk-server and load the Gtk2 definitions
Line 772 ⟶ 809:
gsv+close drop
[THEN]</
===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">
#Include "windows.bi"
Dim As HWND Window_Main
Dim As MSG msg
'Create the window:
Window_Main = CreateWindow("#32770", "I am a window - close me!", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 350, 200, 0, 0, 0, 0)
'Windows message loop:
While GetMessage(@msg, Window_Main, 0, 0)
TranslateMessage(@msg)
DispatchMessage(@msg)
If msg.hwnd = Window_Main And msg.message = WM_COMMAND Then End
Wend
End
</syntaxhighlight>
=={{header|Frink}}==
<
g=(new graphics).show[]
</syntaxhighlight>
=={{header|
<syntaxhighlight lang="futurebasic">window 1</syntaxhighlight>
=={{header|Gambas}}==
<syntaxhighlight lang="gambas">Public Sub Form_Open()
End</syntaxhighlight>
=={{header|Go}}==
===GTK===
{{libheader|go-gtk}}
<
import
"github.com/mattn/go-gtk/glib"
"github.com/mattn/go-gtk/gtk"
)
func main() {
gtk.Init(nil)
window := gtk.
window.Connect("destroy",
func(*glib.CallbackContext) { gtk.MainQuit() }, "")
window.Show()
gtk.Main()
}</
===SDL===
{{libheader|Go-SDL}}
<
import (
"
"github.com/veandco/go-sdl2/sdl"
)
func main() {
window, err := sdl.CreateWindow("RC Window Creation",
if err != nil {
log.Fatal(err)
}
if _, ok := sdl.WaitEvent().(*sdl.QuitEvent); ok {
}
window.Destroy()
}</syntaxhighlight>
===X11===
<
import (
Line 852 ⟶ 922:
}
}
}</
=={{header|Groovy}}==
Line 865 ⟶ 935:
We will open notepad as a window here.
<syntaxhighlight lang
To close the window:
<syntaxhighlight lang
=={{header|Haskell}}==
Line 875 ⟶ 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.
<
aWindow = runGraphics $
withWindow_ "Rosetta Code task: Creating a window" (300, 200) $ \ w -> do
drawInWindow w $ text (100, 100) "Hello World"
getKey w</
=={{header|HicEst}}==
<
! window units: as pixels < 0, as relative window size 0...1, ascurrent character sizes > 1
WRITE(WINdowhandle=handle) '... some output ...'</
=={{header|IDL}}==
Line 897 ⟶ 967:
Icon and Unicon windowing is portable between Windows and X-Windows environments.
==={{header|Icon}}===
<
procedure main(arglist)
Line 903 ⟶ 973:
WOpen("size=300, 300", "fg=blue", "bg=light gray")
WDone()
end</
{{libheader|Icon Programming Library}}
Line 911 ⟶ 981:
The Icon solution works in Unicon. An Unicon-only version is as follows:
<
import gui
$include "guih.icn"
Line 929 ⟶ 999:
w.show_modal ()
end
</syntaxhighlight>
=={{header|J}}==
A minimalist modal dialog:
<syntaxhighlight lang="j"> wdinfo 'Hamlet';'To be, or not to be: that is the question:'</syntaxhighlight>
A free-standing window:
<
pc minwdw;
pas 162 85;pcenter;
)
Line 953 ⟶ 1,020:
)
minwdw_run ''</
=={{header|Java}}==
{{libheader|Swing}}
<
public class Main {
Line 966 ⟶ 1,033:
w.setVisible(true);
}
}</
=={{header|JavaScript}}==
window.open("webpage.html", "windowname", "width=800,height=600");
=={{header|Julia}}==
<syntaxhighlight lang="julia"># v0.6
using Tk
w = Toplevel("Example")</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|Java}}
<
fun main(args : Array<String>) {
setSize(800, 600)
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
}
}</syntaxhighlight>
=={{header|Liberty BASIC}}==
Minimum code required to fulfill the task.
<syntaxhighlight lang="lb">nomainwin
open "GUI Window" for window as #1
wait
</syntaxhighlight>
As it would properly be used in a real program.
<syntaxhighlight lang="lb">nomainwin
open "GUI Window" for window as #1
#1 "trapclose Quit"
wait
sub Quit hndl$
close #hndl$
end
end sub
</syntaxhighlight>
=={{header|Lingo}}==
<syntaxhighlight lang="lingo">win = window().new("New Window")
w = 320
h = 240
firstScreen = _system.deskTopRectList[1]
x = firstScreen.width/2 - w/2
y = firstScreen.height/2- h/2
win.rect = rect(x,y,x+w,y+h)
-- Director needs a binary movie file (*.dir) for opening new windows. But this
-- movie file can be totally empty, and if it's write protected in the filesystem,
-- it can be re-used for multiple windows.
win.filename = _movie.path & "empty.dir"
win.open()</syntaxhighlight>
=={{header|Lua}}==
{{libheader|IUPLua}}
<
iup.dialog{
Line 996 ⟶ 1,102:
iup.MainLoop()
</syntaxhighlight>
=={{header|
Window has title by default the name of variable, here MyForm
Window by default has 6000 twips width by 4000 twips height
Here we open MyForm as modal window (with 1 as first parameter, after "Show")
Window show a square in left side of title (we can change this to be at right), so this close the window (if we have proper event function, we can quit the closing). Also using key combination Alt-F4 close window too (also send event).
Window open in the monitor where we see the mouse pointer.
M2000 Windows have own decoration, independent from platform (same to Xp, Windows 7, Windows 8, Windows 10 and Linux using Wine).
<syntaxhighlight lang="m2000 interpreter">
Module DisplayWindow {
Declare MyForm Form
Method MyForm,"Show",1
}
DisplayWindow
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">CreateDocument[]</syntaxhighlight>
=={{header|mIRC Scripting Language}}==
Line 1,031 ⟶ 1,139:
.window -Cp +d @WindowName 600 480
}
=={{header|Nanoquery}}==
This program creates and displays a 300x300 window with no contents and the title Nanoquery.
<syntaxhighlight lang="nanoquery">w = new(Nanoquery.Util.Windows.Window).setSize(300,300).setTitle("Nanoquery").show()</syntaxhighlight>
=={{header|NetRexx}}==
{{libheader|Swing}}
<
options replace format comments java crossref symbols binary
Line 1,088 ⟶ 1,200:
method isFalse() public static returns boolean
return \(1 == 1)
</syntaxhighlight>
=={{header|Nim}}==
=== gtk3 / gintro ===
{{libheader|gintro}}
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio]
proc activate(app: Application) =
## Activate the application.
let window = newApplicationWindow(app)
window.setTitle("Window for Rosetta")
window.setSizeRequest(640, 480)
window.showAll()
let app = newApplication(Application, "Rosetta.Window")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
=== gtk2 ===
This is example 9 from the Araq/Nim github repository (modified to include a quit button)
<
const
Inside
OutSide
# Context transmitted to callback.
type Context = object
label: PLabel
overButton: bool
proc changeLabel(p: PWidget; event: gdk2.PEventCrossing; context: var Context) {.cdecl.} =
context.label.set_text(if context.overButton: OutSide else: Inside)
context.overButton = not context.overButton
proc thisDestroy(widget: PWidget, data: Pgpointer) {.cdecl.} =
main_quit()
var context: Context
nim_init()
let window = window_new(gtk2.WINDOW_TOPLEVEL)
let stackbox = vbox_new(true, 10)
let button1 = button_new("Move mouse over button")
let buttonstyle = copy(button1.get_style())
buttonstyle.bg[STATE_PRELIGHT] = TColor(pixel: 0, red: 255, green: 0, blue: 0)
button1.set_style(buttonstyle)
let button2 = button_new()
context = Context(label: label_new(Outside), overButton: false)
let button3 = button_new("Quit")
button2.add(context.label)
stackbox.pack_start(button1, true, true, 0)
stackbox.pack_start(button2, true, true, 0)
stackbox.pack_start(button3, true, true, 0)
window.set_border_width(5)
window.add(stackbox)
discard window.signal_connect("destroy", SIGNAL_FUNC(thisDestroy), nil)
discard button1.signal_connect("enter_notify_event", SIGNAL_FUNC(changeLabel), addr(context))
discard button1.signal_connect("leave_notify_event", SIGNAL_FUNC(changeLabel), addr(context))
discard button3.signal_connect("clicked", SIGNAL_FUNC(thisDestroy), nil)
window.show_all()
main()</syntaxhighlight>
=== SDL ===
<
sdl, sdl_image, colors
Line 1,194 ⟶ 1,317:
greeting.freeSurface()
screen.freeSurface()
sdl.Quit()</
=== X11 ===
<syntaxhighlight lang
const
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 300
type WindowData = tuple[display: PDisplay; window: Window]
proc createWindow: WindowData =
let width: cuint = WINDOW_WIDTH
let height: cuint = WINDOW_HEIGHT
var sizeHints: XSizeHints
let display = XOpenDisplay(nil)
if display == nil:
echo
quit
let screen = XDefaultScreen(display)
var rootwin = XRootWindow(display, screen)
let win = XCreateSimpleWindow(display, rootwin, 100, 10, width, height, 5,
sizeHints.flags = PSize or PMinSize or PMaxSize
sizeHints.min_width = width.cint
sizeHints.max_width = width.cint
discard XSetStandardProperties(
display, win, "Simple Window", "window", 0, nil, 0, addr(sizeHints))
discard
discard XMapWindow(display, win)
result = (display, win)
proc closeWindow(data: WindowData) =
discard XDestroyWindow(data.display,
discard XCloseDisplay(data.display)
proc processEvent(xev: var XEvent) =
var key:
case
of KeyPress:
key = XLookupKeysym(cast[ptr
if key.int != 0:
echo
if key.int == 65307: # <Esc>
quit
of ButtonPressMask, PointerMotionMask:
else:
discard
proc eventloop(data: WindowData) =
var xev: XEvent
var numEvents = XPending(data.display).int
while numEvents != 0:
dec numEvents
discard XNextEvent(data.display, addr(xev))
processEvent(xev)
let windata = createWindow()
while true:
eventloop(windata)
windata.closeWindow()</syntaxhighlight>
=== glut ===
<
var win: int = 0
Line 1,285 ⟶ 1,398:
win = glutCreateWindow("Goodbye, World!")
glutKeyboardFunc(TGlut1Char2IntCallback(myOnKeyPress))
glutMainLoop()</
=== win ===
<
import
Line 1,296 ⟶ 1,409:
# {stdcall, import: "MessageBox", header: "<windows.h>"}
discard MessageBox(0, "Hello World!", "Nim GUI Application", 0)</
=== IUP ===
<
# assumes you have the iup .dll or .so installed
Line 1,307 ⟶ 1,420:
# now use a Dialog box to show a message
var lbl =
setAttribute(lbl,"PADDING","10x10")
var contents =
#SetAttribute(contents, "MARGIN", "5x5")
var dlg =
#SetAttribute(dlg, "SIZE", "100x50")
Line 1,322 ⟶ 1,435:
discard mainloop()
iup.
=== wxWidgets ===
This example works on MacOS but should be cross platform and native
<syntaxhighlight lang="nim">import wx
{.experimental.}
const
TITLE = "Rosetta Code - Window Creation Nim"
WIDTH = 300
HEIGHT = 300
let
POSITION = construct_wxPoint(100,100)
SIZE = construct_wxSize(WIDTH,HEIGHT)
let window = cnew construct_wxFrame(nil, wxID_ANY, TITLE, POSITION, SIZE)
window.show(true)
run_main_loop()</syntaxhighlight>
=={{header|Objeck}}==
<
use Gtk2;
Line 1,340 ⟶ 1,474:
}
}
</syntaxhighlight>
=={{header|Objective-C}}==
Line 1,349 ⟶ 1,483:
It opens a 800×600 window, centered on the screen, with title "A Window".
<
#include <AppKit/AppKit.h>
Line 1,397 ⟶ 1,531:
}
return EXIT_SUCCESS;
}</
=={{header|OCaml}}==
{{libheader|LablTk}}
<
let top = Tk.openTk() in
Wm.title_set top "An Empty Window";
Wm.geometry_set top "240x180";
Tk.mainLoop ();
;;</
execute with:
ocaml -I +labltk labltk.cma sample.ml
with the [http://caml.inria.fr/pub/docs/manual-ocaml/manual039.html Graphics] module:
<
let () =
open_graph " 800x600";
let _ = read_line() in
close_graph ()</
execute with:
ocaml graphics.cma tmp.ml
{{libheader|LablGTK2}}
<
let window = GWindow.window ~border_width:2 ()
Line 1,432 ⟶ 1,566:
button#connect#clicked ~callback:window#destroy;
window#show ();
Main.main ()</
execute with:
ocaml -I +lablgtk2 lablgtk.cma gtkInit.cmo sample.ml
{{libheader|OCamlSDL}}
<
Sdl.init [`VIDEO];
let _ = Sdlvideo.set_video_mode 200 200 [] in
Sdltimer.delay 2000;
Sdl.quit ()</
execute with:
ocaml bigarray.cma -I +sdl sdl.cma sample.ml
{{libheader|OCamlSDL2}}
<syntaxhighlight lang="ocaml">open Sdl
let () =
let width, height = (640, 480) in
Sdl.init [`VIDEO];
let window, renderer =
Render.create_window_and_renderer
~width ~height ~flags:[]
in
let rgb = (0, 255, 0) in
let a = 255 in
Render.set_draw_color renderer rgb a;
Render.clear renderer;
Render.render_present renderer;
Timer.delay 3000;
Sdl.quit ()</syntaxhighlight>
execute with:
ocaml -I +sdl2 sdl2.cma sample.ml
{{libheader|ocaml-sfml}}
<
let app = SFRenderWindow.make (640, 480) "OCaml-SFML Windowing" in
let rec loop () =
let continue =
match SFRenderWindow.
| Some SFEvent.Closed -> false
| _ -> true
Line 1,457 ⟶ 1,611:
SFRenderWindow.clear app SFColor.black;
SFRenderWindow.display app;
if continue then loop ()
in
loop ()</
execute with:
ocaml
{{libheader|OCaml-Xlib}}
<
let () =
Line 1,475 ⟶ 1,629:
let _ = xNextEventFun d in (* waits any key-press event *)
xCloseDisplay d;
;;</
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">
DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
Line 1,516 ⟶ 1,701:
WAIT-FOR CLOSE OF THIS-PROCEDURE.
</syntaxhighlight>
=={{header|Oz}}==
<
import
Application
Line 1,536 ⟶ 1,721:
Window = {QTk.build GUIDescription}
{Window show}
end</
=={{header|Pascal}}==
{{works with|Free_Pascal}}
{{libheader|SysUtils}}{{libheader|SDL}}
<
{$linklib SDL}
Line 1,557 ⟶ 1,742:
sleep(2000);
SDL_Quit;
end.</
=={{header|Perl}}==
Line 1,563 ⟶ 1,748:
==={{libheader|Perl/Tk}}===
<
MainWindow->new();
MainLoop;</
==={{libheader|Perl/SDL}}===
<
use SDL::Event;
Line 1,575 ⟶ 1,760:
$app->loop({
SDL_QUIT() => sub { exit 0; },
});</
==={{libheader|Perl/
<
$window =
$window->signal_connect(
destroy => sub {
);
$window->show_all;
==={{libheader|Perl/Qt}}===
<
use warnings;
use QtGui4;
Line 1,605 ⟶ 1,780:
my $window = Qt::MainWindow;
$window->show;
exit $app->exec;</
==={{libheader|Perl/Wx}}===
<
$window = Wx::Frame->new(undef, -1, 'title');
$window->Show;
Wx::SimpleApp->new->MainLoop;</
=={{header|
{{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].
<!--<syntaxhighlight lang="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>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"hello"</span><span style="color: #0000FF;">)},</span><span style="color: #008000;">"MARGIN=200x200"</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"TITLE=Hello"</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
{{trans|C}}
<
(glutInit)
(glutCreateWindow "Goodbye, World!")
(keyboardFunc '(() (bye)))
(glutMainLoop)</
=={{header|PowerShell}}==
{{libheader|WPK}}
<syntaxhighlight lang
{{libheader|Windows Forms}}
<
$form.Text = "A Window"
$form.Size = New-Object Drawing.Size(150,150)
$form.ShowDialog() | Out-Null</
=={{header|Processing}}==
<syntaxhighlight lang="java">
size(1000,1000);
</syntaxhighlight>
=={{header|Prolog}}==
Works with SWI-Prolog which has a graphic interface XPCE.
<syntaxhighlight lang
=={{header|PureBasic}}==
<
x = 400
y = 300
If CreateImage(0, x, y) And StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0, 0, x, y, #White)
DrawText(x/3, y/2, "Hello World!", #Black)
;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
Case #PB_Event_CloseWindow
EndSelect
ForEver
EndIf</syntaxhighlight>
=={{header|Python}}==
{{works with|Python|2.4 and 2.5}}
==={{libheader|Tkinter}}===
<
w = Tkinter.Tk()
w.mainloop()</
{{works with|Python|3.7}}
<!-- see also https://stackoverflow.com/questions/673174/which-tkinter-modules-were-renamed-in-python-3 -->
<syntaxhighlight lang="python">import tkinter
w = tkinter.Tk()
w.mainloop()</syntaxhighlight>
==={{libheader|wxPython}}===
<
class MyApp(wxApp):
Line 1,698 ⟶ 1,887:
app = MyApp(0)
app.MainLoop()</
==={{libheader|Pythonwin}}===
<
from pywin.mfc.dialog import Dialog
d = Dialog(win32ui.IDD_SIMPLE_INPUT)
d.CreateWindow()</
==={{libheader|PyGTK}}===
<
window = gtk.Window()
window.show()
gtk.main()</
==={{libheader|PyQT}}===
<
app = QApplication([])
Line 1,721 ⟶ 1,910:
win.show()
app.exec_()</
=={{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">
win <- tktoplevel()
</syntaxhighlight>
{{libheader|gWidgets}}
The gWidgets packages let you write GUIs in a toolkit independent way. You can create a window with
<syntaxhighlight lang="r">
library(gWidgetstcltk) #or e.g. gWidgetsRGtk2
win <- gwindow()
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket/gui
(send (new frame%
Line 1,745 ⟶ 1,934:
[width 100] [height 100])
show #t)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<b>Library</b> [https://github.com/perl6/gtk-simple GTK]
Exit either by clicking the button or the close window control in the upper corner.
<syntaxhighlight lang="raku" line>use GTK::Simple;
use GTK::Simple::App;
my GTK::Simple::App $app .= new(title => 'Simple GTK Window');
$app.size-request(250, 100);
$app.set-content(
GTK::Simple::VBox.new(
my $button = GTK::Simple::Button.new(label => 'Exit'),
)
);
$app.border-width = 40;
$button.clicked.tap: { $app.exit }
$app.run;</syntaxhighlight>
=={{header|RapidQ}}==
Line 1,757 ⟶ 1,970:
=={{header|REBOL}}==
<syntaxhighlight lang="rebol">
view layout [size 100x100]
</syntaxhighlight>
'size' needed to show the close-window button.
=={{header|Red}}==
Empty Window with close [X] button
<syntaxhighlight lang="red">>>view []
</syntaxhighlight>
=={{header|Ring}}==
<syntaxhighlight lang="ring">
Load "guilib.ring"
MyApp = New qApp {
win1 = new qWidget() {
setwindowtitle("Hello World")
setGeometry(100,100,370,250)
show()}
exec()}
</syntaxhighlight>
=={{header|Ruby}}==
Line 1,767 ⟶ 1,997:
{{libheader|Ruby/Tk}}
<
window = TkRoot::new()
window::mainloop()</
{{libheader|GTK}}
<
window = Gtk::Window.new.show
Gtk.main</
{{libheader|Shoes}}
<syntaxhighlight lang
=={{header|Run BASIC}}==
Show a empty browser with a button to "Close Me"
<
button #c, "Close Me", [doExit]
wait
Line 1,799 ⟶ 2,029:
history.go(-a);
</script>"
wait</
=={{header|
{{libheader|
<syntaxhighlight lang="rust">use winit::event::{Event, WindowEvent}; // winit 0.24
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
fn main() {
let event_loop = EventLoop::new();
let _win = WindowBuilder::new()
.with_title("Window")
.build(&event_loop).unwrap();
event_loop.run(move |ev, _, flow| {
match ev {
Event::WindowEvent {
event: WindowEvent::CloseRequested, ..
} => {
*flow = ControlFlow::Exit;
}
_ => {}
}
});
}</syntaxhighlight>
=={{header|Scala}}==
{{libheader|sdljava}}
{{libheader|Scala Java Swing interoperability}}
<syntaxhighlight lang="scala">import javax.swing.JFrame
object ShowWindow{
Line 1,831 ⟶ 2,069:
jf.setVisible(true)
}
}</
Using native Scala libraries (which are wrappers over Java libraries):
<
import scala.swing.Swing._
Line 1,843 ⟶ 2,081:
preferredSize = ((800, 600):Dimension)
}
}</
=={{header|Scheme}}==
{{libheader|Scheme/PsTk}}
<syntaxhighlight lang="scheme">
#!r6rs
;; PS-TK example: display simple frame
(import (rnrs)
(lib pstk main) ; change this to refer to your installation of PS/Tk
)
(define tk (tk-start))
(tk/wm 'title tk "PS-Tk Example: Frame")
(tk-event-loop tk)
</syntaxhighlight>
=={{header|Seed7}}==
Line 1,852 ⟶ 2,108:
The program waits until a key is pressed and exits.
<
include "draw.s7i";
include "keybd.s7i";
Line 1,861 ⟶ 2,117:
KEYBOARD := GRAPH_KEYBOARD;
ignore(getc(KEYBOARD));
end func;</
=={{header|Sidef}}==
===Tk===
<
%s'MainWindow'.new;
tk.MainLoop;</
===Gtk2===
<
var window = %s'Gtk2::Window'.new;
window.signal_connect(destroy => func(*_) { gtk2.main_quit });
window.show_all;
gtk2.main;</
=={{header|Smalltalk}}==
{{works with|Pharo}}
{{works with|Squeak}}
<syntaxhighlight lang
{{works with|Smalltalk/X}}
<
top := TopView new.
top add: (Label label: 'Hello World') in:(0.0@0.0 corner:1.0@1.0).
top open</
=={{header|Standard ML}}==
Works with PolyML (XWindows/Motif module)
<syntaxhighlight lang="standard ml">
open XWindows ;
open Motif ;
val showWindow = fn () =>
let
val shell = XtAppInitialise "" "demo" "top" [] [XmNwidth 400, XmNheight 300 ] ;
val main = XmCreateMainWindow shell "main" [XmNmappedWhenManaged true ] ;
val buttn = XmCreateDrawnButton main "stop" [ XmNlabelString "Exit"] ;
val quit = fn (w,c,t) => (XtUnrealizeWidget shell; t) ;
in
(
XtSetCallbacks buttn [ (XmNactivateCallback, quit) ] XmNarmCallback ;
XtManageChildren [buttn];
XtManageChild main;
XtRealizeWidget shell
)
end;
</syntaxhighlight>
call
<syntaxhighlight lang="standard ml">
showWindow ()
</syntaxhighlight>
=={{header|Tcl}}==
{{libheader|Tk}}
Loading the [[Tk]] package is all that is required to get an initial window:
<syntaxhighlight lang
If you need an additional window:
<syntaxhighlight lang
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}}==
<
=={{header|Toka}}==
Line 1,909 ⟶ 2,194:
=={{header|TorqueScript}}==
<syntaxhighlight lang="torquescript">
new GuiControl(GuiName)
{
Line 1,948 ⟶ 2,233:
canvas.pushDialog(GuiName);
</syntaxhighlight>
=={{header|TXR}}==
TXR has no library module for connecting to SDL, X11's Xlib, or GTK2.
All of these examples are completely self-contained, using the FFI capability in TXR, which can bind to any library whose interface is defined in terms of C functions and types.
No C header file is processed, and not a single line of C has to be compiled.
===SDL===
{{trans|C}}
A wait for a SDL key-up event is added, missing in the C version, so that the window does not just appear and disappear.
Note that SDL's header file uses a <code>enum</code> for the event constants like <code>SDL_KEYUP</code>. But then in <code>union SD_Event</code>, the event field declared as <code>UInt8</code>. (That's how it appears on my Ubuntu system; newer versions of SDL seems to have switched the type field, and other fields of the event structures, to <code>UInt32</code>.)
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.
<syntaxhighlight lang="txrlisp">(defvarl SDL_INIT_VIDEO #x00000020)
(defvarl SDL_SWSURFACE #x00000000)
(defvarl SDL_HWPALETTE #x20000000)
(typedef SDL_Surface (cptr SDL_Surface))
(typedef SDL_EventType (enumed uint8 SDL_EventType
(SDL_KEYUP 3)
(SDL_QUIT 12)))
(typedef SDL_Event (union SD_Event
(type SDL_EventType)
(pad (array 8 uint32))))
(with-dyn-lib "libSDL.so"
(deffi SDL_Init "SDL_Init" int (uint32))
(deffi SDL_SetVideoMode "SDL_SetVideoMode"
SDL_Surface (int int int uint32))
(deffi SDL_GetError "SDL_GetError" str ())
(deffi SDL_WaitEvent "SDL_WaitEvent" int ((ptr-out SDL_Event)))
(deffi SDL_Quit "SDL_Quit" void ()))
(when (neql 0 (SDL_Init SDL_INIT_VIDEO))
(put-string `unable to initialize SDL: @(SDL_GetError)`)
(exit nil))
(unwind-protect
(progn
(SDL_SetVideoMode 800 600 16 (logior SDL_SWSURFACE SDL_HWPALETTE))
(let ((e (make-union (ffi SDL_Event))))
(until* (memql (union-get e 'type) '(SDL_KEYUP SDL_QUIT))
(SDL_WaitEvent e))))
(SDL_Quit))</syntaxhighlight>
===X11===
{{trans|C}}
One difference between the C original and this one is that the XLib macros for direct structure access, like <code>DefaultGC</code>, <code>DefaultScreen</code> or <code>WhitePixel</code> are not used; rather the correspoding C functions are used via FFI: <code>XDefaultScreen</code> and so on. The macro approach can be mimiced in detail, at the cost of a significant increase in verbosity (cloning the full declaration of the <code>_XDisplay</code> struct declaration, and reproducing the macros).
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.
<syntaxhighlight lang="txrlisp">(typedef XID uint32)
(typedef Window XID)
(typedef Drawable XID)
(typedef Display (cptr Display))
(typedef GC (cptr GC))
(typedef XEventType (enum _XEventType
(KeyPress 2)
(Expose 12)))
(defvarl KeyPressMask (ash 1 0))
(defvarl ExposureMask (ash 1 15))
(typedef XEvent (union _XEvent
(type XEventType)
(pad (array 24 long))))
(defvarl NULL cptr-null)
(with-dyn-lib "libX11.so"
(deffi XOpenDisplay "XOpenDisplay" Display (bstr))
(deffi XCloseDisplay "XCloseDisplay" int (Display))
(deffi XDefaultScreen "XDefaultScreen" int (Display))
(deffi XRootWindow "XRootWindow" Window (Display int))
(deffi XBlackPixel "XBlackPixel" ulong (Display int))
(deffi XWhitePixel "XWhitePixel" ulong (Display int))
(deffi XCreateSimpleWindow "XCreateSimpleWindow" Window (Display
Window
int int
uint uint uint
ulong ulong))
(deffi XSelectInput "XSelectInput" int (Display Window long))
(deffi XMapWindow "XMapWindow" int (Display Window))
(deffi XNextEvent "XNextEvent" int (Display (ptr-out XEvent)))
(deffi XDefaultGC "XDefaultGC" GC (Display int))
(deffi XFillRectangle "XFillRectangle" int (Display Drawable GC
int int uint uint))
(deffi XDrawString "XDrawString" int (Display Drawable GC
int int bstr int)))
(let* ((msg "Hello, world!")
(d (XOpenDisplay nil)))
(when (equal d NULL)
(put-line "Cannot-open-display" *stderr*)
(exit 1))
(let* ((s (XDefaultScreen d))
(w (XCreateSimpleWindow d (XRootWindow d s) 10 10 100 100 1
(XBlackPixel d s) (XWhitePixel d s))))
(XSelectInput d w (logior ExposureMask KeyPressMask))
(XMapWindow d w)
(while t
(let ((e (make-union (ffi XEvent))))
(XNextEvent d e)
(caseq (union-get e 'type)
(Expose
(XFillRectangle d w (XDefaultGC d s) 20 20 10 10)
(XDrawString d w (XDefaultGC d s) 10 50 msg (length msg)))
(KeyPress (return)))))
(XCloseDisplay d)))</syntaxhighlight>
===GTK2===
{{trans|C}}
<syntaxhighlight lang="txrlisp">(typedef GtkObject* (cptr GtkObject))
(typedef GtkWidget* (cptr GtkWidget))
(typedef GtkWidget* (cptr GtkWidget))
(typedef GtkWindowType (enum GtkWindowType
GTK_WINDOW_TOPLEVEL
GTK_WINDOW_POPUP))
(with-dyn-lib "libgtk-x11-2.0.so.0"
(deffi gtk_init "gtk_init" void ((ptr int) (ptr (ptr (zarray str)))))
(deffi gtk_window_new "gtk_window_new" GtkWidget* (GtkWindowType))
(deffi gtk_signal_connect_full "gtk_signal_connect_full"
ulong (GtkObject* str closure closure val closure int int))
(deffi gtk_widget_show "gtk_widget_show" void (GtkWidget*))
(deffi gtk_main "gtk_main" void ())
(deffi-sym gtk_main_quit "gtk_main_quit"))
(defmacro GTK_OBJECT (cptr)
^(cptr-cast 'GtkObject ,cptr))
(defmacro gtk_signal_connect (object name func func-data)
^(gtk_signal_connect_full ,object ,name ,func cptr-null
,func-data cptr-null 0 0))
(gtk_init (length *args*) (vec-list *args*))
(let ((window (gtk_window_new 'GTK_WINDOW_TOPLEVEL)))
(gtk_signal_connect (GTK_OBJECT window) "destroy" gtk_main_quit nil)
(gtk_widget_show window)
(gtk_main))</syntaxhighlight>
===Win32/Win64===
This solution is based on the "Your First Windows Program" example in MSDN. It registers a Window class, creates a Window and runs a Windows message loop against a custom <code>WndProc</code> function that is written in Lisp, which handles <code>WM_QUIT</code> and <code>WM_PAINT</code> events exactly like its C counterpart. All necessary basic types, structures, constants and foreign functions are declared using the TXR FFI language.
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>.
<syntaxhighlight lang="txrlisp">(typedef LRESULT int-ptr-t)
(typedef LPARAM int-ptr-t)
(typedef WPARAM uint-ptr-t)
(typedef UINT uint32)
(typedef LONG int32)
(typedef WORD uint16)
(typedef DWORD uint32)
(typedef LPVOID cptr)
(typedef BOOL (bool int32))
(typedef BYTE uint8)
(typedef HWND (cptr HWND))
(typedef HINSTANCE (cptr HINSTANCE))
(typedef HICON (cptr HICON))
(typedef HCURSOR (cptr HCURSOR))
(typedef HBRUSH (cptr HBRUSH))
(typedef HMENU (cptr HMENU))
(typedef HDC (cptr HDC))
(typedef ATOM WORD)
(typedef LPCTSTR wstr)
(defvarl NULL cptr-null)
(typedef WNDCLASS (struct WNDCLASS
(style UINT)
(lpfnWndProc closure)
(cbClsExtra int)
(cbWndExtra int)
(hInstance HINSTANCE)
(hIcon HICON)
(hCursor HCURSOR)
(hbrBackground HBRUSH)
(lpszMenuName LPCTSTR)
(lpszClassName LPCTSTR)))
(defmeth WNDCLASS :init (me)
(zero-fill (ffi WNDCLASS) me))
(typedef POINT (struct POINT
(x LONG)
(y LONG)))
(typedef MSG (struct MSG
(hwnd HWND)
(message UINT)
(wParam WPARAM)
(lParam LPARAM)
(time DWORD)
(pt POINT)))
(typedef RECT (struct RECT
(left LONG)
(top LONG)
(right LONG)
(bottom LONG)))
(typedef PAINTSTRUCT (struct PAINTSTRUCT
(hdc HDC)
(fErase BOOL)
(rcPaint RECT)
(fRestore BOOL)
(fIncUpdate BOOL)
(rgbReserved (array 32 BYTE))))
(defvarl CW_USEDEFAULT #x-80000000)
(defvarl WS_OVERLAPPEDWINDOW #x00cf0000)
(defvarl SW_SHOWDEFAULT 5)
(defvarl WM_DESTROY 2)
(defvarl WM_PAINT 15)
(defvarl COLOR_WINDOW 5)
(deffi-cb wndproc-fn LRESULT (HWND UINT LPARAM WPARAM))
(with-dyn-lib "kernel32.dll"
(deffi GetModuleHandle "GetModuleHandleW" HINSTANCE (wstr)))
(with-dyn-lib "user32.dll"
(deffi RegisterClass "RegisterClassW" ATOM ((ptr-in WNDCLASS)))
(deffi CreateWindowEx "CreateWindowExW" HWND (DWORD
LPCTSTR LPCTSTR
DWORD
int int int int
HWND HMENU HINSTANCE
LPVOID))
(deffi ShowWindow "ShowWindow" BOOL (HWND int))
(deffi GetMessage "GetMessageW" BOOL ((ptr-out MSG) HWND UINT UINT))
(deffi TranslateMessage "TranslateMessage" BOOL ((ptr-in MSG)))
(deffi DispatchMessage "DispatchMessageW" LRESULT ((ptr-in MSG)))
(deffi PostQuitMessage "PostQuitMessage" void (int))
(deffi DefWindowProc "DefWindowProcW" LRESULT (HWND UINT LPARAM WPARAM))
(deffi BeginPaint "BeginPaint" HDC (HWND (ptr-out PAINTSTRUCT)))
(deffi EndPaint "EndPaint" BOOL (HWND (ptr-in PAINTSTRUCT)))
(deffi FillRect "FillRect" int (HDC (ptr-in RECT) HBRUSH)))
(defun WindowProc (hwnd uMsg wParam lParam)
(caseql* uMsg
(WM_DESTROY
(PostQuitMessage 0)
0)
(WM_PAINT
(let* ((ps (new PAINTSTRUCT))
(hdc (BeginPaint hwnd ps)))
(FillRect hdc ps.rcPaint (cptr-int (succ COLOR_WINDOW) 'HBRUSH))
(EndPaint hwnd ps)
0))
(t (DefWindowProc hwnd uMsg wParam lParam))))
(let* ((hInstance (GetModuleHandle nil))
(wc (new WNDCLASS
lpfnWndProc [wndproc-fn WindowProc]
hInstance hInstance
lpszClassName "Sample Window Class")))
(RegisterClass wc)
(let ((hwnd (CreateWindowEx 0 wc.lpszClassName "Learn to Program Windows"
WS_OVERLAPPEDWINDOW
CW_USEDEFAULT CW_USEDEFAULT
CW_USEDEFAULT CW_USEDEFAULT
NULL NULL hInstance NULL)))
(unless (equal hwnd NULL)
(ShowWindow hwnd SW_SHOWDEFAULT)
(let ((msg (new MSG)))
(while (GetMessage msg NULL 0 0)
(TranslateMessage msg)
(DispatchMessage msg))))))</syntaxhighlight>
=={{header|VBA}}==
<pre>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Need to reference the following object library (From the Tools menu, choose References)
Microsoft Forms 2.0 Object Library
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
And :
Programmatic Access to Visual Basic Project must be trusted. See it in Macro's security!</pre>
<syntaxhighlight lang="vb">
Option Explicit
Sub InsertForm()
Dim myForm As Object, strname As String
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)
strname = myForm.Name
VBA.UserForms.Add(strname).Show
End Sub</syntaxhighlight>
=={{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.
<
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}}==
<
newForm.Text = "It's a new window"
newForm.Show()</
=={{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}}
<syntaxhighlight lang="wren">import "dome" for Window
class EmptyWindow {
construct new(width, height) {
Window.title = "Empty window"
Window.resize(width, height)
}
init() {}
update() {}
draw(alpha) {}
}
var Game = EmptyWindow.new(600, 600)</syntaxhighlight>
=={{header|X86 Assembly}}==
{{libheader|GTK}}<br>
{{works with|NASM}}
<
;GTK imports and defines etc.
%define GTK_WINDOW_TOPLEVEL 0
Line 2,027 ⟶ 2,669:
exit_sig_msg db "-> Rage quitting..",10,0
</syntaxhighlight>
<br>
{{works with|MASM}}
<
.586
.model flat, stdcall
Line 2,106 ⟶ 2,748:
WndProc endp
end start
</syntaxhighlight>
=={{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}}
{{omit from|PARI/GP}}
{{omit from|PHP|PHP cannot create windows by itself}}
{{omit from|PostScript}}
{{omit from|Retro}}
{{omit from|SQL PL|It does not handle GUI}}
{{omit from|TI-83 BASIC|Doesn't run in a windowed interface}}
{{omit from|Unlambda|No access to GUI functions.}}
|