Step 5

In this section:

Now we shall add a menu bar with an associated “About” dialog box in order to create factor5.for. Here is the text, but to make it easier to understand, only those parts of facror4.for that have changed are listed in full.

 6   EXTERNAL factoriser,about
12   ans=winio@('%ca[Number Factoriser]&')
13   ans=winio@('%mn[&File[E&xit]]&','EXIT')
14   ans=winio@('%mn[&Help[&About Number Factoriser]]&',about)
15   ans=winio@('%il&',1,2147483647)
19   END
20
21   INTEGER FUNCTION factoriser()
28   END
29
30   INTEGER FUNCTION about()
31   IMPLICIT NONE
32   INCLUDE <windows.ins>
33   INTEGER ans
34   ans=winio@('%ca[About Number Factoriser]&')
35   ans=winio@('%fn[Times New Roman]%ts%bf%cnTutorial&',2.0D0)
36   ans=winio@('%ts%4nl&',1.0D0)
37   ans=winio@('%cnProgram written to demonstrate%2nl&')
38   ans=winio@('%ts%tc%cn%bfClearWin+&',1.5D0,RGB@(255,0,0))
39   ans=winio@('%tc%sf%2nl%cnby&',-1)
40   ans=winio@('%2nl%cnSalford Software&')
41   ans=winio@('%2nl%cn%9`bt[OK]')
42   about=1
43   END

A new call-back function called about has been added to line 6 and the code for this function has been added to the end of factor4.for in lines 30 to 43. The new menu bar has been included as lines 13 and 14 after the caption in line 12.

This is what the compiled program displays on the screen.

When you click on the “Help” menu and then on the “About Number Factoriser” item, you get the dialog box below.

Now for the details of how this effect is created. First look at lines 13 and 14 for the menu bar.

13    ans=winio@('%mn[&File[E&xit]]&','EXIT')
14    ans=winio@('%mn[&Help[&About Number Factoriser]]&',about)

The menu format is provided by %mn (Menu). Square backets enclose a list of menu topics, with each topic having an optional embedded list of associated menu items. There are two menu topics here, “File” and “Help”. These provide for two drop down menus each of which (in this example) has one item . The “&” character is used in the same way as on a button in order to provide an accelerator key.

Each menu item requires a call-back function and these are provided as further arguments to winio@. The first one ('EXIT') refers to what is called a standard ClearWin+ call-back function. When a standard call-back function is used, the code for the function is supplied by ClearWin+ rather than by the programmer. In this case the effect of calling the function is simply to close the application.

The second call-back function (about) is supplied by the progammer. In this case the about function displays a dialog box that describes the application. When the user clicks on the OK button, the dialog box closes but the application remains active. If about returned zero instead of a 2, the application would also close when the OK button was used.

All we need to do now is look at the new call-back function for the “About” dialog. Let’s concentrate on the format codes that we have not seen before in this tutorial.

%fn (Font) defines a new font for the text that follows. In this case the font is “Times New Roman” and this font is used for the subsequent text up to the %sf format code on line 39. %sf (Standard Font) stands for “standard font” and has the effect of resetting all text attributes (font, size, colour, bold, italic, and underline) to the default settings.

%ts (Text Size) is used to set the text size. It takes one DOUBLE PRECISION argument. The value 2.0D0 on line 35 doubles the standard text size and then the standard size is restored on line 36 with the value 1.0D0. Line 38 uses a text size of one and a half times the standard and then the standard size is restored with %sf on line 39.

%bf (Bold Font) on line 35 is used to provide bold faced font whilst %cn (Centre) has the effect of centring the line of text in the dialog box. In this example %cn is cancelled by the next newline format (%nl (Newline)). On line 38, %tc (Text Colour) changes the colour of the text to red. The colour is provided by the call to the ClearWin+ function RGB@. RGB@ takes three INTEGER arguments in the range 0 to 255. These provide the red, green and blue intensities. Note that %ts (Text Size) comes before %tc and uses the 1.5D0 argument on line 38. %tc is also used on line 39. In this case the argument (-1) restores the system text colour. This is one of the screen colours that the user can set from the Control Panel in the Program Manager.

Finally line 41 produces the OK button. As before the grave accent makes this the default button, whilst the value 9 has the effect of widening the button to a 9 character width. This button does not have a call-back function. As a result, when the user clicks on the button, the format window closes. If there are a number of buttons like this, then the value returned by winio@ (ans in this case) gives the number of the button that was pressed.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited