Hello world/Grafici
Wikibooks, manuali e libri di testo liberi.
Di seguito sono illustrati esempi di Hello world eseguiti su interfaccie grafiche.
[modifica] AppleScript
display dialog "hello, world"
[modifica] AutoIt v3
MsgBox(0, "hello, world", "hello, world")
[modifica] C per GTK+
#include <gtk/gtk.h> void hello(GtkWidget* widget, gpointer data) { g_print("Hello, World!\n"); } int main(int argc, char** argv) { GtkWidget* window; GtkWidget* button; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width(GTK_CONTAINER(window), 10); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); button = gtk_button_new_with_label("Hello, World!"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(hello), NULL); gtk_container_add(GTK_CONTAINER(window), button); gtk_widget_show(window); gtk_widget_show(button); gtk_main(); return 0; }
[modifica] C++ per FOX
#include "fx.h" int main(int argc,char **argv) { FXApp app("MyApp","Me"); app.init(argc,argv); app.create(); FXMessageBox::information(&app,MBOX_OK,"Message","hello, world"); return app.run(); }
[modifica] C++ per GTK+
#include <iostream> #include <gtkmm/main.h> #include <gtkmm/button.h> #include <gtkmm/window.h> using namespace std; class HelloWorld : public Gtk::Window { public: HelloWorld(); virtual ~HelloWorld(); protected: Gtk::Button m_button; virtual void on_button_clicked(); }; HelloWorld::HelloWorld() : m_button("hello, world") { set_border_width(10); m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked)); add(m_button); m_button.show(); } HelloWorld::~HelloWorld() {} void HelloWorld::on_button_clicked() { cout << "hello, world" << endl; } int main (int argc, char *argv[]) { Gtk::Main kit(argc, argv); HelloWorld HelloWorld; Gtk::Main::run(HelloWorld); return 0; }
[modifica] C++ con Qt
#include <qapplication.h> #include <qpushbutton.h> int main( int argc, char **argv ) { QApplication a( argc, argv ); QPushButton Hello( "hello, world", 0 ); Hello.resize( 100, 30 ); a.setMainWidget( &Hello ); Hello.show(); return a.exec(); }
--
[modifica] C#
Versione con una MessageBox:
namespace Hello_World { using System; using System.Windows.Forms; public class HelloWorld { public static void Main() { MesssageBox.Show("Hello, World!"); } } }
Versione con una finestra generica:
namespace Hello_World { using System; using System.Windows.Forms; public class HelloWorld : Form { public static void Main() { Application.Run(new HelloWorld()); } public HelloWorld() { this.Text = "Hello World !" ; } } }
[modifica] Clarion
program
window WINDOW('Hello World'),AT(,,300,200),STATUS,SYSTEM,GRAY,DOUBLE,AUTO
END
code
open(window)
show(10,10,'Hello World')
accept
end
close(window)
[modifica] Delphi
program HelloWorld; uses Dialogs; begin ShowMessage('hello, world'); end.
[modifica] Free Pascal
program UnSaludo; {$mode objfpc}{$H+} uses Interfaces, Forms; begin application.MessageBox('Hola mundo', '', 0) ; end.
[modifica] EASY
Nella Variante VDP:
module helloworld
procedure Main
Message("hello, world")
endproc
o pure
edit1.text:='Hello World';
[modifica] Gambas
PUBLIC SUB Form_Open()
Message.Info("hello, world")
END
[modifica] Java
- AWT:
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class HelloWorldFenster extends Frame {
public HelloWorldFenster() {
super("hello, world");
Label HelloWorldLabel = new Label("hello, world");
add(HelloWorldLabel);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setResizable(false);
setLocation(350, 320);
setSize(160, 60);
setVisible(true);
}
public static void main(String[] args) {
new HelloWorldFenster();
}
}
import javax.swing.JFrame;
import javax.swing.JLabel;
public class HelloWorld extends JFrame {
public HelloWorld() {
super("hello, world");
JLabel HelloWorldLabel = new JLabel("hello, world");
getContentPane().add(HelloWorldLabel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
setLocation(350, 320);
setSize(160, 60);
setVisible(true);
}
public static void main(String[] args) {
new HelloWorld();
}
}
[modifica] LISP
(alert "hello, world")
[modifica] PureBasic
MessageRequester("","Hello World")
[modifica] R
plot.new() text(x = 0.5, y = 0.5, labels = "hello, world")
[modifica] R, library tcltk
library(tcltk) tt <- tktoplevel() label.widget <- tklabel(tt, text="Hello, World!") tkpack(label.widget)
[modifica] Tcl/Tk
label .label1 -text "Hello World" pack .label1
Versione corta:
pack [label .label1 -text "Hello World"]
[modifica] Turbo Pascal 7.0 (con Turbo Vision), per DOS
Versione con MessageBox
program Hello;
uses App, MsgBox;
type
THelloApplication = object(TApplication)
constructor Init;
procedure DoAboutBox;
end;
constructor THelloApplication.Init;
begin
inherited Init;
DoAboutBox;
end;
procedure THelloApplication.DoAboutBox;
var
Res: Word;
begin
Res := MessageBox('hello, world', nil, mfInformation);
end;
var
HelloApplication: THelloApplication;
begin
HelloApplication.Init;
HelloApplication.Run;
HelloApplication.Done;
end.
Versione con Window ed ereditarietà.
program Hello;
uses App, Dialogs, Objects, Views;
type
PHelloWindow = ^THelloWindow;
THelloWindow = object(TWindow)
constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
end;
THelloApplication = object(TApplication)
constructor Init;
end;
constructor THelloWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
var
R: TRect;
begin
inherited Init(Bounds, ATitle, ANumber);
R.Assign(2, 2, 37, 3);
Insert(New(PStaticText, Init(R, 'hello, world')));
end;
constructor THelloApplication.Init;
var
R: TRect;
begin
inherited Init;
R.Assign(3, 3, 50, 14);
InsertWindow(New(PHelloWindow, Init(R, 'Hello world program', 1)));
end;
var
HelloApplication: THelloApplication;
begin
HelloApplication.Init;
HelloApplication.Run;
HelloApplication.Done;
end.
[modifica] Visual Basic .Net
MessageBox.Show("hello, world")
[modifica] Visual Basic
MsgBox "hello, world"
[modifica] Waba / SuperWaba
import waba.ui.*; import waba.fx.*; public class HelloWorld extends MainWindow { public void onPaint(Graphics g) { g.setColor(0, 0, 0); g.drawText("hello, world", 0, 0); } }
[modifica] Windows API (in Borland Pascal)
program Hello;
uses WinTypes, WinProcs;
const
szClassName = 'PASCLASS32';
function WndProc(Window: HWnd; Message, WParam: Word;
LParam: Longint): Longint; export;
var
LPPaint : TPaintStruct;
TheDC : HDC;
begin
WndProc := 0;
case Message of
wm_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
wm_Paint:
begin
TheDC := BeginPaint(Window, LPPaint);
TextOut(TheDC, 5, 5, 'hello, world', 12);
end;
end;
WndProc := DefWindowProc(Window, Message, WParam, LParam);
end;
procedure WinMain;
var
Window: HWnd;
Message: TMsg;
const
WindowClass: TWndClass = (
style: 0;
lpfnWndProc: @WndProc;
cbClsExtra: 0;
cbWndExtra: 0;
hInstance: 0;
hIcon: 0;
hCursor: 0;
hbrBackground: 0;
lpszMenuName: szClassName;
lpszClassName: szClassName);
begin
if HPrevInst = 0 then
begin
WindowClass.hInstance := HInstance;
WindowClass.hIcon := LoadIcon(0, idi_Application);
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground := GetStockObject(white_Brush);
if not RegisterClass(WindowClass) then
Halt(255);
end;
Window := CreateWindow(
szClassName,
'Win32 Pascal Program',
ws_OverlappedWindow,
cw_UseDefault,
cw_UseDefault,
cw_UseDefault,
cw_UseDefault,
0,
0,
HInstance,
nil);
ShowWindow(Window, CmdShow);
UpdateWindow(Window);
while GetMessage(Message, 0, 0, 0) do
begin
TranslateMessage(Message);
DispatchMessage(Message);
end;
Halt(Message.wParam);
end;
begin
WinMain;
end.
[modifica] Windows API (in Borland Turbo Assembler)
.386
LOCALS
JUMPS
.model FLAT, STDCALL
INCLUDE WIN32.INC
L EQU <LARGE>
EXTRN BeginPaint:PROC
EXTRN CreateWindowExA:PROC
EXTRN DefWindowProcA:PROC
EXTRN DispatchMessageA:PROC
EXTRN EndPaint:PROC
EXTRN ExitProcess:PROC
EXTRN FindWindowA:PROC
EXTRN GetMessageA:PROC
EXTRN GetModuleHandleA:PROC
EXTRN GetStockObject:PROC
EXTRN InvalidateRect:PROC
EXTRN LoadCursorA:PROC
EXTRN LoadIconA:PROC
EXTRN MessageBeep:PROC
EXTRN MessageBoxA:PROC
EXTRN PostQuitMessage:PROC
EXTRN RegisterClassA:PROC
EXTRN ShowWindow:PROC
EXTRN SetWindowPos:PROC
EXTRN TextOutA:PROC
EXTRN TranslateMessage:PROC
EXTRN UpdateWindow:PROC
CreateWindowEx EQU <CreateWindowExA>
DefWindowProc EQU <DefWindowProcA>
DispatchMessage EQU <DispatchMessageA>
FindWindow EQU <FindWindowA>
GetMessage EQU <GetMessageA>
GetModuleHandle EQU <GetModuleHandleA>
LoadCursor EQU <LoadCursorA>
LoadIcon EQU <LoadIconA>
MessageBox EQU <MessageBoxA>
RegisterClass EQU <RegisterClassA>
TextOut EQU <TextOutA>
.data
NewHWND DD 0
lpPaint PAINTSTRUCT <?>
Msg MSGSTRUCT <?>
wc WNDCLASS <?>
hInst DD 0
szTitleName DB "Win32 Assembly Program"
Zero DB 0
szAlternate DB "(Secondary)", 0
szClassName DB "ASMCLASS32", 0
szHello DB "hello, world", 0
HelloLength EQU ($ - OFFSET szHello) - 1
.code
Begin:
PUSH L 0
CALL GetModuleHandle
MOV [hInst], EAX
PUSH L 0
PUSH OFFSET szClassName
CALL FindWindow
OR EAX, EAX
JZ RegClass
MOV [Zero], ' '
RegClass:
MOV [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
MOV [wc.clsLpfnWndProc], OFFSET WndProc
MOV [wc.clsCbClsExtra], 0
MOV [wc.clsCbWndExtra], 0
MOV EAX, [hInst]
MOV [wc.clsHInstance], EAX
PUSH L IDI_APPLICATION
PUSH L 0
CALL LoadIcon
MOV [wc.clsHIcon], EAX
PUSH L IDC_ARROW
PUSH L 0
CALL LoadCursor
MOV [wc.clsHCursor], EAX
MOV [wc.clsHbrBackground], COLOR_WINDOW + 1
MOV DWORD PTR [wc.clsLpszMenuName], 0
MOV DWORD PTR [wc.clsLpszClassName], OFFSET szClassName
PUSH OFFSET wc
CALL RegisterClass
PUSH L 0 ; lpParam
PUSH [hInst] ; hInstance
PUSH L 0 ; menu
PUSH L 0 ; parent hwnd
PUSH L CW_USEDEFAULT ; height
PUSH L CW_USEDEFAULT ; width
PUSH L CW_USEDEFAULT ; y
PUSH L CW_USEDEFAULT ; x
PUSH L WS_OVERLAPPEDWINDOW ; Style
PUSH OFFSET szTitleName ; Title string
PUSH OFFSET szClassName ; Class name
PUSH L 0 ; extra style
CALL CreateWindowEx
MOV [NewHWND], EAX
PUSH L SW_SHOWNORMAL
PUSH [NewHWND]
CALL ShowWindow
PUSH [NewHWND]
CALL UpdateWindow
MsgLoop:
PUSH L 0
PUSH L 0
PUSH L 0
PUSH OFFSET Msg
CALL GetMessage
CMP AX, 0
JE EndLoop
PUSH OFFSET Msg
CALL TranslateMessage
PUSH OFFSET Msg
CALL DispatchMessage
JMP MsgLoop
EndLoop:
PUSH [Msg.msWPARAM]
CALL ExitProcess
WndProc PROC USES EBX EDI ESI, hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
LOCAL TheDC:DWORD
CMP [wmsg], WM_DESTROY
JE wmDestroy
CMP [wmsg], WM_RBUTTONDOWN
JE wmRButtonDown
CMP [wmsg], WM_SIZE
JE wmSize
CMP [wmsg], WM_CREATE
JE wmCreate
CMP [wmsg], WM_LBUTTONDOWN
JE wmLButtonDown
CMP [wmsg], WM_PAINT
JE wmPaint
CMP [wmsg], WM_GETMINMAXINFO
JE wmGetMinMaxInfo
JMP DefWndProc
wmPaint:
PUSH OFFSET lpPaint
PUSH [hwnd]
CALL BeginPaint
MOV [TheDC], EAX
PUSH L HelloLength ; lunghezza stringa
PUSH OFFSET szHello ; stringa
PUSH L 5 ; y
PUSH L 5 ; x
PUSH [TheDC] ; DC
CALL TextOut
PUSH OFFSET lpPaint
PUSH [hwnd]
CALL EndPaint
MOV EAX, 0
JMP Finish
wmCreate:
MOV EAX, 0
JMP Finish
DefWndProc:
PUSH [lparam]
PUSH [wparam]
PUSH [wmsg]
PUSH [hwnd]
CALL DefWindowProc
JMP Finish
wmDestroy:
PUSH L 0
CALL PostQuitMessage
MOV EAX, 0
JMP Finish
wmLButtonDown:
PUSH L 0
PUSH L 0
PUSH [hwnd]
CALL InvalidateRect ; ridisegna finestra
MOV EAX, 0
JMP Finish
wmRButtonDown:
PUSH L 0
CALL MessageBeep
JMP Finish
wmSize:
MOV EAX, 0
JMP Finish
wmGetMinMaxInfo:
MOV EBX, [lparam] ; ptr a minmaxinfo struct
MOV [(MINMAXINFO PTR ebx).mintrackposition_x], 350
MOV [(MINMAXINFO PTR ebx).mintrackposition_y], 60
MOV EAX, 0
JMP Finish
Finish:
RET
WndProc ENDP
PUBLIC WndProc
ENDS
END Begin
; creare questo file HELLO.DEF:
NAME HELLO
DESCRIPTION 'Assembly Win32 Program'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
EXETYPE WINDOWS
HEAPSIZE 8192
STACKSIZE 8192
EXPORTS WndProc
; fine HELLO.DEF
[modifica] Windows API (in C)
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "CCLASS32";
HINSTANCE hInstance;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wincl;
hInstance = hInst;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.style = 0;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpszMenuName = NULL; //No menu
wincl.lpfnWndProc = WindowProcedure;
wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //Color of the window
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //EXE icon
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Small program icon
wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor
if (!RegisterClassEx(&wincl))
return 0;
hwnd = CreateWindowEx(0, //No extended window styles
szClassName, //Class name
"Win32 C Program", //Window caption
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, //Let Windows decide the left and top positions of the window
120, 50, //Width and height of the window,
NULL, NULL, hInstance, NULL);
//Make the window visible on the screen
ShowWindow(hwnd, nCmdShow);
//Run the message loop
BOOL bRet;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 15, 3, "hello, world", 13);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
[modifica] X Window
xmessage hello, world!
[modifica] Zenity
zenity --info --text='hello, world'