To use a modeless dialog box, you typically use a Fortran Windows project type. The Fortran Windows Project AppWizard helps you add coding for using a modeless dialog box.
When you create a project and specify the Fortran Windows project, the Fortran Windows Project AppWizard displays four options (press the F1 key to view an explanation of these options).
Select one of the following to help learn about dialog coding where a dialog box is the primary window of the application:
To create an application where a dialog box is the main window of the application, without a menu bar, choose the A simple Dialog Based Application option.
This creates the skeleton of an entire application that you can immediately
build and run to display a sample dialog box.
You can add controls to the dialog
box and add dialog procedure calls to manipulate the controls
and handle dialog callbacks. A number of the sample projects in
the ...\SAMPLES\DIALOG\
directory were started using the
A simple Dialog Based Application option.
To create an application where a dialog box is the main window of the application with a menu bar, choose the A simple Single Document Interface (SDI) option.
This also creates the skeleton of an entire application that you can immediately build and run. You can add a dialog box to the client area of the main window (as explained later).
In the template-like code generated when you select A simple Dialog Based Application option:
use dflogm
use FWin_dialogGlobals
.
.
.
include 'resource.fd'
external FWin_dialogSub
external FWin_dialogApply
! Variables
type (T_MSG) mesg
integer*4 ret
logical*4 lret
The FWin_dialogGlobals module is defined in a separate source file in that project. The FWin_dialogSub and FWin_dialogApply are subroutines defined later in the main source file that are callback routines for different controls for the dialog box.
lret = DlgInit(IDD_FWIN_DIALOG_DIALOG, gdlg)
if (lret == .FALSE.) goto 99999
lret = DlgSetSub(gdlg, IDD_FWIN_DIALOG_DIALOG, FWin_dialogSub)
lret = DlgSetSub(gdlg, IDM_APPLY, FWin_dialogApply)
lret = DlgModeless(gdlg, nCmdShow)
if (lret == .FALSE.) goto 99999
Notes for this example:
DlgInit initializes the dialog box.
The first call to DlgSetSub assigns a callback subroutine
to the Exit button. It associates the FWin_dialogSub subroutine with the
dialog box identifier IDD_FWIN_DIALOG_DIALOG (project name is FWin_Dialog). The
FWin_dialogSub routine contains code to terminate the program.
The second call
to DlgSetSub associates FWin_dialogApply with the Apply button
identifier IDM_APPLY. The user should add code in the FWin_dialogApply subroutine
to take appropriate action.
DlgModeless displays the initialized modeless
dialog box, which is ready for user input.
! Read and process messages
do while( GetMessage (mesg, NULL, 0, 0) )
if ( DlgIsDlgMessage(mesg) .EQV. .FALSE. ) then
lret = TranslateMessage( mesg )
ret = DispatchMessage( mesg )
end if
end do
Notes for this example:
The GetMessage Win32 call inside a DO WHILE loop
returns a message from the calling thread's message queue.
DlgIsDlgMessage determines whether the specified message is
intended for one of the currently displayed modeless dialog boxes, or a specific dialog box.
The TranslateMessage Win32 call translates virtual-key messages into character messages.
The DispatchMessage Win32 call dispatches a message to a window procedure.
call DlgUninit(gdlg)
In the template-like code generated when you select A simple Single Document Interface (SDI) AppWizard option, to add the dialog box to the client area of the main window:
USE dflogm
lret = DlgModeless(dlg, SW_SHOWNA, hwndParent)
In this call, hwndParent is the window handle of the application's main window.
! Read and process messages
do while( GetMessage (mesg, NULL, 0, 0) )
if ( DlgIsDlgMessage(mesg, dlg) .EQV. .FALSE. ) then
if ( TranslateAccelerator (mesg%hwnd, haccel, mesg) == 0) then
lret = TranslateMessage( mesg )
ret = DispatchMessage( mesg )
end if
end if
end do
See the FXPLORER Visual Fortran Sample
in ...\SAMPLES\DIALOG
for an example of this type of application.