I am trying to prevent the user from closing the window when they click on the close button. I would like to have the application dock to the system tray.
My first step is to recognize when the user attempts to close the window and prevent the default behavior on that event. I would expect this code to work, but it does not.
var appWindow = Titanium.UI.getCurrentWindow();
appWindow.addEventListener('app.exit', function(event){
event.preventDefault();
})
I tried using the exit event and the event constants themselves to no avail.
This wont work because all your doing when you call preventDefault is stopping the default behavior in the WebKit browser page, not the native application wrapper itself.
The close command is a native function call to the underlying wrapper, it just passes an event to the listener, it does not pass control.
Also, this sounds somewhat dangerous, not allowing a user to close an application seems problematic. Maybe instead you should register a background service to run instead?
one trick might be to open an 'invisible' window for the app, so even if the user closes the 'application' window, the app should still be running.
Related
I need to check for unsaved data when a packaged app is closed (using the close button at the bottom of the screen and then pressing the X that is top left when the app appears reduced size).
I've managed to add an event listener for the low battery condition and this works as expected. But looking at https://developer.mozilla.org/en-US/docs/Web/Events I can't decide which event is correct for closing an app.
The obvious name -- close -- seems to be something to do with web sockets.
mozbrowserclose seems to be triggered when closing by the app's software.
XUL close "the user presses the close button" seems like the appropriate one, but when trying
window.addEventListener("close", function( event )
{
window.alert("closing");
}, false);
the app closes without triggering the alert.
DOMWindowClose seems to be specific for close by window.close in software
mozbrowserclose seems to be specific to iframes
So ... does anybody know the correct event to trap ?
Phone is ZTE Open C with FFOS 1.3.
It looks like this is a bug -- https://bugzilla.mozilla.org/show_bug.cgi?id=996754 "User-terminated apps do not receive 'beforeunload' event"
I have an air application. Clicking the application menu item opens a native window. Just like in other applications, I want that while the native window is open, access to other preferences in the application (like close application etc) should be disabled.
How can I do this?
I don't know of any easy way of doing this. The best I can think of is to listen for the DEACTIVATE event, prevent it, and then manually reactivate the window. Some code:
var args:NativeWindowInitOptions = new NativeWindowInitOptions();
var subWindow:NativeWindow = new NativeWindow(args);
subWindow.activate();
subWindow.addEventListener(Event.DEACTIVATE, onDeactivate);
private function onDeactivate(event:Event):void
{
event.preventDefault();
NativeWindow(event.target).activate();
}
This will ensure that this subWindow always retains focus until it is closed.
There are two differences that I can see between this method and typical application behavior for this type of subwindow.
1) The parent window can be dragged around (for some reason this does not dispatch a DEACTIVATE event)
2) Usually the subwindow should kind of "flicker" and plays an alert sound to indicate that it must be dealt with before further actions can be made (this is the the behavior for other applications on Windows 7 at least; I am not sure about other OS's).
For the dragging problem you should be able to have the parent window listen for the MOVING event and preventDefault() whenever the subwindow is active.
I don't see any good way of replication the behavior of 2. You can have the subwindow notifyUser(NotificationType.INFORMATIONAL) in the DEACTIVATE event but it's not the same thing that other applications do.
Hi I want to make a small test window app that can force IE to save its data and shutdown upon a button click and restart with same tabs when another button is clicked??
I am fairly new to Win32 programming can anyone help me out here.??
Any leads will be appriciated??
Try to find one of each browser class with EnumChildWindows then you save the text(current link) of each one, and send a WM_CLOSE message to the program, if you debug the IE you'll probably see a CALL to the function to open a new window, when you find it, you can call it again and with the new browser class you put the text you got from the one that was opened
I am attempting to handle the loss of focus of my application, either by a phone call or other event, and also by the pressing of the home key.
I have tried setting a flag in the OnNavigatingFrom/OnNavigatedFrom and OnNavigatedTo event handlers but each time the app starts (either after pressing home, or something else) it always seems to be resetting the flag.
Which are the correct events I should be using in order to correctly "pause" and subsequently "resume" my application if it loses focus?
You should read the documentation about application lifecycle.
When you press the Home button, or when you receive a phone call, the application is paused.
If you pressed Home, you can then restore the application by pressing the back button.
to handle these events, in App.xaml.cs by default the methods are: Application_Activated and Application_Deactivated
Of course you can manage to store data before the pause, and restore it when application is restored.
This is called tombstoning.
What you need is described in the following links:
http://windowsphone7.vectorform.com/2010/11/16/wp7-application-lifecycle/
http://www.windowsphonegeek.com/articles/WP7-Application-Lifecycle-and-Tombstoning
Read this. This is a microsoft tutorial on how to save state.
It'll give you how to save your ApplicationData when it is tombstoned.
Basically edit the Application_Closing and Application_Activated methods in the App.xaml to save the data to the system using isolated storage.
I have a VB6 ActiveX exe that is launched from a third-party CRM App. On launch, the main form opens but it starts to flash and then loses focus. If you move the form, you'll see a server busy screen with the Switch To, Retry button.
I've tried using SetFocus and the SetFocusAPI in the OnActivate event of the form, but that doesn't work. Are there any suggestions on how I can have this form have focus when launched from the other app?
Additional Info:
The OnLoad event calls the SetWindowPos API in order to center the app over the calling app and sets HWND_TOPMOST.
Additional Info:
The Active Window is the correct window(but it's clearly not in focus)
The foreground window is the calling application. SetForegroundWindow switches the foreground window, but immediately returns back to the calling app. It's not until I click on the form that the form is in the foreground. I'm attempting all of this within a loop in the module that calls the form (and not in the calling app).
The CRM application has to call AllowSetForegroundWindow to "authorize" the ActiveX ProcessID to "steal" the focus from the current process.
Have you tried setting the tab order on the form? Your user control should have a tab order of 0 so it gets the focus.
Also, where does the focus go after it is launched?