Back to Contents        Previous        Next







3. First windows **

Windows are, of course, the main visual tool of Wimp programs, so let’s have a look at how Dr Wimp handles them. We will start with the very common ‘info’ window.

Adding an ‘Info’ window
An info window is usually accessed from the ‘Info’ item on the iconbar menu. In the Tutorials folder (Tutor1 sub-directory) you will find the file “Template1”. Copy this into the !MyApp application directory and rename it as “Templates”. You can examine it if you want by loading it into !WinEd. (At the moment, we will only be using windows which have been designed in a window template editor - such as !WinEd, which is included in the package. A template editor puts its results into a ‘templates’ file - and one file can hold several window definitions.)

In !MyApp’s !RunImage listing add the following line below FNwimp_iconbar (above FNwimp_createmenu):

info%=FNwimp_loadwindow(“<MyApp$Dir>.Templates”,“info”,0)

This wimp-function loads into the application’s memory the definition of a window from the templates file, whose full pathname is given in the first parameter. The second parameter is the name of the particular window as named in the templates file.


The last parameter tells DrWimp where to find any sprites that you may have used in designing the window. A 0 means “look in the Wimp sprite pool”, and this is the most common option. Alternatively, a handle to a sprite area could be used instead and would mean “look in this sprite area” as well. Our ‘Info’ window uses just one sprite (the Dr Wimp logo) and it is included in the !MyApp !Sprites/!Sprite22 files - which means that it will be loaded automatically into the sprite pool on application start-up. Thus setting the final parameter to 0 is appropriate here.


The function FNwimp_loadwindow returns a handle for the window which we have assigned to the variable info% - whose name, again, tells us what it is.



Attaching a sub-menu/window
Now we need to modify the iconbar menu to take into account the ‘info’ window. We want Item 1 of the iconbar menu to ‘lead to’ this window, just like a sub-menu.

This is very simple to do and, in fact, RISC OS (and Dr Wimp) allows submenus to be either normal submenus or windows. Using Dr Wimp, all you have to do is ‘attach’ a submenu/window to the required menu item using the following wimp-function in a line such as:

PROCwimp_attachsubmenu(iconbarmenu%,1,info%)

So, add that line after the line with FNwimp_createmenu in it - as the menu and the attachment need to exist before you can attach anything.

The first parameter of PROCwimp_attachsubmenu is the handle of the menu to which the submenu is to be attached: the second parameter is the particular item on that menu to which the submenu is to be attached (in this case 1 which is the top item) and the third parameter is the handle of the sub-menu to attach (or the handle of the window to attach). In this case it is the handle to the ‘info’ window.

And that’s it!

Re-load !MyApp and you will now see that the first (Info) menu item now has the familiar arrow-head against it, indicating that a submenu/window is ‘attached’. If you move across this arrow-head the info window will appear.



Adding/changing icon text
You will see in the info window that the Author and Version fields have default information in them. It is very simple to change this, and the technique that we are about to describe can be used for any icon that has text, whether it is a Radio button, a default action button, or just a label icon - provided the icon text is defined as ‘indirected’, (see !WinEd). You only need to know the window handle and the icon number/handle. We will be changing the text in icon numbers 1, 2 and 4 below. (You can find the icon number by loading the Templates file into !WinEd, opening the ‘info’ window and moving the pointer over the icons. The !WinEd ‘Monitor’ window at the top right of the screen will give you the number of each icon.)


First of all we will look at the Author field. This is icon number two. Add the following line just before ENDPROC in PROCuser_initialise:

PROCwimp_puticontext(info%,2,“© Joe Bloggs 1996”)

Replace “Joe Bloggs” with your own name (there is a limit on the length of the string though). This is fixed by the indirected size and the physical size of the box. These can easily be changed using !WinEd.


Now for the Version field, which is icon number 4. It is common practice to display the version number and date in the form “X.XX (Dt-Mth-Yr)”, eg:

         1.42 (16-Oct-99)

So add the following line just before ENDPROC in PROCuser_initialise (changing the date to whatever you wish):

PROCwimp_puticontext(info%,4,“1.00 (29-Mar-98)”)

By now, you will see that the parameters to the function are quite simple. From left to right they are: the window handle, the icon number/handle, and the text to put into the icon.

Check that the application works as it is supposed to and then try using the same method to change the “Purpose” field (icon number 1) to something more interesting.


By the way, as long as the window has been loaded, you can change icon text in the above fashion at any time. If the window is open when you do it, the change will be displayed straightaway. If not, the change will show when you next display the window.

Note that, in icons, the Wimp only allows text to be displayed. So any numbers need to be converted to strings before putting into an icon - and often need to be converted back to numbers after reading from an icon.


[Your !RunImage listing should now look like listing RI_01 in Tutor1 (apart from the REM lines, perhaps). Do not destroy it as the following sections continue the tutorial from this stage.]





Top of page        Back to Contents        Previous        Next