Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
API_AppRun vs. launch an app and wait
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00680456
Message ID:
00681567
Views:
166
Hi George,
That seems so simple however I am having a proplem. I have vfp run the cad cam app. Now at this point the cad cam app is on the desktop as well as vfp is on the desktop. I type in the command window the following:
closewindow(is_run32("CadCam",.t.)) && I have included closewindow.prg below

The cad cam app closes but my computer slows to a halt. If I bring up the task manager I get the following stats:
processes:29
cpu usage:100%
mem usage:150872k/309352k

And.... if I try to launch cad cam app again, I get 2 of them. What is going on?

closewindow.prg
LPARAMETERS tnHandle, tlDestroy
LOCAL lnhWnd
lnhWnd = tnHandle

#DEFINE WM_DESTROY 0x0002
#DEFINE WM_CLOSE 0x0010
DECLARE INTEGER SendMessage IN Win32API;
INTEGER hwnd, INTEGER uMsg, INTEGER wParam, INTEGER lParam
* lnhWnd is the Window handle to close
IF !tlDestroy
* Close and allow prompt to save changes
= SendMessage(lnhWnd, WM_CLOSE, 0, 0)
else
* Close without allowing prompt
= SendMessage(lnhwnd, WM_DESTROY, 0, 0)
ENDIF




>Hi Neil,
>>I am enjoying is_run32. Thank you for this little gem. I noticed that it returns the handle to the window that I am examining. Your documentation advises that the handle could be used for other API stuff. I got to thinking after reading that. Since I am controlling a cad cam program via SendKey commands, there is a possibility that my SendKey that causes an exit from the cad cam app, could fail because of a long file loading etc. I use is_run32 in a loop to determine if the cad cam app closes. But I also included a little counter in the loop so if the loop is transversed more that 50 times I have to assume that my sendkey never closed the app. Could I use the handle returned by is_run32 in an API thing or wsh construct to close the app. A little code would be appreciated.
>
>Check the FAQ I wrote (FAQ#7773). It'll show you how to use the SendMessage() API call, to shutdown another application.
>
>>I have another question about API etiqueette and housekeeping. Over the years you have posted code to UT which utilizes declare dll stuff. I have yours and other developer's code in a classlibrary called outsiders.prg
>>What happens when your code and several other developer's code make the same declare statement. Are there any toes being stepped on when 2 or more functions make the same declare statement? Should I just move everybodies declare statements to the top and remove duplicates? Should I have a clear dll statement in some cleanup routine?
>
>It's difficult to give a definitive answer to this. Frankly, "It depends...". Prior to VFP 7.0, I made it a habit to do the declarations in an object's Init event, if I was going use the object, then discard it. If, however, the object was going to be persistent, then I'd make the declarations inside the method that used it.
>
>With VFP 7.0, however, I've changed the practice a bit. Regardless of where I make the declarations, I clear them before the method terminates with CLEAR DLLS < alias name list >.
>
>In general, there's little harm in re-defining an API call. There are, however, specific cases where the declaration can be slightly different depending on the usage. If recollection serves, I think that this may apply to SystemParmetersInfo() as an example. To see what I mean, you might want to download my Enable/Disable Screen Saver programming and make comparisons between the declaration.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform