[top] [up] [next]

Creating windows


The six steps below demonstrate creating a frame window with a panel window and a button control on the panel window.

0. Including the windows classes

All the classes necessary for Windows programming are in the module 'win.txt'. This file is in the 'modules' directory of 'Trinc-Prolog'. It is necessary that this file is open when a file that wants to create windows is compiled.

This can be done by using the compile directive ensure_loaded/1, this directive ensures that a file is loaded. The advantage of using this compile directive is that relative filepaths to files can be used.

     ensure_loaded('..\\..\\modules\\win.txt').
1. Create a frame window

To create a window there are always two steps:

  1. Create an instance of a class derived from the class window.
  2. With the instance create a window.

The example below creates an instance of the class frame and then tells the frame instance to create a window.

    X new_obj frame,
    X<-create(R),

The window is created invisible. If the window is created successfully then R is unified with the value 'true', else with 'false'. The result of these two lines is an invisible and empty frame window.

2. Resizing and positioning

Then the window is moved to a new position.

    X<-move(point(139, 298), false),

The coordinates are relative to the upper-left corner of the screen, the second parameter is false because the window does not have to redraw itself after it has been moved, the window is still invisible.

Resize the window:

     X<-resize(point(150, 150), false),

The values of the point structure specifies the new width and height of the window. Because the window is still invisible it doesn't have to be be redrawn.

3. Showing the window

The next step is to show the empty frame window to the user.

    X<-show,
    pl_img13.gif (2433 bytes)
4. Panel inside a frame

The frame class has a method to create a single panel window that completely fills the client area:

    X<-createSinglePanel(Panel, true),

The variable Panel is assigned the panel instance that was created and if this was successful then R was unified with the value 'true', else with 'false'.

    pl_img14.gif (2607 bytes)
5. Creating a control

After the panel has been created it is possible to place controls on the panel window:

    B new_obj button,
    B<-create(Panel, true, 10, 10, 100, 24, true)

First a new button instance is created and then the button window is created, the parent window of the control is the Panel window, the next parameter specifies that the button must have a thick border. The following four parameters determine the coordinates of the upper left corner (10, 10), width (100) and height (24) of the button.

The button class is derived from the window class and that class has a method to change the text of a window:

    B<-putText('OK')
    pl_img15.gif (2573 bytes)

The complete Prolog source of the discussed example is:

    X new_obj frame,
    X<-create(R),
    X<-createSinglePanel(Panel, true),
    X<-move(point(139, 298), false),
    X<-resize(point(150, 150), false),
    X<-show,
    B new_obj button,
    B<-create(Panel, true, 10, 10, 100, 24, true),
    B<-putText('OK').

An instance of the button class can also be created by methods of the panel class, the methods addButton/5, addButton/6, addButton/7 and addButton/8 can be used for that.

[top] [up] [next]

 

info@trinc-prolog.com