ROVLib Tutorial - Program information© Jason Tribbeck 2002 |
![]() |
We will be adding a program information window in this tutorial.
/** * ProgInfo.c - Adding a program information window */ /* Include 4 standard C header files */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include <ctype.h> /* Include the RISC OS kernel header file */ #include "kernel.h" /* Include the ROVLib header files */ #include "main.h" #include "canvas.h" #include "menu.h" #include "baricon.h" #include "extras.h" /* Prototype the click function */ void click(int icn); /* Prototype the menu event handler */ void choose(menu m, int item); /* Prototype the menu click event handler */ void menu_click(canvas c); /* A variable to hold the canvas */ static canvas c; /* A variable to hold the menu */ static menu iconm; int main(int argc, char **argv) { /* Initialise the ROVLib system */ main_init("My Application"); /* Initialise the ROVLib canvas core */ canvas_init(); /* Initialise the ROVLib menu core */ menu_init(); /* Create the canvas */ c = canvas_create(640, 480, "An example canvas"); /* Make the canvas as a window */ canvas_make(c); /* Create an icon on the icon bar */ baricon("file_ff8", click); /* Register a menu handler on the icon bar */ canvas_addhandler(CANVAS_ICONBAR, CANVAS_MENUHANDLER, menu_click); /* Create the program information canvas */ c_proginfo = create_infobox("My Application", "An example ROVLib application", "© Jason Tribbeck", "1.00 (14 Feb 2002)"); /* Create the menu */ iconm = menu_create("Menu test", 2, choose, NULL); /* Add the 'Info' menu item */ menu_add(iconm, "Info"); /* Add the 'quit' menu item */ menu_add(iconm, "Quit"); /* Add the program information canvas */ menu_attachpane(iconm, 0, c_proginfo); /* Open the canvas in the centre of the screen */ canvas_opencentre(c); /* Poll forever (or at least until told to quit!) */ main_poll(); } /* Actually perform the click function */ void click(int icn) { canvas_reopen(c); } /* Handle the menu click event */ void menu_click(canvas c) { menu_displayiconbar(iconm); } /* Handle the menu choice */ void choose(menu m, int item) { switch(item) { case 1 : exit(0); break; } }
The amount of new code in this application is minimal - basically we create the
program information canvas by calling create_infobox
, which returns a
canvas that is the right size for the information box, and already made into a
window. The size of the information box is determined by the length of the strings
passed into it, as well as the current WIMP font. This is unlike many other RISC OS
libraries.
Once created, we can attach it as a submenu to the icon bar menu, in the first position.
As we've inserted a menu item, we have to change which item causes the application to die. Now, we are going to die on choice 1.
This will appear identical to the previous tutorial, but will have an additional menu item, with a submenu that has the program information box that looks like:
You have seen how to create a program information canvas, and also attach canvasses as submenus to a menu.