- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
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
!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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Good Luck!
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow! Thank You! I've got now. I will try to fix all you havementioned.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page