Using MUI in Blitz

Magic User Inteface (MUI) is a system developed to take the hard work out of designing a GUI for your application, leaving you to concentrate on the application itself. Nearly all aspects of an MUI interface can be customised by the user. The programmer mearly has to define the interface, and leave MUI to the task of controlling layout etc.

That's not to say that it's easy to use as a developer. In fact, MUI is like a programming environment itself, and during development it is easy to introduce conflicts between objects which will undoubtedly crash your system. It is important, therefore, to back up regularly whilst designing an MUI interface.

The basic system itself is object oriented, where each element of the GUI has its' own identification number, and each object can be set to react to user input in a variety of ways. In fact, it is possible to create an application using MUI almost exclusively, where all actions in the code become automatic depending upon what the user is doing. This, however, is beyond the scope of this tutorial, and should, in any event, only be tackled by advanced users.

The interface between Blitz and MUI is achieved using EFMUILib, which provides a limited number of commands. This does not mean, however, that use of MUI within your application is limited. The system can be used to its' fullest, and even new additions to MUI can be supported without updating the Blitz libraries.

Before you start, you should download the MUI developer archive. The autodocs within the archive are essential, though example code is aimed at C users, and is of limited value.

All examples in this tutorial will use standard MUI classes, but the principals for using custom classes are the same, and I will, of course, tell you how to access and use a custom class. Each time you install a new custom class, be sure to copy the autodocs too.

So, let's start with a small example, which will introduce you to initialising an MUI interface, and notification. If you run this small program, it will simply open an MUI window, and wait for you to close it again. Before you start, you will need to open the Compiler Options window in Blitz and add in the residents box "blitzlibs:mui.res" (without the quotes). If you have installed the MUI2.res, you can use that instead. You can find the mui2.res file as part of the EFMUILib.

OK, done that? Good, then we'll begin.

Code ; First, do a little bit of Blitz housekeeping
Findscreen 0 ; We need an intuition screen to open our window on. This simply uses the frontmost

; Now we'll set up a procedure to initialise the MUI window.

Statement setmui{}

MUIApplicationTitle "Lesson1" ;Sets the MUI application name
MUIApplicationVersion "$VER: Lesson 1" ; Sets version information
MUIApplicationCopyright "(c) 2001, Steve Hargreaves" ;Sets copyright information
MUIApplicationAuthor "Steve Hargreaves" ;Sets Author information
MUIApplicationDescription "Open an MUI window on the frontmost screen" ;And a description

; The above is equivalent to setting strings containing the information, and is used by Exchange and Version.

MUIApplicationBase "LESS" ;This should be a unique identifier for your application

; We'll even add a tag to our application. For the full list of tags, see the MUIApplication autodoc

MUIAddApplicationTags #MUIA_Application_SingleTask,True

; This just ensures that only one copy of our program is run at a time.
; Now we'll create an object to put in our window, just a little text label at the moment.

MUILabel 1,"My MUI Window",#MUIO_Label_Centered

; OK, the parameters - The "1" is the MUI Object number, and must be unique (if it isn't, you'll
; probably get a crash) Then the text, since this is a label, it should say something
; And finally, any flags to apply to the object. The one used will centre the text in the window
; Most MUI commands follow a format similar to this.

;Now, we'll add this to our window (I know, we don't have a window yet - fear not, we will)

MUICreateWindow 2,"My First Window","WIND1",1
MUIAddSubWindow 2

; The MUICreateWindow command takes 4 parameters. The first is the unique object number, Then the
; window title, then a unique identifier, and finally the object group to be added.
; Since we only have one object, that's all we need. The MUIAddSubWindow command makes the window
; available to MUI. OK, That's it. Our window is ready. Now we'll initialise MUI itself:-

If MUICreateApplication=False


; If, for any reason, the MUI application fails to initialise, then the program will quit quietly.

; Now that we have our application prepared, let's set up notification, so that we know when the
; close gadget has been pressed

MUINotifyApp 2,#MUIA_Window_CloseRequest,1,#MUIV_Application_ReturnID_Quit

; This now means that the window close event will be sent by MUI to Blitz. These are standard
; MUI constants, and don't need to be defined in advance

End Statement

;Now we'll open our window and wait for it to be closed

MUIOpenWindow 2 ; This is all you need to open the window

While ev.l>#MUIV_Application_ReturnID_Quit


MUICloseWindow 2 ; When the event is trapped, close the window


OK, so it's a lot of work, just to open a simple window. I know, and I agree. For such a simple window, you might as well use gadtools, and do the whole job in two or three lines. The real power of MUI comes into it's own when you are designing a more complex GUI. Already, in this simple example, you can't fail to have noticed that you haven't had to determine the size of the window, or set any flags to determine what gadgets are shown in the window border etc. In fact, you haven't worried about layout at all.

A full GUI can be created with the same disregard for layout, and considerably more quickly than Gadtools. It's also much easier to change an MUI GUI than it is a gadtools one.

The power of MUI is in it's notification and layout options. The MUINotifyApp command means that you can react to almost any event and any gadget with the minimum of fuss, so we'll have a closer look at that in the next section.

Previous Programming contents Next: How to use Notification in MUI

by Steve Hargreaves.

News | Introduction | Search | List/Forum/IRC Webring | Contact
Installation | Troubleshooting | Programming | Archives | Links
Return to programming main
Page last modified: 6th February 2002