ID 757211
Date 7/23/2021
Public

## Initializing and Activating the Dialog Box

Each dialog box has an associated variable of the derived type dialog. The dialog derived type is defined in the IFLOGM.F90 module; you access it with USE IFLOGM. When you write your dialog application, refer to your dialog box as a variable of type dialog. For example:

  USE IFLOGM
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).

An application that controls a dialog box should perform the following actions:

1. Call DLGINIT or DLGINITWITHRESOURCEHANDLE to initialize the dialog type and associate your dialog and its properties with the type.

2. Initialize the controls with the dialog set routines, such as DLGSET.

3. Set the callback routines to be executed when a user manipulates a control in the dialog box with DLGSETSUB.

4. Depending on whether you want a modal or modeless dialog type:

• To use a modal dialog, run the dialog with DLGMODAL.

• To use a modeless dialog, call DLGMODELESS and use DLGISDLGMESSAGE in your message loop.

5. Retrieve control information with the dialog get functions, such as DLGGET.

6. Free resources from the dialog with DLGUNINIT.

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 IFLOGM
IMPLICIT NONE
INCLUDE 'RESOURCE.FD'
INTEGER retint
LOGICAL retlog
TYPE (dialog) dlg
EXTERNAL UpdateTemp
! Initialize.
IF ( .not. DlgInit( idd_temp, dlg ) ) THEN
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 DLGSETDLGSETSUB and, 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.