Silverfrost Forums

Welcome to our forums

How to put an EXIT button in a window, to close ALL windows?

2 Dec 2011 1:48 #9335

I've written a program that opens a number of windws. Each is opened using a %lw statement that specifies and (integer) control variable - a different %lw and a different variable for each window. A sample of this is:

      i=winio@('%lw&',IFirstWinClosed)

There is also a %ww statement for each window, saying:

      i=winio@('%ww[not_fixed_size,independent]&')

so that the windows can be resized and I can move from window to window during the program execution.

Each window comes with a small red X button in the upper right corner, that is automatically placed there by the system. Clicking it closes that window, but does not close any other window. This is normal, and it's what I want that small X to do.

In the first window, I'd like to place a larger button labeled EXIT, near the bottom of the window. When clicked, this EXIT button will close ALL the windows and terminate the program.

      i=winio@('%^bt[Exit]&',ExitBtn)

The callback function for this EXIT button sets the control variables for each window to a positive number, and then calls window_update@ for each control variable:

      INTEGER FUNCTION ExitBtn()
      COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed
     1  ,IBOMInqWinClosed,ICompInqWinClosed
C
C* Close all windows.
      IFirstWinClosed=1
      IOutEditWinClosed=1
      IStatusWinClosed=1
      IBOMInqWinClosed=1
      ICompInqWinClosed=1
      CALL window_update@(IFirstWinClosed)
      CALL window_update@(IOutEditWinClosed)
      CALL window_update@(IStatusWinClosed)
      CALL window_update@(IBOMInqWinClosed)
      CALL window_update@(ICompInqWinClosed)
      ExitBtn=1
      END

I have found that this code successfully closes all windows EXCEPT the first one - the one the large EXIT button is in. That first window remains open, and the program execution is not terminated.

I have also found that if I modify the statement that created the large EXIT button, to read:

      i=winio@('%^bt[Exit]&','EXIT')

invoking the standard callback function EXIT instead of my hand-written callback function ExitBtn, then the large EXIT button does close the first window (the one the button is in), but does not close any of the others.

I have tried adding a STOP statement to this callback function before the END statement. Also tried adding a CALL EXIT(Ierr) statement in the same place. Neither seems to have any effect - the callback function still closes all windows except the one it's in (the first window).

Is there a way I can make this large EXIT button close ALL windows, including the one it's in, and terminate the program?

2 Dec 2011 5:39 #9337

You can start more than one call-back function when clickig a button or a menue entry. Try this:

i=winio@('%^bt[Exit]&','+',ExitBtn,'EXIT')

or the other sequence

i=winio@('%^bt[Exit]&','+','EXIT',ExitBtn)

Regards - Wilfried

2 Dec 2011 7:48 #9341

Little-Acorn,

As your master window probably has a big red button with an X on it on the top right of the caption bar, why do you want another? Assuming your program starts with:

      PROGRAM OAK

