Programming AmigaOS in C

4. How to create a MUI Window?

To create a window in MUI, you need to create a MUI application and specify an ApplicationObject and within that object, you need to specify a WindowObject, for example:

app = ApplicationObject,
  MUIA_Application_Title, "A MUI Window",
  MUIA_Application_Version, "$VER: Window 41.0 (11.04.10)",
SubWindow, window = WindowObject,

For AmigaOS 4, you need to use the IMUIMaster interface, with the MUI_NewObject() function, so the code will look like this (if you don't want to spoil the code, modify the header file in libraries/mui.h and add the interface name). Any objects start with MUIC need to use the this code change:

app = IMUIMaster->MUI_NewObject(MUIC_Application,
  MUIA_Application_Title, "A MUI Window",
  MUIA_Application_Version, "$VER: Window 41.0 (11.04.10)",
SubWindow, window = IMUIMaster->MUI_NewObject(MUIC_Window,

To define your window such as giving a title, an ID, gadgets, menu and size you need to provide attributes. The attributes start with MUIA_Window. Some of the attributes available are:

MUIA_Window_Title = Window title string
MUIA_Windows_ID = Window ID. Use the MAKE_ID(a,b,c,d) function.
MUIA_Window_Activate = Window activated?
MUIA_Window_Backdrop = Backdrop enabled?
MUIA_Window_Borderless = Window is borderless?
MUIA_Window_CloseGadget = Include close gadget?
MUIA_Window_DepthGadget = Include depth gadget?
MUIA_Window_SizeGadget = Include size gadget?
MUIA_Window_DragBar = Include a drag bar?
MUIA_Window_Height = Height of window
MUIA_Window_Width = Width of window
MUIA_Window_LeftEdge = Left edge position
MUIA_Window_TopEdge = Top edge position
MUIA_Window_Menustring = Menu object

There are many other attributes for a window in Mui.h header file. Unlike a window created in Intuition or Gadtools, you do not always need to specify a width and height as the the gadgets inside the window will allow MUI to auto-calculate the size for you so that it always looks neat. Some attributes have defaults, so some attributes can be left out if the default matches your design. Check the development guide with information. For our example, we will create a window 200 x 100 with all the gadgets:

SubWindow, window = WindowObject,
 MUIA_Window_Title, "My Window",
 MUIA_Windows_ID, MAKE_ID('W','I','N','1'),
 MUIA_Window_Activate, TRUE,
 MUIA_Window_Height, 100,
 MUIA_Window_Width, 200,
 MUIA_Window_LeftEdge, 75,
 MUIA_Window_TopEdge, 75,
 MUIA_Window_CloseGadget, TRUE,
 MUIA_Window_DepthGadget, TRUE,
 MUIA_Window_SizeGadget, TRUE,

Some attributes require an Object such as the Menustrip, MouseObject and RefWindow. You can define these objects within the Window definition and define its attributes as well. e.g.

MUIA_Window_Menustrip, (mstrip = MenustripObject,
.... list of attributes.... ),

5. How to create a MUI Screen?

There are three additional attributes which you can add to the Window Object which allows you to create a screen or use a Public screen:

MUIA_Window_Screen = Provide address of a Screen structure.
MUIA_Window_ScreenTitle = Provide or change name of Screen.
MUIA_Window_PublicScreen = Provide an address of a public screen.

Before you can use a new screen, you need to use OpenScreenTagList() function to create your screen. For example, this will create a 640 by 480 public screen.

 struct Screen *myScreen;
 myScreen = OpenScreenTagList(NULL, 
   SA_Left, 0, SA_Top, 0, SA_Width, 640, SA_Height, 480,
   SA_Depth, 8, SA_Title, "My New Screen",
   SA_SysFont, 1,

In the MUI application, specify the following line to use the new Screen:

MUIA_Window_Screen, &myScreen,

See the Screens page in my Tutorial about screens.

Next Page