This section shows how easy it is to create a simple window, and how to include CAPI elements, such as panes, in your window.
(make-instance 'interface
:title "My Interface")
(display *)
Figure 2.1 Creating a simple window
A small window appears on your screen, called "My interface" consisting of a menu bar with the Works menu. This is the most simple type of window that can be created with the CAPI. The Works menu gives you access to a variety of LispWorks tools, just like the Works menu of any other LispWorks window. It is automatically provided by LispWorks for any interface you create.
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.
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 some of the brief interactive examples in this manual pass :process nil
to contain
or display
. The interface is then displayed in the Listener's execution process and can safely be modifed in that same process. In contrast, the demo example in is modified only by callbacks which run in the demo interface's own process, and so it is not displayed using :process nil
. In general, real applications would not pass :process nil
.
This is how you can create and display a button using contain
.
(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.