then goes on to:

      IA=WINIO@('%ca ...

and later you see:

      IA=WINIO@( 'string with no ampersand')

Then the following line of code will be executed when you click on that exit button. The problem is to close the other windows first. The trick is to see if the exit code was zero, i.e.

      IF (IA .EQ. 0) THEN

as that means exit via that button. You can go on to set all the %lw codes appropriately and CALL UPDATE_WINDOW@ if necessary. Finally, you get to the END of your program routine, and as the main window closes when you came out of the WINIO@ section, then you have the desired result. If you absolutely have to have your own button, then it can have a callback if you want. If you don't have a callback, then you drop out of the main window code with the WINIO@ return value of 1 (assuming there is only 1 button) - or 0 if closure was done via the big X. (You will need a %ww to get the big X).

Eddie

2 Dec 2011 10:08 #9342

Quoted from LitusSaxonicum As your master window probably has a big red button with an X on it on the top right of the caption bar,

Yes, it does, as I mentioned in the opening post. It works as advertised, and I'm happy with it.

why do you want another?

As I mentioned in the OP, the built-in one only closes that window, not all windows.

Etc.

2 Dec 2011 10:10 #9343

Quoted from Wilfried Linder You can start more than one call-back function when clickig a button or a menue entry. Try this:

i=winio@('%^bt[Exit]&','+',ExitBtn,'EXIT')

or the other sequence

i=winio@('%^bt[Exit]&','+','EXIT',ExitBtn)

Regards - Wilfried

Wilfried, great! I didn't know you could do that. Thank you!

Hopefully calling my hand-written callback function, and then calling the standard function EXIT, I will get them all closed. If so, that will do it!

Thanks!

2 Dec 2011 10:28 #9344

With respect, my post goes on to tell you how to get the close box to close all other windows.

... added to that, you could put it all in the %cc code callback.

E

5 Dec 2011 9:13 #9345

Sorry, Eddie. I got the impression you hadn't read what I'd posted. And I must confess that I didn't understand what your wrote, particularly the phrase 'as the main window closes when you came out of the WINIO@ section'.

My main window does indeed start with an 'i=winio@('%ca[.......' command with an ampersand, followed by many statements (with ampersands) setting up buttons, text boxes, etc. (including one that sets up my extra EXIT button). And the final 'i=winio@.......' command has no ampersand, causing the fairly-complex window to finally open and display all those elements.

      PROGRAM TheBigProg
      WINAPP
      INCLUDE <windows.ins>

C (lots of stuff that makes up the main program)

      CALL OpenFirstWin(10,20)
      
      STOP
      END

      SUBROUTINE OpenFirstWin(IUPLEFTX,IUPLEFTY)
COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed
     1  ,IBOMInqWinClosed,ICompInqWinClosed
C (lots of COMMON, CHARACTER etc. statements)
      i=winio@('%sp&',IUPLEFTX,IUPLEFTY)
C* Create the First Window. Grave accent lets me use a long caption.
      i=winio@('%lw&',IFirstWinClosed)
      i=winio@('%`ca[My New Program]&')

C  The actual caption is longer than that, of course. 
C  These statements are followed by all the others that 
C  create other text boxes, buttons etc., including the 
C  extra EXIT button. 

      i=winio@('%^bt[Exit]&','+',ExitBtn,'EXIT')

C  All have ampersands except for the very last: 

C* Use %ww to make this window independent from other windows.
      i=winio@('%ww[not_fixed_size,independent]')
C
      RETURN
      END
C
      INTEGER FUNCTION ExitBtn()
      COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed
     1  ,IBOMInqWinClosed,ICompInqWinClosed
C
C* Close all windows.
      IOutEditWinClosed=1
      IStatusWinClosed=1
      IBOMInqWinClosed=1
      ICompInqWinClosed=1
      CALL window_update@(IOutEditWinClosed)
      CALL window_update@(IStatusWinClosed)
      CALL window_update@(IBOMInqWinClosed)
      CALL window_update@(ICompInqWinClosed)
      IFirstWinClosed=1
      CALL window_update@(IFirstWinClosed)
C
      ExitBtn=1
      END

As you can see, I set all the handles (each is from an i=winio@('%lw statement) to nonnegative values and then call window_update@ for each of them. And the windws do close as I expect. Then I set the handle from the first window to a non-negative value, and call window_update@ for that one too. I expected this to close the first window as it closed the others, but for some reason it does not close that first window.

Wilfried, as you can see, I modified the statement that created my extra EXIT button as you described, putting in two function calls. Even if my ExitBtn function didn't close the first window, I expected the second function ('EXIT') to close it. But neither of them closed it.

Could the 'i=winio@('%ww....' statement near the end of the OpenFirstWin subroutine, be messing this up?

6 Dec 2011 2:33 #9346

why not try:

      INTEGER FUNCTION ExitBtn() 
      ...
C 
      ExitBtn=0
      END 
6 Dec 2011 4:01 #9348

Quoted from JohnCampbell why not try:

      INTEGER FUNCTION ExitBtn() 
      ...
C 
      ExitBtn=0
      END 

Hmmm, never thought of it.

I will try it, thanks John!

6 Dec 2011 9:07 #9351

Using the remarks from Eddie and John, you may write like this:

      PROGRAM TheBigProg 
      WINAPP 

      IMPLICIT NONE
      INCLUDE <windows.ins> 

      integer*4    j
      external     openfirstwin,openiouteditwin,ExitBtn

      j = winio@('%ca[Main prog]%fn[MS SANS SERIF]%ts&',.96D0)
      j = winio@('%ww[]%sp%sz%cc&',10L,10L,300L,200L,ExitBtn)
      j = winio@('%mn[&File[First Window,Edit Window,End]]&',
     *    openfirstwin,openiouteditwin,ExitBtn)
      j = winio@('%^bt[Exit]',ExitBtn) 
      END 

      INTEGER FUNCTION OpenFirstWin() 
      COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed 
     1  ,IBOMInqWinClosed,ICompInqWinClosed 

      i=winio@('%ww[topmost]&') 
      i=winio@('%sp%sz%lw&',100L,100L,100L,80L,IFirstWinClosed) 
      i=winio@('%^bt[Exit]','EXIT') 
      openfirstwin = 1
      END 

      INTEGER FUNCTION OpenIOutEditWin() 
      COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed 
     1  ,IBOMInqWinClosed,ICompInqWinClosed 

      i=winio@('%ww[topmost]&') 
      i=winio@('%sp%sz%lw&',300L,100L,100L,80L,IOutEditWinClosed) 
      i=winio@('%^bt[Exit]','EXIT') 
      openiouteditwin = 1
      END 

      INTEGER FUNCTION ExitBtn() 
      COMMON/WinCtls/IFirstWinClosed,IOutEditWinClosed,IStatusWinClosed 
     1  ,IBOMInqWinClosed,ICompInqWinClosed 
 
      IOutEditWinClosed=1 
      IStatusWinClosed=1 
      IBOMInqWinClosed=1 
      ICompInqWinClosed=1 
      CALL window_update@(IOutEditWinClosed) 
      CALL window_update@(IStatusWinClosed) 
      CALL window_update@(IBOMInqWinClosed) 
      CALL window_update@(ICompInqWinClosed) 
      IFirstWinClosed=1 
      CALL window_update@(IFirstWinClosed) 
      ExitBtn = 0
      END

Regards - Wilfried

6 Dec 2011 11:54 #9354

Quoted from JohnCampbell why not try:

      INTEGER FUNCTION ExitBtn() 
      ...
C 
      ExitBtn=0
      END 

BINGO!!!

With that ExitBtn=0 statement, now it closes ALL windows with the one click!

Thank you, John Eddie and Wilfried!

Please login to reply.