All callback routines should have the following interface:
SUBROUTINE callback ( dlg, control_name, callbacktype)
Where:DLG_CLICKED
,
DLG_CHANGE
, DLG_DBLCLICK
).
The last two arguments let you write a single subroutine that can be
used with multiple callbacks from more than one control. Typically, you
do this for controls comprising a logical group. For example, all the controls
in the temperature dialog in the TEMP example are associated with the
same callback routine, UpdateTemp
. You can also associate more
than one callback routine with the same control, but you must then provide
an index parameter to indicate which callback is to be used.
The following is an example of a callback routine:
SUBROUTINE UpdateTemp( dlg, control_name, callbacktype )
USE DFLOGM
IMPLICIT NONE
TYPE (dialog) dlg
INTEGER control_name
INTEGER callbacktype
INCLUDE 'RESOURCE.FD'
CHARACTER(256) text
INTEGER cel, far, retint
LOGICAL retlog
! Suppress compiler warnings for unreferenced arguments.
INTEGER local_callbacktype
local_callbacktype = callbacktype
SELECT CASE (control_name)
CASE (IDC_EDIT_CELSIUS)
! Celsius value was modified by the user so
! update both Fahrenheit and Scroll bar values.
retlog = DlgGet( dlg, IDC_EDIT_CELSIUS, text )
READ (text, *, iostat=retint) cel
IF ( retint .eq. 0 ) THEN
far = (cel-0.0)*((212.0-32.0)/100.0)+32.0
WRITE (text,*) far
retlog = DlgSet( dlg, IDC_EDIT_FAHRENHEIT, &
& TRIM(ADJUSTL(text)) )
retlog = DlgSet( dlg, IDC_SCROLLBAR_TEMPERATURE, cel, &
& DLG_POSITION )
END IF
CASE (IDC_EDIT_FAHRENHEIT)
! Fahrenheit value was modified by the user so
! update both celsius and Scroll bar values.
retlog = DlgGet( dlg, IDC_EDIT_FAHRENHEIT, text )
READ (text, *, iostat=retint) far
IF ( retint .eq. 0 ) THEN
cel = (far-32.0)*(100.0/(212.0-32.0))+0.0
WRITE (text,*) cel
retlog = DlgSet( dlg, IDC_EDIT_CELSIUS, TRIM(ADJUSTL(text)) )
retlog = DlgSet( dlg, IDC_SCROLLBAR_TEMPERATURE, cel, &
& DLG_POSITION )
END IF
CASE (IDC_SCROLLBAR_TEMPERATURE)
! Scroll bar value was modified by the user so
! update both Celsius and Fahrenheit values.
retlog = DlgGet( dlg, IDC_SCROLLBAR_TEMPERATURE, cel, &
& DLG_POSITION )
far = (cel-0.0)*((212.0-32.0)/100.0)+32.0
WRITE (text,*) far
retlog = DlgSet( dlg, IDC_EDIT_FAHRENHEIT, TRIM(ADJUSTL(text)) )
WRITE (text,*) cel
retlog = DlgSet( dlg, IDC_EDIT_CELSIUS, TRIM(ADJUSTL(text)) )
END SELECT
END SUBROUTINE UpdateTemp
Each control in a dialog box, except a pushbutton, has a default callback that performs no action. The default callback for a pushbutton's click event sets the return value of the dialog to the pushbutton's name and then exits the dialog. This makes all pushbuttons exit the dialog by default, and gives the OK and CANCEL buttons good default behavior. A routine that calls DLGMODAL can then test to see which pushbutton caused the modal dialog to exit.
Callbacks for a particular control are called after the value of the control has been changed by the user's action. Calling DLGSET does not cause a callback to be called for the changing value of a control. In particular, when inside a callback, performing a DLGSET on a control will not cause the associated callback for that control to be called.
Calling DLGSET before or after DLGMODAL or DLGMODELESS has been called also does not cause the callback to be called. If the callback needs to be called, it can be called manually using CALL after the DLGSET is performed.