Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems with Is_Run32
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Problems with Is_Run32
Divers
Thread ID:
00502433
Message ID:
00502433
Vues:
64
I've received a couple of messages regarding a problem with my Is_Run32() function from the files section.

The problem is basically that if an application is launched from within VFP (using any technique that allows for the window state of the launched to be indicated), the if the function is immediately called thereafter, it returns 0 (indicating that the program isn't running).

Below I've listed three ways the problem can be demonstrated. The code should be pasted into the command window, highlighted, then Execute Selection from the context menu used. Note also that the calls to the various methods should be made after closing any open instance of notepad.
* Using the VFP RUN command
RUN /N NOTEPAD.EXE
? Is_Run32("NOTEPAD") && Displays zero
* Using the Windows Script Host's Shell Object
oShell = CREATEOBJECT("WScript.Shell")
oShell.Run("NOTEPAD.EXE", 1)
? Is_Run32("NOTEPAD") && Displays zero
* Using the old WinExec function in the API
DECLARE INTEGER WinExec IN Win32API;
  STRING @lpexe, INTEGER uShowWnd
= WinExec(("NOTEPAD.EXE", 1)
? Is_Run32("NOTEPAD") && Displays zero
As near as I'm able to figure out, the problem is connected with VFP not being the active window when the call is made. There seems also to be, in the case of the Shell object a bit of a timing problem (the window hasn't been created yet).

One workaround that I've found is to assure that VFP remains active by not allowing the called application to immediately come to the front. In the case of the Shell, a brief pause is also required. Below is workaround code for the above. Note that the application is started minimized and inactive by the use of the value 7 as the window state parameter.
* Using the VFP RUN command
RUN /N7 NOTEPAD.EXE
? Is_Run32("NOTEPAD") && Displays the window handle
* Using the Windows Script Host's Shell Object
oShell = CREATEOBJECT("WScript.Shell")
oShell.Run("NOTEPAD.EXE", 7)
* Pause for a 1/10 of a second
WAIT WINDOW "" TIMEOUT .1
? Is_Run32("NOTEPAD") && Displays the window handle
* Using the old WinExec function in the API
DECLARE INTEGER WinExec IN Win32API;
  STRING @lpexe, INTEGER uShowWnd
= WinExec(("NOTEPAD.EXE", 7)
? Is_Run32("NOTEPAD") && Displays the window handle
Once the window handle is correctly retrieved, the ShowWindow() API call may then be used to manipulate the window to the desired position. Documentation regarding this function is available in the API section.

I'll be investigating making changes to the function to overcome this problem in the near future. As soon as I've found a solution, I'll modify the code and upload it.
George

Ubi caritas et amor, deus ibi est
Répondre
Fil
Voir

Click here to load this message in the networking platform