2 Getting Started
(make-instance 'interface :title "My Interface")
Figure 2.1 Creating a simple window
A small window appears on your screen, consisting of a menu bar with two menus, labelled Works and Help. 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 displaying 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 Chapter 5.
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 Chapter 7, "Defining Interface Classes" on how to display CAPI elements in an interface.
This is how you can create and display a button using
(make-instance 'push-button :data "Button")
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.
Generated with Harlequin WebMaker