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 find if text window %cw is already opened

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Tue Feb 02, 2010 10:59 pm    Post subject: How to find if text window %cw is already opened Reply with quote

or its associated logical unit number LUN like in this line

winio@(‘%100.20cw[hscroll,vscroll]’, LUN)

is in use?

When %cw is open we can write on its associated LUN like into usual fortran output unit (like print on screen) or some file:

writre(LUN,*) abc

But in Fortran there exist a way to find if file is open or is in use with INQUIRE statement.

What is needed for %cw is sort of like INQUIRE(filename, exists) statement but instead of "filename" has to be the LUN number - that sort of idea. May be other workarounds exist.

I need it for the following. Suppose I open %cw to print on screen some data (some variable 1). If i will need to printscreen another Variable 2 I would like to print it values into the different %cw screen which program has automatically open for that. Hence the program has to find that one (or two or five) %cw is already open and specific LUN numbers are taken and then open new %cw window with LUN=LUN+1 and write there.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Feb 03, 2010 10:09 am    Post subject: Reply with quote

I don't think that INQUIRE can currently be used in this context.
If you have a %cw that can be closed (e.g. in a %aw construction for a MDI) then you could get the %hw or %lc handle and adapt the following code to see if the window is still open.

Code:
WINAPP
INCLUDE <windows.ins>
STDCALL MyFindWindowEx 'FindWindowExA' (VAL,VAL,STRING,VAL):INTEGER*4
nTHandle = Create_Window@("Caption",0,0,200,200)
CALL Open_to_Window@(8,nTHandle)
!Processing goes here
nThis = 0
DO
nThis = MyFindWindowEx(0,nThis,"SalfordClass",0)
IF(nThis == 0 .OR. nThis == nTHandle) exit
ENDDO
if(nThis /= 0) WRITE(8,*) "This window is still open"
END


Alternatively you might be able to use %cc to control the closure of the %cw window so that you know when it has been closed by the user.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Thu Feb 04, 2010 4:08 am    Post subject: Reply with quote

Thanks Paul, will try, may be that's the best solution...
Back to top
View user's profile Send private message
LitusSaxonicum



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

PostPosted: Wed Oct 27, 2010 1:45 pm    Post subject: Reply with quote

Dan,

I don't know if you are still working on this, or whether Paul's answer was enough. I found that I could give a program its own class name with:

Code:
       IA=WINIO@('%nc[MyClassName]%rm&',MESSAGE_FN)


and allow the whole program to respond to 2 messages ('RUNNING' or 'CLOSE')

Code:
       INTEGER FUNCTION MESSAGE_FN()
C      -----------------------------
C
C      This is the message handler that will close the main window if
C      it receives a 'CLOSE' message (irrelevant if MyClassName
C      is used standalone). It will also reply 'YES' to a 'RUNNING'
C      message, which can be used to inhibit launching multiple copies
C      of MyClassName, but is irrelevant if it is
C      is launched directly from Windows.
C
C      -----------------------------------------------------------------
       CHARACTER*(255) MESSAGE
       INCLUDE <WINDOWS.INS>

       MESSAGE = CLEARWIN_STRING@('MESSAGE_TEXT')
       IF (MESSAGE .EQ. 'CLOSE') THEN
           MESSAGE_FN = 0
           RETURN
       ELSE IF (MESSAGE .EQ. 'RUNNING') THEN
           CALL REPLY_TO_TEXT_MESSAGE@('YES')
       ENDIF

       MESSAGE_FN = 1
       RETURN
       END


You can handle more than 2 of course. The window that contains your %cw would need to have its class name. My example launches a complete standalone program, and I can see if an instance of it is running already with:

Code:
       IA = SEND_TEXT_MESSAGE@('MyClassName','RUNNING',REPLY)
       IF (REPLY .NE. 'YES') THEN
etc

By sending the message 'CLOSE' I can shut down that program. By sending the message 'RUNNING' I get the reply 'YES' if it is. You could do something similar before writing to the window with its own class name.

As my example is a complete standalone program, I found that I also needed to give its "About" box its own class name, so that if the call for its owner program to shut down came while the about box was displayed, I could send a message to that to shut itself down as well!

Regards

Eddie
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sun Oct 31, 2010 9:42 am    Post subject: Reply with quote

oops, missed your message under mine own which was posted same day. I will take note to explore this your way, Eddie, thanks for idea. All that tricks are permanently needed almost in each application.
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 -> ClearWin+ 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