Solution3 of the Visual ClearWin demonstration pack uses the illustration below. Once you have worked through this it is recommended that you proceed to Solution4 and so on. The demonstration pack includes a folder called "Solution". A simple way to start a Visual ClearWin solution is to copy this folder (making sure that the Fortran project is configured for one of the .NET modes such as Debug .NET).
This topic describes how to get started with Visual ClearWin. By working through the following instructions you can produce an application that looks like this.
When using the resulting application, a floating point value is entered into the Value box and the square of this value appears in the Result box when the button is clicked.
The solution consists of two projects; one contains a simple Fortran executable, the other a C# Form contained in a DLL. We start with the DLL because it contains names that are used in the Fortran code.
In Microsoft Visual Studio, create a New, Blank Solution and Add a New Project. For the type of project, select Visual C# Projects and Windows Application (you could use a Visual Basic Project if you prefer). When you do this, a new blank form is displayed in a design view. In the Properties of this project, under the General properties, select the Output Type to be a Class Library.
Now construct a form similar to that shown above. Use components from the Toolbox together with the mouse to design the form, selecting components from the toolbox and dragging a rectangle in the design view (you can pin the Toolbox open by clicking on the pin icon in the caption). Use the Properties Window for the form and for each component in order to create the visual attributes that you want. It is not necessary to view the code for the form.
The input and output boxes on the form must use a Visual ClearWin control called Double_Box. If this type of control is not visible in the Toolbox then you can add it by customizing the Toolbox as follows. Right click on the Toolbox and select Customize Toolbox. In the resulting dialog, select the tab for .NET Framework Components. Click on the Namespace header, scroll down to Salford.VisualClearWin and click on the check box for each of the Silverfrost controls that are listed. It should only be necessary to customise the Toolbox once.
In the properties for the button control, make sure that the DialogResult property is set to None.
In the References for this project, make sure that there is a reference to Salford.VisualClearWin.
Create a second project to contain the Fortran main program. Add a New Project and, for the type of project, select FTN95 Projects and FTN95 Visual ClearWin Application. In the Properties of this project, ensure that it uses the .NET platform and, in the Linker Options, that Yes is selected against Windows Application.
Open the Fortran file that has been added to the project for you and modify the template so that it becomes:
MODULE Form1
USE VC
TYPE(VCdialog) dlg1
DOUBLE PRECISION x,y
CONTAINS
INTEGER FUNCTION DoProcess()
y=x*x
DoProcess=0
END FUNCTION DoProcess
END MODULE Form1
PROGRAM Main
USE Form1
dlg1=vcCreateDialog@("WindowsApplication1.Form1")
CALL vcLinkDouble@(dlg1,"double_Box1",x)
CALL vcLinkDouble@(dlg1,"double_Box2",y)
CALL vcOnClick@(dlg1,"button1",DoProcess)
CALL DisplayDialog@(dlg1)
END
In the References for this project, select Add Reference and add a reference to the C# project. Also make sure that there is a reference to Salford.VisualClearWin.
Ensure that the C# form is built before the Fortran main program by clicking on Project Build Order in the popup menu for the solution.
Now redirect the class library (DLL) in your existing Visual C# project so that it is sent to the folder used by your Fortran executable. To do this open the Properties dialog for the C# project and in the Build section of the Configuration Properties set the Output Path to "..\Project1\Debug\NET\" or its equivalent.
The strings that appear in the Fortran program use default names from the C# project. Theses are "WindowsApplication1" which is a misnomer for the C# DLL, "Form1" for the name of the Form, and "double_Box1", "double_Box2", and "button1" for controls in the Form.
The Fortran module called VC is a Silverfrost module that is used to access the Visual ClearWin library. vcCreateDialog@, vcLinkDouble@, vcOnClick@ and vcShowDialog@ relate to methods in this library. This library includes a class called Dialog that provides a wrapper for the Microsoft Forms class. dlg1 is an instance of this class.
vcCreateDialog@ creates a Dialog from the form contained in the C# project. The first call to vcLinkDouble@ identifies x with the value obtained from the input box in the form. The second call identifies y with the value in the output box.
vcOnClick@ connects a button click event to the function called ButtonClick. As a result of this code, when you enter a number in the input box at run time, the value is automatically copied to x. When you click on the button, the callback function is called and y is computed as the square of x. This value automatically appears in the output box because y is linked to it.
vcDisplayDialog@ makes the form visible and does not return until it is closed by the user.
This example illustrates the main features of Visual ClearWin. The design view of a C# (or VB) form is used to create the visible form. In addition to the features illustrated above, the design can include components such as images, menus, toolbars, status bars, and common dialog boxes. Standard controls such as list boxes, combo boxes, tree views, list views and tab controls can be populated at design time or (where necessary) at run time.
Static text is provided as a Label component and this can use various fonts and colours. An image is provided as a PictureBox component. An image file is then attached to the PictureBox using the Image property. This can use one of a number of image formats including BMP, ICO, JPEG and GIF (although the design view can sometimes lock when using a GIF image).
Links are programmed between the controls in a form and Fortran variables using methods such as vcLinkDouble@, vcLinkInteger@ and vcLinkText@. These provide dynamic linking. If two controls share the same Fortran variable then Visual ClearWin automatically updates one when the other is changed. Alternative methods such as vcGetInteger@ and vcSetInteger@ allow you to get and set values without dynamic linking.
An event in a form can be made to trigger a Fortran callback function. vcOnClick@ is used for click events on buttons, menu items and toobar buttons whilst vcOnEvent@ allows you to link other events to a callback.
vcCreateDialog@ is commonly called to create a form. For simple dialogs that require no linking etc. you can call vcShowMessageBox@ which combines vcCreateDialog@ with vcShowDialog@. The alternative is to call vcCreateMdiChild@. This is used to create a child from a MDI (Multi Document Interface) parent.
vcDisplayDialog@ is used to display a modal dialog. A modal dialog is one that must be closed before other dialogs in the application can be used. The alternative is to call the routine vcShow@ in order to display a modeless dialog. If we were to use vcShow@ in the above program it would return immediately and terminate the application. Modeless dialogs are used for child dialogs that can be left open. For example, vcCreateMdiChild@ should be followed by a call to vcShow@.
A set of demonstration solutions has been written to illustrate the main features of Visual ClearWin.
Solution1 |
The application described above but using a C# executable. See A simple C# form. |
Solution2 |
The application described above but using a VB executable. |
Solution3 |
The application described above. |
Solution4 |
The application used in the "Factoriser" tutorial of ClearWin+. |
Solution5 |
Illustrates various controls. |
Solution6 |
Illustrates menus, toolbars, status bars and accelerator keys. |
Solution7 |
Illustrates graphics drawing (drawing lines, filling regions, drawing text and images). |
Solution8 |
Illustrates graphics drawing (pixel-by-pixel drawing). |
Solution9 |
Illustrates using common dialog boxes. |
Solution10 |
Illustrates a multiple document interface. |
Solution11 |
Illustrates a single document interface. |
Solution12 |
Illustrates populating a ListBox at run time. |
Solution13 |
Illustrates populating a ComboBox at run time. |
Solution14 |
Illustrates populating a ListView at run time. |
Solution15 |
Presents a fully functional tree editor that illustrates populating a TreeView at run time. |
Solution16 |
Presents an elementary Paint program that illustrates advanced features of the Drawing_Panel control. |
Solution17 |
Uses an Explorer_Box control to create a simple Internet Explorer program. |
Solution18 |
Uses an Explorer_Box to create a simple WYSIWYG HTML editor. |
Solution19 |
Uses an Explorer_Box to create a simple Help viewer. |
Solution 20 |
Illustrates enhanced menus. |
Solution 21 |
Illustrates a MDI based on a tab control. |
Controls in your application are automatically given the standard Microsoft� Windows� XP style of appearance. This is done for you by the linker DBK_LINK which plants code that makes your application use ComCtl32.dll version 6 rather than the default version 5. The result is that when your application is run under Windows XP it will use this style. Most controls will then use the new style by default but controls that have the FlatStyle property (in particular the GroupBox control and controls derived from the ButtonBase class) must have this property set to FlatStyle.System. In exceptional circumstances you may wish to avoid the use of the Windows XP style. For example, at the time of writing, the XP style for tab controls is unfinished and does not display correctly when the tabs are along the bottom of the control. The style can be switched off by using /no_xp_style on the DBK_LINK command line (or the FTN95 command line if DBK_LINK is called from FTN95). For further information about XP styles see Using Windows XP Visual Styles.