I have an application that called several other .exe components written in delphi. The question I ask is that is it possible to close the delphi app along with all application it opened (when clicking the '[x]' button)?
Also, obviously, I have learned how to open and close external application, but in several cases like Windows Media Player it just doesn't seem to work... can anyone give me some solution to this?
Thanks in advance
You can use Job Objects , read the documentation for these functions CreateJobObject and AssignProcessToJobObject.
A job object allows groups of processes to be managed as a unit....
Examples include enforcing limits such as working set size and process
priority or terminating all processes associated with a job.
If you keep track of the applications you open, you can post a WM_QUIT message to each one's window handle in the OnClose event of your Delphi app's main form.
The same should work for Media Player, but it's hard to say when you don't give any information about how you opened it.
Related
I am essentially trying to create something like a launcher for an Unreal application. The expected behavior that I was looking for is that when I launch an application the launcher would minimize or hide in the background and then whenever you close the application the launcher would then be restored.
I can successfully get the launcher to launch the other app and minimize itself but, for some reason my method for re-maximizing it doesn't seem to work. However, I was able to get it to work if I keep the app on screen(& not in focus) but, at a small size. It just seems that minimizing or hiding the app causes this method not to work
Essentially, I am using FPlatformProcess::CreateProc and grabbing the processID and then listening to see if the application is running. If it quits running then I (try to) restore the window.
My guess is there is something happening that is most likely pausing the app for some reason. I should also note that I overrode the UGameViewportClient class so that it doesn't pause the game even if it loses focus and that doesn't seem to work either.
I could possibly modify some code on the other application but, I want to keep that at a minimum. Any help would be greatly appreciated.
I was able to get a hold of one of the Engine developers with my question. Essentially, there are two options for doing something like this. First, you can use the MessageBus class and establish a connection between the two game instances. The drawback to this method however, is that it isn't really possible to detect crashes and things of that nature.
The second method (the approach I took) is to create a watchdog program in something like Visual Basic that you can use to set up a listener to a process exiting. This also allows you to set up other things like listening for application crashes or sending logs to developers.
I have an Alloy app. It has got 7 windows and opens at same time. When user close a opened window $.removeListener(); $.destroy(); codes runs at window close event. But I am getting memory leaks on Android device. %90 windows has got ListView, every window has got max 2 Listview. What is the right approach for multiple windows?
First of all, why you would want to open 7 windows at same time when user can only see max 1 window at a time.
It's dead simple, open only that window which user should see first, & create a link-flow to other window in previous window.
Can you think of any app on Play Store which does so, if you have, then please send me its link, I would really love to review it?
But if you mean to say that user will see all windows at same time in a scrolling behaviour or like paging, then go to Ti.UI.TabGroup
Are you 100% sure that your event listeners are being removed?
I don't know the function $.removeListener(); is this a custom function?
As a general rule I try and put as many of my event listeners into the xml, as these are automatically removed, and have a custom function destroyMe() that runs onClose which removes any other listeners that I may have used and $.destroy()
Ti.App.addEventListener is a killer too, make sure these are removed if you use them!
ps: i totally understand the 7 windows bit :-)
Related to my question here, is it possible to create a window hook that will monitor if an application has been opened or not?
Most that I have found about hooks seem to focus on user input (keyboard press, mouse events), but I could not confirm if it is possible to know that the "double click" the user made is to open an application, or just to highlight a word.
Thank you.
Indeed, window hooks would not be sufficient. In fact for the task you are asking about you could use various strategies, such as:
enumerating the processes to find the one you're looking for (Tool Help API or PSAPI)
enumerating the top-level windows on the desktop (but you're limited to your desktop then)
check for a global or local event, mutex (or other kernel object) to deduce from that that some instance of the application is running
... or even from kernel PsSetCreateProcessNotifyRoutine
probably there are variations on the above plus some more.
In essence the question is whether you want to check for the process or for some other indicator that signifies whether the program you want to check for has been started.
I want to respond to a certain type of new window being opened by an external application. I have some experience finding applications and windows currently open (system wide) using some of the carbon functionality, so could theoretically just check every few seconds. This would require getting a list of all open windows and checking it against some list I would have to maintain, and feels very clunky.
How can I get a simple, clean notification when a new window is launched? Should I use the accessibility API? If so, what specifically am I looking for?
First, create an AXObserver. Then, watch for launches of any applications that you think you'd be interested in. When such a launch occurs, create an application AXUIElement for that process, and add your observer to it for the kAXWindowCreatedNotification notification.
I question whether this is the best way to do whatever you're trying to do. You might step back a bit from this solution (that is, watching for new windows) and ask another question about your goal.
I'm facing a problem for an application I'm writing (http://code.google.com/p/blazingstars/issues/detail?id=25), where my program is a menulet (menu bar) application that uses the Accessibility API to interact with and control another program. I do the usual things like registering for the API notifications and getting the window list through API calls, etc., but I realized a while ago that if my program is started in a second Space (virtual desktop) after the program I'm interacting with is started in the first, my program will crash and burn because it can't access any information about its target. (Is there a way around that problem I'm missing?)
A simple solution would be to popup a dialog asking the user to restart the program in the correct Space, but for the life of me I can't figure out how to tell which Space my target is in, either through NSWorkspace or the Accessibility API, so that I can compare it to the Space that I'm in. Any ideas?
Note that setting the collection behaviour to NSWindowCollectionBehaviorCanJoinAllSpaces isn't going to do me any good because I have to do a bunch of work upon launch, so I have to be in the same space as my target right from the start.
I think you can do this with the APIs in CGWindow.h..
Specifically see CGWindowListCopyWindowInfo() and kCGWindowWorkspace.
I've used these APIs to do all types of things like getting window contents, window frames, etc...
If that doesn't work then you might want to try this private API:
extern CGSError CGSGetWindowWorkspace(const CGSConnectionID cid,
CGSWindowID wid,
CGSWorkspaceID *workspace);
The trick would be getting the connection ID of the target process.
You should probably redesign your app so that it delays its initialization until the app you want to control is in the current space.
There is no easy way to do this under Leopard because there are no official "space change" notifications, but the blog post and comments on this page may help.