VB6 ActiveX exe loses focus when launched from a third party app - vb6

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?

Related

Is there an equivalent of an OnModal message in MFC?

My MFC application has multiple top level (parented to the desktop) windows, any one of which can host an external application which can launch a modal dialog. Is there a way for one the other top level windows to get a notification when any of the others becomes modal?
My specific problem is that one of the my windows is hosting an embedded PDF viewer and when the user clicks print, only the window hosting the viewer is locked, not the others.
When a modal dialog is shown EnableWindow(FALSE) is called for the parent. It is deactivated now and will not accept any mouse input. Also it will not receive the keyboard focus.
When EnableWindow(FALSE) is called WM_ENABLE with wParam==FALSE is sent to the window.
When your parent receives this message you can call EnableWindow(FALSE) for all your other windows too. Recursion might be a problem here, but you can use a private window message or flags to prevent this.
Before the modal dialog closes EnableWndow(TRUE) is called again and WM_ENABLE with wParam==TRUE is sent again.

Is it possible to prevent an application from being activated (brought to front) without using DLL injection?

I need to write application A, which intercepts the WM_ACTIVATE message to a window of application B in order to prevent B from becoming top-most application.
Is it possible to do this without DLL injection (add a hook on that message, process and "neutralize" it with a series of WinAPI calls) ?
I think this is what you're after:
LockSetForegroundWindow
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633532(v=vs.85).aspx
Remarks
The system automatically enables calls to SetForegroundWindow if the user presses the ALT key or takes some action that causes the system itself to change the foreground window (for example, clicking a background window).
This function is provided so applications can prevent other applications from making a foreground change that can interrupt its interaction with the user.
Just don't forget to unlock :)
Edit:
Try SetWinEventHook as described here:
Is there Windows system event on active window changed?
Then when the unwanted window comes to the front you can send it to the background.

Preventing application exit in TideSDK

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.

Accept mouse clicks without activating the application?

I am working on a utility application that controls other running applications. On certain input event my application displays a window, user can pick some operation from the window, the window disappears and control returns to the previous app. My problem is that clicking in my app’s window activates my application, thus removing focus from the previous application’s window. I can re-activate the previous application when my window closes, but I’d rather keep the original application activated all the time. Is that possible?
It's quite easy to to, just make your window an instance of NSPanel (a subclass of NSWindow), and set it as non-activating in Xcode/IB (or create it programatically, with NSNonactivatingPanelMask in the style mask).
One idea would be: while your app is running, try to keept track of the active window in the system.
After you activate your app and click the command button, restore the previous active window.
This is only an idea, I don't know how to do it on mac.

Handling focus loss of application

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.

Resources