The next thing we need is a child window in order to present the results of the
factorising process. factor4.for includes the code for such a window but
we shall leave out the code that calculates the results until the end. Here is
the text of factor4.for:
1 WINAPP 'CWP_ICO.RC'
3 PROGRAM factor4
4 IMPLICIT NONE
5 INCLUDE <windows.ins>
6 EXTERNAL factoriser
7 INTEGER ans,number
8 CHARACTER*50 str
9 COMMON number,str
11 str=' '
12 ans=winio@('%ca[Number Factoriser]&')
14 ans=winio@('Number to be factorised: %rd&',number)
19 INTEGER FUNCTION factoriser()
20 INTEGER number
21 CHARACTER*50 str
22 COMMON number,str
24 CALL window_update@(str)
Lines 8, 9, 11, 16 and 19 to 26 have been added and as before an "&"
character has been placed at the end of the format string on line 15.
When the program is compiled the result looks like this:
At the current state of development, when you click on the "Factorise" button,
the number that has been entered is simply copied to the new child window.
The allocation of the variable number to a common block in lines 9, and
22, provides a method for passing this variable to the factoriser function.
You will recall that call-back functions like factoriser do not have any
arguments. Line 23 stores the value of number as a character string in str.
str is also held in common because it is used for output on line 16:
On line 16, %2nl provides two line feeds so that the child window that follows
is placed below the existing controls.
The %ob format code is used to open a box at the current position. It
automatically marks the position of the top left-hand corner of a box that will
be drawn when a corresponding %cb (close box) is encountered. %cb automatically
marks the position of the bottom right-hand corner of the box. The box is
simply provided as a border. The enclosed area has no special attributes. In
the present case the box is used to enclose a string that is produced by the
%st format. The string is located in str and the width of the associated
area is 42 characters. However, the standard width of a character in this
context will be the maximum width of all the characters of the proportionally
Finally, line 24 has the effect of updating the string on the screen in order to
reflect a change in the contents of str.