Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29594 Discussions

Creating GUI using Compaq Visual Fortran (for Windows)

__azerty__
Beginner
1,934 Views
Dear Colleagues,
I am trying to understand how to create asimple windows GUI using Visual Fortran. I have been working for a long time with Fortran 77 and Fotran 90, but I have never programmed windows applications before. So, I am using the standard code for a 'dialog', automatically generated by Compaq Visual Fortran 6.5, and then assign my subroutine to a button. Unfortunately this does not work. After I run my application the dialog with the button appears, but nothing happens when I click this button. The code is pasted below. Could you please tell me what I did incorrectly?
Thanks!
integer*4 function WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'WinMain' :: WinMain
!DEC$ ENDIF

use user32
use kernel32
use dflogm
use MyGlobals

implicit none

integer*4 hInstance
integer*4 hPrevInstance
integer*4 lpszCmdLine
integer*4 nCmdShow

include 'resource.fd'

external MyApply

! Variables
integer*4 ret
logical*4 lret


ghInstance = hInstance
ghModule = GetModuleHandle(NULL)
ghwndMain = NULL

lret = DlgInit(IDD_My_DIALOG, gdlg)
if (lret == .FALSE.) goto 99999
lret = DlgSetSub(gdlg, IDD_My_DIALOG, MySub)
lret = DlgSetSub(gdlg, IDM_APPLY, MyApply)
lret = DlgModeless(gdlg, nCmdShow)
if (lret == .FALSE.) goto 99999

call DlgUninit(gdlg)

WinMain = mesg.wParam
return

99999 &

ret = MessageBox(ghwndMain, "Error initializing application matrix8"C, &
"Error"C, MB_OK)
WinMain = 0

end



SUBROUTINE MyApply( dlg, id, callbacktype )

use dflogm

implicit none

include 'resource.fd'

type (dialog) dlg
integer id, callbacktype, lret, IDC_STATIC

if (callbacktype == dlg_clicked) then

lret = DLGsET (dlg, IDC_STATIC, &
'You have clicked the button', DLG_TITLE)

endif

END SUBROUTINE MyApply
0 Kudos
5 Replies
dima333a
Beginner
1,934 Views
Unfortunately I can not give you an advise in this particular case, but you may try the book by Norman Lawrence " Compaq Visual Fortran A guide to Creating WIndows Applications"
0 Kudos
g_f_thomas
Beginner
1,934 Views
Lawrence's book is certainly a good start. However, within the bowels of MSVF/DVF/CVF/IVF documentation are cautionary words to the effect that Window's Fortran isn't easy: believe me, it isnt, and I'm good at it. There are no short cuts, whether via QuickWin, VB, C#, etc. Doing Windows is a grind in Fortran or any other language.

Good Luck!
Gerry T.
0 Kudos
__azerty__
Beginner
1,934 Views
Thank you for the suggestions! Well, yes, I am trying to get the book you've reccommended... But may be someone could jast paste here the simplest code with assigning the simple user-defined function to the simplest button? I still don't understand what I am doing wrong with it...
0 Kudos
anthonyrichards
New Contributor III
1,934 Views
There are several errors that prevented the code you posted from compiling and working.
Firstly, you initiated a MODELESS dialog box, which requires a message loop, hence your reference to 'msg' in 'WinMain=msg.wparam', but 'msg' is nowhere defined or initiated.
To use your callbacks, you must change it to a MODAL dialog using the following:
lret = DlgModal(gdlg)
if (lret == .FALSE.) goto 99999

call DlgUninit(gdlg)

WinMain = 1
then your callbacks will work.(I assume there is code somewhere for Mysub..it was not posted. I also had to make up code for MYGLOBALS, which I presumed contained specifications for ghInstance, ghModule, ghwndMain gdlg etc.)
I would advise changing your static control ID to IDC_STATIC1 so as to distinguish it from any other static text you may add later.
Make sure you define both MySub and MyApply as EXTERNAL.
With these changes, it worked fine.
0 Kudos
__azerty__
Beginner
1,934 Views
Wow! Thank You! I've got now. I will try to fix all you havementioned.
0 Kudos
Reply