Silverfrost Forums

Welcome to our forums

How to come out of windows when programe ends

22 Feb 2011 6:14 #7819

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..

22 Feb 2011 10:41 #7824

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.

!  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
23 Feb 2011 1:24 #7827

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?

23 Feb 2011 8:05 #7831

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 😉

25 Feb 2011 10:00 #7836

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 :roll:

25 Feb 2011 4:57 #7840

Quoted from BEEFHEART some instructions what it needs to work with :roll:

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? :roll:

9 Mar 2011 11:58 #7888

Quoted from sparge

Quoted from BEEFHEART some instructions what it needs to work with :roll:

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? :roll:

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???

9 Mar 2011 12:31 #7889

Here you are:

      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:

', 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:f3c02b80cb] 659048 = FindWindow('SalfordClass', 'Output') T = DestroyWindow(hwnd)

Remove temporary file open, close and print statements when you are finished debugging. Regards Ian

25 Mar 2011 2:52 #7970

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.....

25 Mar 2011 3:13 #7971

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&amp;xit]&amp;', 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

Please login to reply.