View previous topic :: View next topic |
Author |
Message |
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Tue Feb 22, 2011 7:14 pm Post subject: How to come out of windows when programe ends |
|
|
Running a program that uses WINAPP when program ends I have to manually close window by clicking the top right x in the normal way which is fine, but is there any command that will shut this window down automatically within the fortran prog on enfing...or its more likely done better from within a batch file.. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Tue Feb 22, 2011 11:41 pm Post subject: |
|
|
I have the following callback function "exit_func" that closes the OUTPUT window then exits the program. The OUTPUT window can be opened when doing a WRITE (*,...
Info on this in the forum dates back to around October 2008.
I think you can select other windows to close by choosing the appropriate name in FindWindow.
I use unit 98 as a run log file.
To close the main window, the function return value = 0 closes and exits the program.
Code: |
! Menu entry
i = winio@ ('%mn[[E&xit]]&', exit_func)
integer*4 function exit_func()
!
! integer*4 :: i
! i = winio@ ('Exit function called.&')
! i = winio@ ('%nl%cn%bt[OK]')
!
call close_output_window
!
! Setting the return value to zero will exit the program.
!
exit_func = 0
end function exit_func
subroutine close_output_window
!
INCLUDE <windows.ins>
!
integer*4 hwnd
logical L
!
hwnd = FindWindow("SalfordClass", "Output")
write (98,*) hwnd,' = FindWindow("SalfordClass", "Output")'
if (hwnd < 1) return
L = DestroyWindow (hwnd)
write (98,*) L, ' = DestroyWindow(hwnd)'
!
end subroutine close_output_window
|
|
|
Back to top |
|
|
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Wed Feb 23, 2011 2:24 pm Post subject: Hi Again |
|
|
Have you ran the above code? I have simply cut and pasted it in to PLATO
I had to alter the integer statement which should be the second line before win statements?
Then it compiles with no errors but complains when I run it as such:
No main, winmain, libmain.....
I did at least declare Salflibc.lib file etc have I missed something? |
|
Back to top |
|
|
sparge
Joined: 11 Apr 2005 Posts: 371
|
Posted: Wed Feb 23, 2011 9:05 pm Post subject: |
|
|
Yes, you missed that it is a callback function. If you don't know what that is yet it's probably best to avoid trying to use one, particularly without a main program to take care of it |
|
Back to top |
|
|
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Feb 25, 2011 11:00 am Post subject: Fair enough |
|
|
But when someone pastes some code I expect it to work stand alone or at least have some instructions what it needs to work with |
|
Back to top |
|
|
sparge
Joined: 11 Apr 2005 Posts: 371
|
Posted: Fri Feb 25, 2011 5:57 pm Post subject: Re: Fair enough |
|
|
BEEFHEART wrote: | some instructions what it needs to work with |
John's post gave them to you. You already had the main program, he gave you the callback function to use with it, and a line of illustrative main program code to show you how to implement it, and some descriptive text that told you how it worked. What more did you need? |
|
Back to top |
|
|
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Wed Mar 09, 2011 12:58 pm Post subject: Re: Fair enough |
|
|
sparge wrote: | BEEFHEART wrote: | some instructions what it needs to work with |
John's post gave them to you. You already had the main program, he gave you the callback function to use with it, and a line of illustrative main program code to show you how to implement it, and some descriptive text that told you how it worked. What more did you need? |
Ok sparge if its all so simple please give me a sample of the above connected to an example/simple main program that I can compile and run please??? |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Wed Mar 09, 2011 1:31 pm Post subject: |
|
|
Here you are:
Code: |
winapp
program close_output_test
include <windows.ins>
integer*4 i,exit_func
external exit_func
! print something to an output window
print *,'Something'
! open a log file for debugging - remove later
open(unit=98,file='logfile.txt',status='unknown')
! Menu entry
i = winio@ ('%mn[E&xit]', exit_func)
! close log file - remove later
close(unit=98)
end
integer*4 function exit_func()
!
!
call close_output_window
!
! Setting the return value to zero will exit the program.
!
exit_func = 0
end function exit_func
subroutine close_output_window
!
INCLUDE <windows.ins>
!
integer*4 hwnd
logical L
!
hwnd = FindWindow("SalfordClass", "Output")
! temporary debugging statement - remove later
write (98,*) hwnd,' = FindWindow("SalfordClass", "Output")'
if (hwnd < 1) return
L = DestroyWindow (hwnd)
! temporary debugging statement - remove later
write (98,*) L, ' = DestroyWindow(hwnd)'
!
end subroutine close_output_window
|
Result of in "logfile.txt" will look like:
Quote: | 659048 = FindWindow("SalfordClass", "Output")
T = DestroyWindow(hwnd)
|
Remove temporary file open, close and print statements when you are finished debugging.
Regards
Ian |
|
Back to top |
|
|
colt1954
Joined: 21 Dec 2010 Posts: 81
|
Posted: Fri Mar 25, 2011 3:52 pm Post subject: Hi Ian |
|
|
Well this certainly runs....trouble is it leaves the normal window open and a further 'exit window' !!!
Am I missing soemthing again...not sure I understood you last comments Ian about remove etc..... |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Fri Mar 25, 2011 4:13 pm Post subject: |
|
|
It seems to do everything I expected:
1. Writes "Something" to the output window.
2. opens a small window with a single "Exit" menu item
When you select "Exit", the program terminates and destroys the command window and the output window.
I am compiling it in Plato with Win32 debug.
If you close the small menu window with the X in the caption bar, then the closing callback is not invoked. You will need another statement as shown and an & after the menu definition. This will then call exit function on any closure of the window.
i = winio@ ('%mn[E&xit]&', exit_func)
i=winio@('%cc',exit_func)
The last comment was just to remove the following code lines from the main program when you are finished debugging:
! open a log file for debugging - remove later
open(unit=98,file='logfile.txt',status='unknown')
! close log file - remove later
close(unit=98 )
and from the callback remove
! temporary debugging statement - remove later
write (98,*) L, ' = DestroyWindow(hwnd)'
Regards
Ian |
|
Back to top |
|
|
|