Silverfrost Forums

Welcome to our forums

How to find if text window %cw is already opened

2 Feb 2010 9:59 #5864

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.

3 Feb 2010 9:09 #5867

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.

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.

4 Feb 2010 3:08 #5880

Thanks Paul, will try, may be that's the best solution...

27 Oct 2010 12:45 #7095

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:

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

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

       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:

       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

31 Oct 2010 8:42 #7110

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.

Please login to reply.