Window creation: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 1: Line 1:
{{task}}
[http://people.msoe.edu/~millerni/forums.php?show=topic&id=114&forum=13 meridia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=157&forum=13 free wwe ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=128&forum=13 cheap phentermine] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=158&forum=13 cheap xanax] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=106&forum=13 hydrocodone online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=160&forum=13 cheap zanaflex] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=102&forum=13 free free ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=97&forum=13 buy didrex] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=135&forum=13 free real ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=100&forum=13 buy fioricet] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=96&forum=13 diazepam online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=136&forum=13 cheap rivotril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=87&forum=13 cheap ativan] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=144&forum=13 sonyericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=137&forum=13 sagem ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=152&forum=13 verizon ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=139&forum=13 sharp ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=125&forum=13 cheap ortho] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=156&forum=13 cheap wellbutrin] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=151&forum=13 online valium] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=121&forum=13 nexium online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=147&forum=13 free tracfone ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=142&forum=13 sony ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=94&forum=13 free cool ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=161&forum=13 but zoloft] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=117&forum=13 free motorola ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=133&forum=13 qwest ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=138&forum=13 free samsung ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=122&forum=13 nextel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=89&forum=13 celexa online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=99&forum=13 free ericsson ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=115&forum=13 free midi ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=146&forum=13 tenuate online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=109&forum=13 cheap levitra] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=82&forum=13 adipex online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=132&forum=13 free punk ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=130&forum=13 cheap propecia] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=83&forum=13 albuterol online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=85&forum=13 cheap alprazolam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=153&forum=13 buy viagra] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=148&forum=13 order tramadol] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=143&forum=13 sony ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=86&forum=13 ambien online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=103&forum=13 funny ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=104&forum=13 cheap hgh] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=129&forum=13 polyphonic ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=90&forum=13 cialis online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=123&forum=13 free nokia ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=101&forum=13 cheap flexeril] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=124&forum=13 online norco] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=149&forum=13 cheap ultracet] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=88&forum=13 cheap carisoprodol] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=108&forum=13 kyocera ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=93&forum=13 cheap clonazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=127&forum=13 cheap pharmacy online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=95&forum=13 cyclobenzaprine online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=150&forum=13 cheap ultram] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=111&forum=13 lisinopril online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=159&forum=13 cheap xenical] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=162&forum=13 cheap zyban] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=116&forum=13 mono ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=112&forum=13 buy lorazepam] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=145&forum=13 free sprint ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=110&forum=13 lipitor online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=131&forum=13 prozac online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=120&forum=13 free music ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=105&forum=13 hoodia online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=155&forum=13 online vigrx] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=98&forum=13 cheap diethylpropion] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=113&forum=13 but lortab] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=154&forum=13 cheap vicodin] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=119&forum=13 free mtv ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=84&forum=13 alltel ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=141&forum=13 cheap soma] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=107&forum=13 free jazz ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=140&forum=13 sildenafil online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=126&forum=13 paxil online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=118&forum=13 free mp3 ringtones] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=92&forum=13 clomid online] [http://people.msoe.edu/~millerni/forums.php?show=topic&id=91&forum=13 cingular ringtones] {{task}}


==[[C]]==
==[[C]]==
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
catch( std::exception const & exc )
{
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 06:24, 1 July 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 & exc )
 {
  std::cout << exc.what() << std::endl ;
  exit( -1 ) ;
 }
 
 exit( 0 ) ;
}

C#

Platform: .NET 1.1 (or higher)

Compiler: 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

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

With some example values filled in:

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


Java

Library: 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

   window.open("webpage.html", "windowname", "width=800,height=600");

mIRC Scripting Language

Interpreter: mIRC

Switches: C = Center Window p = Picture Window d = Desktop Window

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

Perl

Interpreter: Perl 5.8.8

Using Tk:

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

Python

Interpreter: Python 2.4, 2.5

Tkinter

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

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

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

PyGTK

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

Ruby

Interpreter: Ruby 1.8.5

Tk

require 'tk'

window = TkRoot::new()
window::mainloop()

GTK

require 'gtk2'

window = Gtk::Window.new.show
Gtk.main

RapidQ

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

Tcl

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 tclkit under MS Windows, all you have to do is associate the tcklkit with the extension ".tcl" and then create an empty file with the name (e.g.) nothing.tcl. Douple-clicking that will "open a window" (an empty one).

Toka

Library: SDL

Toka has partial bindings for the SDL library.

needs sdl
0 SDL_Init
800 600 16 0 SDL_SetVideoMode

Visual Basic .NET

Framework: .NET

   Dim newForm as new Form
   newForm.Text = "It's a new window"
  
       newForm.Show()