forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Dec 02, 2011 2:48 am    Post subject: How to put an EXIT button in a window, to close ALL windows? Reply with quote

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:

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


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

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

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

Code:

      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:

Code:
      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?
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Fri Dec 02, 2011 6:39 am    Post subject: Reply with quote

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

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

or the other sequence

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

Regards - Wilfried
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Dec 02, 2011 8:48 pm    Post subject: Reply with quote

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:

Code:
      PROGRAM OAK
then goes on to:
Code:
      IA=WINIO@('%ca ...
and later you see:
Code:
      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.
Code:
      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
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Dec 02, 2011 11:08 pm    Post subject: Re: Reply with quote

LitusSaxonicum wrote:
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.

Quote:
why do you want another?

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

Etc.
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Fri Dec 02, 2011 11:10 pm    Post subject: Re: Reply with quote

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

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

or the other sequence

Code:
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!
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Dec 02, 2011 11:28 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Mon Dec 05, 2011 10:13 pm    Post subject: Reply with quote

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.

Code:

      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?
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Tue Dec 06, 2011 3:33 am    Post subject: Reply with quote

why not try:
Code:
      INTEGER FUNCTION ExitBtn()
      ...
C
      ExitBtn=0
      END
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Tue Dec 06, 2011 5:01 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
why not try:
Code:
      INTEGER FUNCTION ExitBtn()
      ...
C
      ExitBtn=0
      END


Hmmm, never thought of it.

I will try it, thanks John!
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Tue Dec 06, 2011 10:07 am    Post subject: Reply with quote

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

Code:
      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
Back to top
View user's profile Send private message
Little-Acorn



Joined: 06 Jul 2008
Posts: 111
Location: San Diego

PostPosted: Wed Dec 07, 2011 12:54 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
why not try:
Code:
      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!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group