Window creation: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 35: Line 35:
}
}


==[[C plus plus|C++]]==
==[[C plus plus|C ]]==
[[Category:C plus plus]]
[[Category:C plus plus]]
===[[Qt]] 4===
===[[Qt]] 4===
Line 58: Line 58:
[[Category:Gtk]]
[[Category:Gtk]]


'''Compiler command:''' g++ filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`
'''Compiler command:''' g filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`


#include <iostream>
#include <iostream>
Line 73: Line 73:
}
}
catch( std::exception const & exc )
catch( std::exception const
{
std::cout << exc.what() << std::endl ;
exit( -1 ) ;
}
exit( 0 ) ;
}

==[[C sharp|C#]]==
[[Category:C sharp]]
'''Platform:''' [[.NET]] 1.1 (or higher)

'''Compiler:''' [[Visual C sharp|Visual C#]] 2003

'''Using:''' [[System.Windows.Forms.dll]]

using System;
using System.Windows.Forms;
public class Window
{
[STAThread]
static void Main()
{
Form newForm = new Form();
newForm.Text = "It's a new Window!";
newForm.Show();
}
}

==[[E]]==
[[Category:E]]

===Java AWT/Swing===

'''Implementation:''' E-on-Java

when (currentVat.morphInto("awt")) -> {
def w := <swing:makeJFrame>("Window")
w.setContentPane(<swing:makeJLabel>("Contents"))
w.pack()
w.show()
}

==[[IDL]]==
[[Category:IDL]]

With some example values filled in:

Id = WIDGET_BASE(TITLE='Window Title',xsize=200,ysize=100)
WIDGET_CONTROL, /REALIZE, id


==[[Java]]==
[[Category:Java]]

'''Library:''' [[Swing]]

[[Category:Swing]]

import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class SimpleWindow {
public static void main(String[] args) {
JFrame window = new JFrame("This is a title!");
window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
window.setSize(800, 600);
window.setVisible(true);
}
}

==[[JavaScript]]==
[[Category:JavaScript]]
window.open("webpage.html", "windowname", "width=800,height=600");

==[[mIRC Scripting Language]]==
[[Category:mIRC Scripting Language]]

'''Interpreter:''' [[mIRC]]
'''Switches:'''
C = Center Window
p = Picture Window
d = Desktop Window

alias CreateMyWindow {
.window -Cp +d @WindowName 600 480
}

==[[Perl]]==
[[Category:Perl]]

'''Interpreter:''' [[Perl]] 5.8.8

Using [[Tk]]:

use Tk;
$mw = MainWindow->new();
MainLoop;

==[[Python]]==
[[Category:Python]]

'''Interpreter:''' [[Python]] 2.4, 2.5

===[[Tkinter]]===

[[Category:Tkinter]]

import Tkinter
w = tkinter.Tk()
w.mainloop()

===[[wxPython]]===

[[Category:wxPython]]

from wxPython.wx import *
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "Hello from wxPython")
frame.Show(true)
self.SetTopWindow(frame)
return true
app = MyApp(0)
app.MainLoop()

===[[Pythonwin]]===

[[Category:Pythonwin]]

import win32ui
from pywin.mfc.dialog import Dialog
d = Dialog(win32ui.IDD_SIMPLE_INPUT)
d.CreateWindow()

===[[PyGTK]]===

[[Category:PyGTK]]

import gtk
window = gtk.Window()
window.show()
gtk.main()

==[[Ruby]]==
[[Category:Ruby]]

'''Interpreter:''' [[Ruby]] 1.8.5

===[[Tk]]===

[[Category:Tk]]

require 'tk'
window = TkRoot::new()
window::mainloop()

===[[GTK]]===
require 'gtk2'
window = Gtk::Window.new.show
Gtk.main

==[[RapidQ]]==
[[Category:RapidQ]]

create form as qform
center
width=500
height=400
end create
form.showModal

==[[Tcl]]==
[[Category:Tk]]

Loading the "Tk" package is all that is required to get an initial window:

package require Tk

If you need an additional window:

toplevel .top

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 tcklkit with the extension ".tcl" and then create an <i>empty</i> file with the name (e.g.) <tt>nothing.tcl</tt>. Douple-clicking that will "open a window" (an empty one).

==[[Toka]]==
[[Category:Toka]]

'''Library:''' [[SDL]]
[[Category:SDL]]

Toka has partial bindings for the [[SDL]] library.

needs sdl
0 SDL_Init
800 600 16 0 SDL_SetVideoMode

==[[Visual Basic .NET]]==
[[Category:Visual Basic .NET]]

Framework: [[.NET]]
Dim newForm as new Form
newForm.Text = "It's a new window"
newForm.Show()

Revision as of 15:57, 22 June 2007

Task
Window creation
You are encouraged to solve this task according to the task description, using any language you may know.

C

Standard: ANSI C (AKA C89):

Compiler: GCC 4.0.3

Library: SDL

Compile Command: gcc -lSDL SDL_Window.c -o window

/*
 *   Opens an 800x600 16bit color window. 
 *   Done here with ANSI C.
 */

#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"

main(){

SDL_Surface *screen;

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
  return(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode( 800, 600, 16, SDL_SWSURFACE | SDL_HWPALETTE );
}

C

Qt 4

Compiler command: qmake -pro; qmake

#include <QApplication>
#include <QMainWindow>

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 QMainWindow window;
 window.show();
 return app.exec();
}

Gtk

Compiler command: g filename.cc -o test `pkg-config --cflags --libs gtkmm-2.4`

#include <iostream>
#include <gtkmm.h>

int
main( int argc, char* argv[] )
{
 try
 {
  Gtk::Main m( argc, argv ) ;
  Gtk::Window win ;
  m.run( win ) ;
 }
 
 catch( std::exception const