All Manuals > CAPI User Guide and Reference Manual > 2 Getting Started

NextPrevUpTopContentsIndex

2.2 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.

  1. Enter the following in a listener
(setq interface
      (make-instance 'interface
                     :visible-min-width 200
                     :title "My Interface"))
 
(display interface)

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 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 relative to the topmost/leftmost visible pixel of the primary monitor.

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 - top level windows on how to display CAPI elements in an interface.

Note that a displayed CAPI element should only be accessed in its own thread. See The correct thread for CAPI operations for more information about this.

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

  1. Enter the following into a listener:
(setq button
      (make-instance 'push-button
                     :data "Button"))
 
(contain 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.


CAPI User Guide and Reference Manual (Unix version) - 25 Feb 2015

NextPrevUpTopContentsIndex