` Printed Icetips Article

Icetips Article



Par2: Finding If A Specific Open Window Apps Exists
2009-03-17 -- Robert Price
 
Last week I asked how I could find if another App was open.  The problem 
was I couldn't be sure of it's window title because that depends on 
whether or not it had any child windows open.

After Steve Parker pointed me in the right direction, further search 
found that another programmer (vpos) posted this on Tek-Tips Forums 
website.  For my purposes I found that the GetClassName function was not 
needed and there was no reason to use the second If statement by 
directly taking the sub() of the returned wTitle.

Here was his posting

vpos (Programmer) 
21 Nov 02 11:56
try this prototype for findwindow:

Module('winapi')
  FindWindow(<*cstring>,*cstring),unsigned,pascal,raw,name('FindWindowA')
End

The first parameter is the name of the class, for a clarion application 
it will be something like ClaWin and a lot of figures... ie 
Clawin8388608Class1
The second parameter is the title of the window (in the title bar.)

if you pass a NULL to the calss name then windows then this api will 
look through all the classes.. otherwise it will search everywhere.

If it still does not work then try this other method, it loop through 
all the opened windows (visible or not) until it finds a clarion 
program, then checks that it is the one you are interrested in.

module('winapi')
 
GetClassName(UNSIGNED,*CSTRING,SIGNED),SIGNED,PASCAL,RAW,NAME('GetClassNameA')
   GetWindowText(Long,Long,SIGNED),SIGNED,PASCAL,RAW,NAME('GetWindowTextA')
End

WindowHandle USHORT
WindowTitle  CSTRING(256)
ClassName    CSTRING(256)

FindWindowName = 'The title of of the window to close'

Loop WindowHandle = 1 To 0FFFFh
     rlen# = GetWindowText(WindowHandle,Address(WindowTitle),200)
     If rlen# Then
         ret#  = GetClassName(WindowHandle,ClassName,200)
         If (Sub(ClassName,1,6) = 'ClaWin') And Clip(WindowTitle) = 
FindWindowName)  Then
              MESSAGE('You cannot run more than one instance of ' & 
FindWindowName)
              Return
          End
     End
End

ere is what I ended up with  for my final code:

I have an Entry string Field for input of either a patients last name or 
numeric Id number and a Lookup Button that either can be used to find a 
patients record.  In the "When Selected before Generated Code"
   Do CheckOpenWindow
   If SkipLookupPatient
      Select(?Anyotherfield)
      Cycle
    .



!! Inside Global Map embed

  Module('Win32 API')

    GetWindowText(Long,Long,SIGNED),SIGNED,PASCAL,RAW,NAME('GetWindowTextA')

   End


!! Local Data Variables

wHnd         (Long)
wTitle  (CString)
SkipLookupPt (Byte)
rlen         (long)

CheckOpenWindow Routine !Code to check for Open App
    SkipLookUpPatient = False
    wTitle = 'KODAK'
    Clear(wHnd)
    Clear(rlen)
   Loop wHnd = 1 To 0FFFFh
     rlen = GetWindowText(wHnd,Address(WTitle),200)
     If rlen
         If Sub(wTitle,1,5) = 'KODAK'
              MESSAGE('Please Close X-Ray Program' &'|Before 
Continuing     with Another Patient','Notice',Icon:Exclamation)
              SkipLookUpPatient = True
              Exit
          End   !  end If sub

      End       ! end if rlen
     End        ! end Loop



!!!!!!!!!!!!



I was concerned about the time delay that might occur when the lookup 
was being done as it is a rather Brute Force way of finding the App with 
Open Window.  It could be conceivably be hundred or more windows 
returned during the loop.  However, there has been no noticeable delay 
that the user has been able to detect.



Printed November 21, 2024, 7:34 am
This article has been viewed/printed 35223 times.