Posted by tfair in SWF Studio V3 on Jan 10 2011, 06:08 pm

Is it possible to quit another application? I've looked at the Shell operations but don't see anything.

Thanks for any help.


Posted by AGo in SWF Studio V3 on Jan 10 2011, 06:08 pm

Win.sendMessage will do the trick


Posted by northcode in SWF Studio V3 on Jan 10 2011, 08:01 pm

To expand a little on what AGo said...

You'll want to use ssCore.Win.sendMessage and send "kill" as the message. You'll need to know the window handle or the caption of the window you want to close.

This will kill any window with the work "Notepad" anywhere in the caption. It's not a precision tool, but more of a shotgun approach.


ssCore.Win.sendMessage({target:"Notepad", message:"Kill"});


If you want to close a specific window you can use ssCore.SysInfo.getWindowList to get a list of all the top level windows on your system and use the window handle (hwnd) parameter ot Win.sendMessage to kill just that window.

If you do use SysInfo.getWindow list, it can also return the process id of the window you're interested in. You might want to use that with ssCore.SysTools.killProcess to kill applications that don't respond to Win.sendMessage. Some apps are harder to kill than others :)


Posted by nc.user in SWF Studio V3 on Jan 10 2011, 08:57 pm

The problem with this approach, I found out, is that this is a HARD Kill which does not nicely shut down the application like it would when using the exit or quit menu option, ALT+F4 etc...

I used this option to kill Firefox and it didn't like it at all, when it was restarted it presented the restore window option like it would when it crashes.

That is only thing you should be aware of when using that. At least from my experience.


Posted by northcode in SWF Studio V3 on Jan 10 2011, 11:58 pm

The "kill" message works by posting a WM_CLOSE message to the target window. This is the "proper" way to ask an application to close itself. It's the equivalent of Alt+F4 or using the close button, but not quite, since the request comes from outside the application.

If an application rejects messages posted from other applications then the only way another app can shut it down is by calling TerminateProcess, which is the same as killing it using the "End Task" option in Task Manager. This basically yanks the rug out from under the process and it's generally a bad idea.

The SysTools.killProcess first sends a WM_CLOSE message, but if the application doesn't respond then it calls TerminateProcess.

If you choose to take control of other applications without their consent, you can't be too surprised if they react badly.

The BEST way to do this would be to locate the window you wanted to close, give it focus and then send it the Alt+F4 key sequence or simulate a mouse click on it's close button. Most applications will not be able to distinguish this fake input from user input. There is a flag with each input message a window gets, so it could differentiate fake input from user input but 99.999% of applications will never look at this flag.


Posted by tfair in SWF Studio V3 on Jan 12 2011, 09:47 am

Thanks for the reply to this. I did have a little difficulty: I wanted to close another Flash application (non Swf_Studio) and found that all of them are generically named along the lines of "Flash 10 Player". I ended up using a Local Connection setup to do the same task.


Posted by northcode in SWF Studio V3 on Jan 12 2011, 11:05 am

If you have control of the EXE you can use a tool like Resource Hacker to edit that string resource in the Flash Player and make the caption show whatever you like.


Posted by gr.ind.can in SWF Studio V3 on Sep 25 2012, 04:32 am


QUOTE: from northcode;51933

The BEST way to do this would be to locate the window you wanted to close, give it focus and then send it the Alt+F4 key sequence or simulate a mouse click on it's close button.


Hey Northcode,
I want to send a key combination Ctrl+Alt+Shift+Home to a selected window from a winList. Please let me know how to send this by code.


Posted by gr.ind.can in SWF Studio V3 on Sep 25 2012, 04:36 am

Actually i wanted to send that key combination to whatever app is on top. Can you please guide me.


Posted by gr.ind.can in SWF Studio V3 on Sep 25 2012, 06:10 am

I got the solution. Here is the code:

ssCore.SysInfo.setStickyKeys( { sticky:true, hotkey:true } );
ssCore.Keyboard.sendKey( { hwnd:processInfo[0], key:ssKey.VK_CONTROL} );
ssCore.Keyboard.sendKey( { hwnd:processInfo[0], key:ssKey.VK_ALT} );
ssCore.Keyboard.sendKey( { hwnd:processInfo[0], key:ssKey.VK_SHIFT} );
ssCore.Keyboard.sendKey( { hwnd:processInfo[0], key:ssKey.VK_HOME} );
ssCore.SysInfo.setStickyKeys({sticky:false, hotkey:false});

Thanks.


Posted by northcode in SWF Studio V3 on Oct 02 2012, 12:50 am

Instead of using sticky keys you can also use sendPress and sendRelease to send the key codes in the same way as you would normally press and release them.