At 2009-07-14 13:11, you wrote:
>I came across a code written by Ramani to avoid two instances of an 
>application in the same desktop.
>It uses extensively the DDE functions, is there anything I should be 
>aware of ?

Well you could use API-calls instead - here is some commented (and 
uncommented) code...

DECLARE INTEGER FindWindow ;
    IN WIN32API ;
    STRING cNull,STRING cWinName

IF WinExist(myapp)
         WAIT WINDOW 'MyApp already started ...' NOWAIT
         =BeepW(4)
         WAIT WINDOW ''MyApp already started ...'' TIME 3
         CANCEL
ENDIF

***********************************************
*  Program  WINEXIST.PRG  (Does the Window exist)
*  Syntax:  ? winexist("Control Panel")
***********************************************
PROCEDURE WinExist
PARAMETERS WindowName
IF TYPE("WindowName")<>"C"
         WAIT WINDOW 'WINEXIST: Wrong parameter'
         RETURN .F.
Endif

*DECLARE integer FindWindow IN USER32.DLL integer, string
*DECLARE integer SetForegroundWindow in USER.DLL Integer
*DECLARE integer ShowWindow in USER.DLL Integer, Integer
*Isrunning = FindWindow(0,WindowName)

**** CODE START

  LOCAL awin_apps, vfp_handle, ln_current_window,ln_window_count

  * Dimension array awin_apps to store running apps
  DIMENSION awin_apps[1]

  * Initialize variable to store handle for current application
  vfp_handle=0

  * Declare API Functions
  * Redan deklarerad
*!*      DECLARE INTEGER FindWindow ;
*!*       IN win32api ;
*!*       INTEGER nullpointer, ;
*!*       STRING cwindow_name
  DECLARE INTEGER GetWindow ;
   IN win32api ;
   INTEGER ncurr_window_handle, ;
   INTEGER ndirection
  DECLARE INTEGER GetWindowText ;
   IN win32api ;
   INTEGER n_win_handle, ;
   STRING @ cwindow_title, ;
   INTEGER ntitle_length
  * End of API function declarations

  * Get handle for current application
  vfp_handle=findwindow(0,_SCREEN.CAPTION)

  * Store handle of current app to a variable
  ln_current_window=vfp_handle

  * Initialize a count variable used to dimension array of running apps
  ln_window_count=0
  DO WHILE ln_current_window>0

   *  Initialize variable to store application title
   lc_window_title=SPACE(255)

   * Call to GetWindowText to fetch window caption
   ln_length=getwindowtext(ln_current_window, ;
      @lc_window_title,LEN(lc_window_title))
   * Note that the lc_window_title variable is used as a buffer to
   * receive text from the call to GetWindowText

   IF ln_length>0
      lc_window_title=STRTRAN(TRIM(lc_window_title),CHR(0),"")
   ELSE
      lc_window_title=""
   ENDIF

   IF ln_current_window>0 .AND. !EMPTY(lc_window_title)
      * Increment the window count and re-dimension the array of running
      * applications
      ln_window_count=ln_window_count+1
      DIMENSION awin_apps(ln_window_count)
      awin_apps[ln_Window_Count]=lc_window_title
   ENDIF

   * Call to GetWindow to fetch handle of running applications.
   ln_current_window=getwindow(ln_current_window,2)
  ENDDO

*!*      CREATE TABLE runapps (appname m)

*!*      IF ALEN(awin_apps,1)>0
*!*       SELECT runapps
*!*       APPEND BLANK
*!*       FOR i=1 TO ALEN(awin_apps,1)
*!*          REPLACE appname WITH awin_apps[i]+cr ADDITIVE
*!*       NEXT
*!*      ENDIF
*!*      MODIFY MEMO appname NOEDIT

** CODE END

*If isrunning > 0
IF ASCAN(awin_apps,WindowName)>0
*       SetForegroundWindow(isrunning)
*       ShowWindow(isrunning,4)
         RETURN .T.
ELSE
         RETURN .F.
Endif



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to