2.3 Creating a window

This section shows how easy it is to create a simple window, and how to include CAPI elements, such as panes, in your window.

Enter the following in a listener

(make-instance 'interface

:visible-min-width 200

:title "My Interface")

(display *)

Figure 2.1 Creating a simple window

A small window appears on your screen, called "My Interface". This is the most simple type of window that can be created with the CAPI.

Note: By default this window has a menu bar with the
Works
menu. The
Works menu gives you access to a variety of LispWorks tools, just like the
Works
menu of any window in the Common LispWorks IDE. It is automatically provided by default for any interface you create. You can omit it by passing
:auto-menus
nil
.

The usual way to display an instance of a CAPI window is
display. However, another function,
contain
, is provided to help you during the course of development.

Notice that the "My Interface" window cannot be made smaller than the minimum width specified. All CAPI geometry values (window size and position) are integers and represent pixel values.

Only a top level CAPI element is shown by
display -- that is, an instance of an
interface
. To display other CAPI elements (for example, buttons, editor panes, and so on), you must provide information about how they are to be arranged in the window. Such an arrangement is called a
layout
-- you will learn more about layouts in Laying Out CAPI Panes.

On the other hand,
contain
automatically provides a default layout for any CAPI element you specify, and subsequently displays it. During development, it can be useful for displaying individual elements of interest on your screen, without having to create an interface for them explicitly. However,
contain
is only provided as a development tool, and should not be used for the final implementation of a CAPI element. See Defining Interface Classes on how to display CAPI elements in an interface.

A displayed CAPI element should only be modified in its own thread (that is,
mp:process
). This is why the brief interactive examples in this manual generally use
execute-with-interface or
apply-in-pane-process when modifying a displayed CAPI element. In contrast, the demo example in Connecting an interface to an application is modified only by callbacks which run in the demo interface's own process, and so there is no need to use
execute-with-interface
or
apply-in-pane-process
.

This is how you can create and display a button using
contain.

Enter the following into a listener:

(make-instance 'push-button

:data "Button")

(contain *)

Figure 2.2 Creating a push-button interface

This creates an interface which contains a single push-button, with a label specified by the
:data keyword. Notice that you could have performed the same example using
display
, but you would also have had to create a layout so that the button could have been placed in an interface and displayed.

You can click on the button, and it will respond in the way you would expect (it will depress). However, no code will be run which performs an action associated with the button. How to link code to window items is the topic of the next section.