Each dialog box has an associated variable of the derived type dialog
.
The dialog
derived type is defined in the DFLOGM.F90 module; you access it
with USE DFLOGM. When you write your dialog application, refer to your dialog box
as a variable of type dialog
. For example:
USE DFLOGM
INCLUDE 'RESOURCE.FD'
TYPE (dialog) dlg
LOGICAL return
return = DLGINIT( IDD_TEMP, dlg )
This code associates the dialog
type with the dialog (IDD_TEMP
in this example) defined in your resource and include files (TEMP.RC
and RESOURCE.FD
in this example).
You give your application access to your dialog resource by adding the .RC file to
your project. You give your application access to the dialog include file by including
the .FD file in each subprogram. You associate the dialog properties in these files with
the dialog
type by calling DLGINIT with your dialog name.
An application that controls a dialog box should perform the following actions:
dialog
type and associate your dialog and its properties with the type.
As an example of activating a dialog box and controls, the following
code initializes the temperature dialog box and controls created in the
TEMP project example. It also sets the callback routine as UpdateTemp
, displays the
dialog box, and releases the dialog resources when done:
SUBROUTINE DoDialog( )
USE DFLOGM
IMPLICIT NONE
INCLUDE 'RESOURCE.FD'
INTEGER retint
LOGICAL retlog
TYPE (dialog) dlg
EXTERNAL UpdateTemp
! Initialize.
IF ( .not. DlgInit( idd_temp, dlg ) ) THEN
WRITE (*,*) "Error: dialog not found"
ELSE
! Set up temperature controls.
retlog = DlgSet( dlg, IDC_SCROLLBAR_TEMPERATURE, 200, DLG_RANGEMAX)
retlog = DlgSet( dlg, IDC_EDIT_CELSIUS, "100" )
CALL UpdateTemp( dlg, IDC_EDIT_CELSIUS, DLG_CHANGE)
retlog = DlgSetSub( dlg, IDC_EDIT_CELSIUS, UpdateTemp )
retlog = DlgSetSub( dlg, IDC_EDIT_FAHRENHEIT, UpdateTemp )
retlog = DlgSetSub( dlg, IDC_SCROLLBAR_TEMPERATURE, UpdateTemp )
! Activate the modal dialog.
retint = DlgModal( dlg )
! Release dialog resources.
CALL DlgUninit( dlg )
END IF
END SUBROUTINE DoDialog
The dialog routines, such as DLGSET and DLGSETSUB, refer to the dialog controls by the names you assigned to them in the Properties box while creating the dialog box in the Resource Editor. For example:
retlog = DlgSet( dlg, IDC_SCROLLBAR_TEMPERATURE, 200, DLG_RANGEMAX)
In this statement, the dialog function DLGSET assigns the control
named IDC_SCROLLBAR_TEMPERATURE
a value of 200. The index DLG_RANGEMAX
specifies that this value is a scroll bar maximum range. Consider the following:
retlog = DlgSet( dlg, IDC_EDIT_CELSIUS, "100" )
CALL UpdateTemp( dlg, IDC_EDIT_CELSIUS, DLG_CHANGE)
The preceding statements set the dialog's top Edit box, named
IDC_EDIT_CELSIUS
in the Resource Editor, to an initial value of 100, and calls
the routine UpdateTemp
to inform the application that the value has changed. Consider
the following:
retlog = DlgSetSub( dlg, IDC_EDIT_CELSIUS, UpdateTemp )
retlog = DlgSetSub( dlg, IDC_EDIT_FAHRENHEIT, UpdateTemp )
retlog = DlgSetSub( dlg, IDC_SCROLLBAR_TEMPERATURE,UpdateTemp )
The preceding statements associate the callback routine UpdateTemp
with the
three controls. This results in the UpdateTemp
routine being called
whenever the value of any of the three controls changes.
Routines are assigned to the controls with the function DLGSETSUB. Its first argument is the dialog variable, the second is the control name, the third is the name of the routine you have written for the control, and the optional fourth argument is an index to select between multiple routines. You can set the callback routines for your dialog controls anywhere in your application: before opening your dialog with either DLGMODAL or DLGMODELESS, or from within another callback routine.
In the TEMP example, the main program calls the DoDialog subroutine to display the Temperature Conversion dialog box.